Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'directives' of undefined at createFieldExecutionResolver #8

Open
ticdenis opened this issue Mar 15, 2018 · 6 comments

Comments

@ticdenis
Copy link

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);
@gregberge
Copy link
Member

Hello what GraphQL version do you use?

@ticdenis
Copy link
Author

ticdenis commented Mar 15, 2018

0.13.1 version

@gregberge
Copy link
Member

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

@ticdenis
Copy link
Author

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

@Yunoo
Copy link

Yunoo commented Apr 2, 2018

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

@krishesk
Copy link

krishesk commented Aug 8, 2019

Hi there,

have you figured out why yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants