Urigo/graphql-modules

Implementing directives with latest graphql-tools/utils

shotor opened this issue · 3 comments

Describe the bug

Using the new directive implementation described in: https://www.graphql-tools.com/docs/schema-directives

The overwritten fieldConfig.resolve function never gets called.

To Reproduce
Created minimal reproduction here https://github.com/shotor/graphql-modules-tools-repro

Expected behavior

Expect when you call the query userWithError that it should call the custom resolve function and then throw an error. But it's never called. I'm not sure what is

Environment:

  • OS: Linux
  • @graphql-modules@1.4.4
  • @graphql-tools/utils@8.0.2
  • @graphql-tools/load-files@6.3.2
  • @graphql-tools/merge@7.0.0
  • apollo-server-express@3.1.2
  • NodeJS: 14

Additional context

Possibly I'm not wiring this correctly, although the transformer is called on init. Described the wiring I did in reproduction repository.

Generated schema with createSchemaForApollo is wrapped, that's why you cannot access to the resolvers directly. You can add a custom schemaBuilder to createApplication;

const { makeExecutableSchema } = require('@graphql-tools/schema');
createApplication({
  ...,
  schemaBuilder: ({ typeDefs, resolvers }) => anyKindOfSchemaTransformer(
    makeExecutableSchema({ typeDefs, resolvers })
  )
})

That works. Thanks!

Do you want me to add this setup to the docs? Currently graphql-modules docs contains a legacy version of adding directives using the SchemaVisitor pattern

@shotor Sure! We'd love to :)