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

Support custom directives in mercurius core #989

Open
brainrepo opened this issue Apr 28, 2023 · 0 comments
Open

Support custom directives in mercurius core #989

brainrepo opened this issue Apr 28, 2023 · 0 comments

Comments

@brainrepo
Copy link
Contributor

brainrepo commented Apr 28, 2023

Mercurius doesn't offer any tool for easy handling of custom directives. The easiest way to do it is documented here: #982.
This pr uses graphql-tools to simplify the schema change process.
This issue is to explore 2 possible ways:

  1. create a plugin that helps to hide all the schema work.
  2. explore the possibility of integrating some custom directives APIs directly inside Mercurius

For point 1. the plugin API could be like what is done in the Mercurius auth plugin

const schema = `
  directive @redact on FIELD_DEFINITION

  type Query {
    ...
  }
`

const resolvers = {
   ...
}

app.register(mercurius, {
  schema,
  resolvers
})

app.register(mercuriusCustomDirective, {
  redact: {
    mapperKind: 'OBJECT_FIELD',
    resolver: redact(authDirectiveAST, parent, args, context, info) {
       ...
     },
  }
})

app.listen({ port: 3000 })

Integrating the custom directives feature into Mercurius che allows us to reduce the number of schema traversals. We can also take the opportunity from this work to extract some schema mapping and traversal to an external lib that can act as a partial replacement of graphql-tools #990

@simoneb

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

1 participant