Aliasing not working with graphql-shield permissions middleware and customFieldResolver
Bug report
- [X] I have checked other issues to make sure this is not a duplicate.
Describe the bug
When using aliasing in my graphQL query, the aliased field is returned as null. If I do return the field + its aliased value, the aliased value (as well as the non-aliased field value) are returned.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- This is my GraphQL Schema.
type Query {
book: Book!
}
type Book {
id: ID!
name: String!
content: String!
similarBooks: [Book!]!
}
- This is the invoked query that doesn't work
Query A):
book {
id
otherBooks: similarBooks {
id
}
}
It works with:
Query B):
book {
id
similarBooks {
id
}
}
or
Query C):
book {
id
similarBooks {
id
}
otherBooks: similarBooks {
id
}
}
- I use these permissions
const permissions = shield({
Query: allow,
})
- This is the error I see
Actual behavior
In Query A), I am getting null for otherBooks.
Expected behavior
I expected to see a value for otherBooks (assuming the data is set this way). Expected query results are observed for queries B) and C)
Additional context
Here is my graphQL server setup:
import { ApolloServer } from 'apollo-server-lambda';
import { applyMiddleware } from 'graphql-middleware';
import { makeExecutableSchema } from 'graphql-tools';
const schemaWoMiddleware = makeExecutableSchema({
typeDefs,
resolvers,
});
const middleWare = applyMiddleware(
schemaWoMiddleware,
permissions,
);
const resolverFragmentReplacements = middleWare.fragmentReplacements;
const schema = middleWare.schema;
...
const server = new ApolloServer({
// ref: https://github.com/apollographql/apollo-server/issues/865
fieldResolver: customFieldResolver,
schema,
tracing: false,
cacheControl: false,
});
return server.createHandler();
The customFieldResolver is a direct copy of https://github.com/akadop/graphql-yoga/blob/ee0c03fa8d0e9578f4589e19da6beff1d8112a67/src/customFieldResolver.ts
I use those versions:
"apollo-server-lambda": "2.1.0",
"graphql": "0.13.2",
"graphql-middleware": "1.7.3",
"graphql-playground-middleware-lambda": "1.7.3",
"graphql-shield": "3.2.3",
"graphql-tag": "2.9.2",
"graphql-tools": "3.1.1",
If I remove the permissions in the middleWare, aliasing works (and my customFieldResolver is invoked). With permissions defined in middleWare, the customFieldResolver is never invoked.
Hey @morgothulhu 👋,
Thanks for reporting this. I am not entirely sure but it seems like this might be a graphql-middleware bug. I'll dig deeper into the problem later this week and let you know about the progress. Is this in any way blocking for your progress?
Let me know! 🙂
@maticzav - all good. Fortunately, this is not blocking yet - so any time this week will be perfect. Thanks for the great work with graphql-shield - loving it!
@maticzav any path forward with this? Thx in advance!
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.
any progress on this?
@dude-awesome could you compose a small reproduction CodeSandbox? I can work on this issue much sooner if I have a reproduction I can work on right away.
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.
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.