-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Documentation on adding custom directives #446
Comments
There isn't documentation outside the codebase itself at present, but you can take a look at directives.js which exports the The difficulty you may run into is introducing non-spec-compliant behavior into the executor itself to omit fields. You'll likely need to fork this library to make the necessary changes. |
Thanks for the response! So using a directive for this purpose would violate the spec? Why would that be? I just see it as the same as the @include directive with the conditional fulfilled server side. Not sure why doing this could cause issues. |
Violate is a strong word for what this directive would propose - rather it's just adding new execution behavior that's not defined by the spec. That means adding this directive won't make your service any less GraphQL, it would be GraphQL plus more behavior. Violation implies a breaking change that makes a service not-quite-GraphQL instead. I know that's kind of word pickiness, but it's a subtle but important point in this case. Just trying to say that you're not doing anything wrong by doing this, but that there also are not hooks into the executor in this library that allow for easy addition of behavioral changes like this so it might not be very straight-forward. |
I see, that makes perfect sense. Thanks again for the detailed and thorough reply. |
I'm looking to create a custom directive for my GraphQL server. I want my server to omit certain fields conditionally, based on the value of the fields that are decorated with the directive.
For example:
Would return all sites and their names, but only include their siteId if its value is over 4.
Is there any documentation or an API I could read so I can see the best practice when adding a new directive?
The text was updated successfully, but these errors were encountered: