-
Notifications
You must be signed in to change notification settings - Fork 830
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
Custom Directive and specifying the same on a Field and Type #1006
Comments
@prashanthellina it's not documented but you can pass from graphql.types.directives import specified_directives # <== default directives
from graphene import Schema
schema = Schema(query=Query, directives=specified_directives + [MyDirective]) You'll have to define your own directives but you can see how the |
Thank you @jkimbo for the example above. I can understand how this will help in accomplishing this part of the schema. directive @unique(
info: String = "Blah blah"
) on FIELD_DEFINITION | ENUM_VALUE
directive @ignore(
info: String = Blah blah"
) on OBJECT What do I do to get this part: type ExampleType @ignore(info: "Blah"){
newField: String
oldField: String @unique(info: "Blah")
} i.e. Telling |
I believe decorating on the Query would be supported by the resolver argument info. You can get the arguments from the resolve info parameter: https://docs.graphene-python.org/en/latest/api/#execution-metadata You'd have to write your logic in a decorating function or in the resolver itself. I don't think that there is currently support for applying decorators on Schema, but you can definitely emulate the desired behavior through a wrapping class (kind of like List and NonNull in graphene). I'd love to dig into this a bit more though! Here's an example of how directives are implemented in graphql-tools for Js. https://www.apollographql.com/docs/graphql-tools/schema-directives/ |
@prashanthellina thanks for your patience. So I've looked into this a bit more and it looks like it's not possible to apply directives on a field/object level. This is a conscious limitation of the reference GraphQL server implementation graphql-js. You can read more about the reasoning here: graphql/graphql-js#746 (comment) and follow the ongoing discussion about it here: graphql/graphql-js#1343 The relevant comments from leebyron are:
and
(there is also a great long comment which explains things in detail) Since Graphene is based on graphql-core which is a direct port of the graphql-js implementation, support for directives on fields/objects won't happen until that support is available in graphql-js. I hope that's helpful. You might also want to checkout ariadne which is an alternative way of building a GraphQL server using the SDL. I'm going to create an new issue to document adding custom directives to the schema and then close this one. |
@jkimbo Thank you for the confirmation. I thought I was missing something. I believe there is merit in implementing I quite liked the way that For the moment, I am exploring using GraphQLS2S for defining the schema in an SDL superset (that support inheritance, generics etc to help reduce verbosity) and then transpiling it to standard SDL. After I have the final schema, I am using |
I've tried looking at the documentation to figure out how to accomplish this but got no where.
How do I define a schema like this using
Graphene
?The text was updated successfully, but these errors were encountered: