Custom Directive and specifying the same on a Field and Type
See original GitHub issueI’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
?
directive @unique(
info: String = "Blah blah"
) on FIELD_DEFINITION | ENUM_VALUE
directive @ignore(
info: String = Blah blah"
) on OBJECT
type ExampleType @ignore(info: "Blah"){
newField: String
oldField: String @unique(info: "Blah")
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Directives - Apollo GraphQL Docs
Configure GraphQL types, fields, and arguments. ... Your schema can define custom directives that can then decorate other parts of your schema: GraphQL....
Read more >The @custom Directive - GraphQL - Dgraph
The @custom directive is used to define custom queries, mutations, and fields. The result types can be local or remote.
Read more >Creating a Custom Directive • Angular - codecraft.tv
We create a directive by decorating a class with the @Directive decorator. The convention is to associate a directive to an element via...
Read more >How to use and create custom directives in Angular
Directive provides the same functionality for the @Directive decorator. The Input decorator is used to communicate between the two components.
Read more >Field arguments vs. directives in GraphQL - LogRocket Blog
Query-type directives cannot be used to modify the source of the data, however, because their logic is provided via directive resolvers, which ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jkimbo Thank you for the confirmation. I thought I was missing something. I believe there is merit in implementing
directives
as I find that a good way to signal behavior formally (rather than in comments) to both the user of the schema/service and the implementer of the resolver logic.I quite liked the way that
prisma
(https://www.prisma.io/) uses directives to provide more expressiveness when using the SDL to describe ORM like interactions with a database.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
ariadne
to implement the actual resolver logic.@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: https://github.com/graphql/graphql-js/pull/746#issuecomment-301554231 and follow the ongoing discussion about it here: https://github.com/graphql/graphql-js/issues/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.