graphql-directive
graphql-directive copied to clipboard
Cannot read property 'directives' of undefined at createFieldExecutionResolver
Hi, it throws me the following error when trying to add directive resolve functions to the schema.
I have checked with forEachField and astNode is always undefined, is it my configuration or is it a bug?
const schema = new GraphQLSchema({
directives: [
new GraphQLDirective({
name: 'isAuth',
locations: [ DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.FIELD ]
})
],
query: new GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: new GraphQLObjectType({
name: 'User',
fields: () => ({
id: { type: GraphQLNonNull(GraphQLInt) },
email: { type: GraphQLNonNull(GraphQLString) }
})
}),
args: { id: { type: GraphQLInt } },
resolve: (parent, args, context, info) => {
return { id: 1, email: '[email protected]' };
}
}
}
})
});
const directiveResolvers = {
isAuth(next, source, args, context, info) {
throw Error('Ups!');
}
};
const { addDirectiveResolveFunctionsToSchema } = require('graphql-directive');
addDirectiveResolveFunctionsToSchema(schema, directiveResolvers);
Hello what GraphQL version do you use?
0.13.1 version
I just ran test with all up to date and it works, it is weird.
Is for use ApolloServer?
package.json
// ...
"apollo-server-express": "^1.3.2",
"graphql": "^0.13.1",
"graphql-date": "^1.0.3",
"graphql-directive": "^0.2.1",
"graphql-fields": "^1.0.2",
"graphql-tools": "^2.21.0",
// ...
server
this.app = express();
const {
graphqlExpress,
graphiqlExpress
} = require('apollo-server-express');
// ...
this.app.use(compression());
this.app.use('/graphql', bodyParser.json(), graphqlExpress({
schema: require('./schema'),
context: {
db: require('./config/knex')
},
debug: this.isDevelopment,
tracing: true,
cacheControl: true
}));
if (this.isDevelopment) {
this.app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql'
}));
}
I am facing the same problem while using graphql 0.13.2 with apollo-server-koa 1.3.4
Hi there,
have you figured out why yet?