Help fixing: ValidationError: It seems like you have applied rules to Query types but Shield cannot find them in your schema.
See original GitHub issueBug report
- [yes ] I have checked other issues to make sure this is not a duplicate.
I tried integrating graphql-apollo with graphql shield, However, I get a validation error as below:
ValidationError: It seems like you have applied rules to Query types but Shield cannot find them in your schema.
at generateMiddlewareFromSchemaAndRuleTree
(/node_modules/graphql-shield/src/generator.ts:250:13)
My code:
export default shield(
{
Query: {
viewer: isAuthenticated,
},
}
);
#Graphql schema definition:
const RootQuery = new GraphQLObjectType({
name: "RootQuery",
fields: {
viewer: VIEWER,
},
});
export const schema = new GraphQLSchema({
query: RootQuery,
mutation: Mutation,
});
#Integration of graphql shield:
const apolloServer = new ApolloServer({
schema: applyMiddleware(schema, permissions),
context: async ({ req }) => {
const user = await getUserContextIsAuthenticated(req);
return { user };
},
});
Viewer’s query:
export const VIEWER = {
type: UserType,
args: {},
resolve: async (_parent: any, args: any, { user }: any) => {
const manager = getConnection("main_db");
console.log("viwer context", user);
const id = args.id;
return await manager.getRepository(Users).findOne({ id: user.id });
},
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
graphql-shield - Bountysource
ValidationError : It seems like you have applied rules to Query types but Shield cannot find them in your schema. at generateMiddlewareFromSchemaAndRuleTree ......
Read more >GraphQL Shield - Medium
The process of implementing Shield into existing applications consists of two steps — defining rules and assigning them to schema, types or ...
Read more >Troubleshooting CloudFormation - AWS Documentation
Troubleshoot issues that might occur when you create, update, or delete an AWS CloudFormation stack.
Read more >Thoughts about Using GraphQL Shield in a layer above ...
Now let's consider a query that we actually want to run. Let's get the 5 most recent posts. This should obey the auth...
Read more >Common Problems Found in RAML 1.0 API Specifications
To resolve the problem, you would replace schema and schemas with type and types : ... Any name that is used in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hello Baloc22m.
If you use GraphQLObjectType to define your schema and you want to apply some rules, you should to use the property name (defined in GraphQLObjectType ) on permissions.
let me know if its working. 😉
@MAMISHO Thank you. It works for me.