maticzav / graphql-shield

🛡 A GraphQL tool to ease the creation of permission layer.

Home Page:https://graphql-shield.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Apollo Federation and Shield Question

carlos-dc opened this issue · comments

Question about GraphQL Shield

I have a dummy api running Apollo Federation with 1 gateway and 2 subgraphs. Apollo Federation offers a method called __resolveReference that we can use to populate a field from one subgraph in another. I seem to be having issues getting Shield rules to work together with this method. The behavior that I am experiencing is that when I apply rules to a type let's say "User", this method does not get invoked at all.

For example, my subgraphs are User and App. the App type extends the User type at the "owner" field and it's resolved using this __resolveReference method. When I add the permissions to the User's subgraph schema using applyMiddleware this method is not called and owner returns null. If I comment out the permissions from the schema then it starts populating again.

Is this something that you guys are aware of? Is there a special way of setting up Shield to work with Apollo Federation?

Thanks for the help.

Hey @carlos-dc 👋,

Thank you for opening an issue. We will get back to you as soon as we can. Have you seen our Open Collective page? Please consider contributing financially to our project. This will help us involve more contributors and get to issues like yours faster.

https://opencollective.com/graphql-shield

We offer priority support for all financial contributors. Don't forget to add priority label once you become one! 😄

We've encountered the same issue as well. It seems that graphql-shield doesn't play well with federated graphs and the __resolveReference subgraph resolvers. There was a workaround for for an older version of Apollo-server that used the buildFederatedSchema method and solved this problem. (Fix here). But the latest version has the buildSubgraphSchema method which does not have the same options to satisfy the previous solution.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Here another one having the same issue. Not being able to access the __resolveReference if the Apollo Server subgraph has a middleware on it (by using applyMiddleware) but somehow, others subgraphs with the same config works properly with the middlewares and __resolveReference... weird though.

P.S: Will share the versions in case it's needed:
"@apollo/subgraph": "^0.4.0"
"apollo-server": "^3.6.7"
"apollo-server-express": "^3.6.7"
"graphql-middleware": "^6.0.9"
"graphql-shield": "^7.5.0"