Apollo-feature-requests: Bug cannot use schemaDirectives with modules

Created on 29 Nov 2018  路  6Comments  路  Source: apollographql/apollo-feature-requests

This is a recent bug. I have tried to use the new modules param in the new ApolloServer constructur (2.2.2). It works like a charm, except when trying to use schemaDirectives as well.

This is my constructor

const server = new ApolloServer({
  modules: [rootSchema]
  schemaDirectives: {
    auth: AuthDirective,
  },
  tracing: true,
});

If I ever decide to use the auth directive anywhere in my schema ... an error will occur:

Error: Unknown directive "auth".

Note that if I use the typeDefs and resolvers parameters, it will work properly. It only happens with the new modules param

this is my package.json

{
  "name": "graphql-api",
  "version": "0.1.0",
  "private": true,
  "author": "Aldo Funes",
  "scripts": {
    "graphql:schema": "graphql get-schema"
  },
  "dependencies": {
    "apollo-server": "^2.2.3",
    "axios": "^0.18.0",
    "casual": "^1.5.19",
    "debug": "^4.1.0",
    "faker": "^4.1.0",
    "graphql": "^14.0.2",
    "graphql-custom-types": "^1.5.0",
    "graphql-type-json": "^0.2.1",
    "jsonwebtoken": "^8.4.0",
    "lodash.merge": "^4.6.1",
    "node-vault": "^0.9.3",
    "yup": "^0.26.6"
  },
  "devDependencies": {
    "babel-jest": "^23.6.0",
    "flow-copy-source": "^2.0.2"
  }
}

All 6 comments

I had a similar problem as well. Using the "modules" option does not fire any schemaDirective, period. So I switched back to makeExecutableSchema. It is a shame cause the modules options it a more elegant way, I think.

I'm experiencing the same exact problem. However, I can't use with or without modules. Did you rollback to a specific version?

@luismaldonadov
I had the same problem. I hope this can help you.
I have this versions

"@graphql-modules/core": "^0.6.6",
"apollo-server-express": "^2.4.8",
"graphql": "^14.2.0",

and this is the workaround from my index.ts

// workaround because of bug https://github.com/apollographql/apollo-server/issues/2046
import { makeExecutableSchema } from 'graphql-tools'
const schema = makeExecutableSchema({
  typeDefs: AppModule.typeDefs,
  resolvers: AppModule.resolvers,
  schemaDirectives: AppModule.schemaDirectives,
})
const server = new ApolloServer({
  schema: schema,
  context: session => session,
})
// this is how it should work
/*
const server = new ApolloServer({
  modules: [
    AppModule
  ],
  context: session => session,
})
*/
// end of workaround

We're revising our implementation of schema directives and won't be supporting the existing graphql-tools API with the new modules option. Keeping this issue open to keep track of the feature request however.

getting this issue right now, Unknown directive "xxxx" , even without modules, directives too complicated!

any updates on this or proper workarounds that do not involve reverting the use of modules?

Was this page helpful?
0 / 5 - 0 ratings