-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
applyMiddleware corrupts schema with Apollo federation stub types
#395
Comments
@jekabs-karklins have you found solution? I have similar schema design to yours and getting similar error. I was using v4.0.2 everything was working expected but recently I have update to latest version(v6.0.10) and then started getting this issue. I have also tested v4.0.3 seems like working everything as expected but not working in 5.0.0 and above |
Well, I tested and yes, the last working version is v4.0.3. I would like to know if there will be a solution, because working with a 2 years outdated version isn't ideal. Also huge thanks, this lib is awesome. |
hi guys have anyone found a solution? |
I tried to
if you try to |
You can try out what @martin-trajanovski is suggesting |
I found a solution. You need to check whether the resolver is one of the type fields for the Apollo Federation spec, and simply make your middleware a no-op when it matches. (TypeScript) function isFederationIntrospectionQuery({
prev,
key,
typename,
}: GraphQLResolveInfo['path']): boolean {
if (prev) {
return isFederationIntrospectionQuery(prev);
} else {
return (key == '_entities' || key == '_service') && typename == 'Query';
}
}
// ...
applyMiddleware(
schema,
async (resolve, root, args, context, info) => {
if (isFederationIntrospectionQuery(info.path)) {
// no-op
return resolve(root, args, context, info);
}
// etc... Could this logic get rolled into graphql-middleware, or some utility or option be added to make this easier? |
We are using Apollo federation https://www.apollographql.com/docs/federation/federation-spec/ where gateway combines two graphql schemas into one unified schema.
We have vanilla ordinary setup for it
We have type user in service A
And we have type stub type User in service B
And we have type Equipment in service B that refers to the user
By applying this trivial middleware in the service A
GraphQL will be unable to resolve external fields for the User. i.e.
This will work
But this will start to fail
with error message
Cannot return null for non-nullable field User.lastname.
I was unable to pinpoint what is going on, but I see that the schemas ar slightly different after running applyMiddleware(doNothing)
The text was updated successfully, but these errors were encountered: