graphql-directive icon indicating copy to clipboard operation
graphql-directive copied to clipboard

Cannot read property 'directives' of undefined at createFieldExecutionResolver

Open ticdenis opened this issue 6 years ago • 6 comments

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);

ticdenis avatar Mar 15 '18 22:03 ticdenis

Hello what GraphQL version do you use?

gregberge avatar Mar 15 '18 22:03 gregberge

0.13.1 version

ticdenis avatar Mar 15 '18 22:03 ticdenis

I just ran test with all up to date and it works, it is weird.

gregberge avatar Mar 15 '18 22:03 gregberge

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'
      }));
    }

ticdenis avatar Mar 15 '18 23:03 ticdenis

I am facing the same problem while using graphql 0.13.2 with apollo-server-koa 1.3.4

Yunoo avatar Apr 02 '18 21:04 Yunoo

Hi there,

have you figured out why yet?

krishesk avatar Aug 08 '19 07:08 krishesk