Tried postgrphile example but not sure where mistake were done?
I am trying to implement graphql-shield as a plugin
middlewarePlugin = makeProcessSchemaPlugin((schema: typeof GraphQLSchema) => {
return applyMiddleware(schema, permissions);
});
permission.ts
const { rule, shield } = require("graphql-shield");
const isAuthenticated = rule()((parent: any, args: any, user: any ) => {
return user !== null;
});
const permissions = shield({
Query: {
viewer: isAuthenticated
}
});
export = permissions;
I import middlewarePlugin as others plugins in postgraphile:
appendPlugins: [
myClass.myPlugin,
myClass.jsonPlace,
myClass.middlewarePlugin
],
crash log:
| A serious error occurred when building the initial schema. Exiting because
retryOnInitFail
is not set. Error details: graphql | graphql | TypeError: Cannot read property 'fragment' of undefined graphql | at isMiddlewareWithFragment (/home/node/app/node_modules/graphql-middleware/src/utils.ts:25:17) graphql | at Object.isMiddlewareFunction (/home/node/app/node_modules/graphql-middleware/src/utils.ts:33:10) graphql | at Object.validateMiddleware (/home/node/app/node_modules/graphql-middleware/src/validation.ts:9:7) graphql | at addMiddlewareToSchema (/home/node/app/node_modules/graphql-middleware/src/middleware.ts:33:27) graphql | at normalisedMiddlewares.reduceRight.schema.schema (/home/node/app/node_modules/graphql-middleware/src/middleware.ts:91:11) graphql | at Array.reduceRight () graphql | at applyMiddlewareWithOptions (/home/node/app/node_modules/graphql-middleware/src/middleware.ts:80:77) graphql | at applyMiddleware (/home/node/app/node_modules/graphql-middleware/src/middleware.ts:132:10) graphql | at hook (/home/node/app/resolvers/test.resolver.ts:254:16) graphql | at SchemaBuilder.applyHooks (/home/node/app/node_modules/graphile-build/src/SchemaBuilder.js:398:20)