-
Notifications
You must be signed in to change notification settings - Fork 237
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
docs: custom directive examples and docs page #982
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call this redaction rather than censorship :) See e.g. bottom of this page https://www.fastify.io/docs/latest/Reference/Logging/
Thank you, All your comments make sense, I am going to implement your suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better but I still think that the use case you're using is not fitting. Maybe It wasn't clear in my previous comment but you can't redact something that you don't know what will be. You will need to redact the whole field instead. So I imagine the @redact directive to be applied to all fields of a type which possibly contain sensitive information, and they will redact the content of the whole field. Does this make sense now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments, but looking better now, thanks
I implemented the suggestions |
@mcollina this looks good to me but I'd like another pair of eyes before we merge this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/custom-directive.md
Outdated
The `mapSchema` function applies each callback function to the corresponding type definition in the schema, creating a new schema with the modified type definitions. The function also provides access to the field resolvers of each object type, allowing you to alter the behaviour of the fields in the schema. | ||
|
||
```js | ||
const { mapSchema, getDirective, MapperKind } = require('@graphql-tools/utils') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document somewhere what version of graphql-tools this guide refers to graphql-tools
.
I would also prefer to not use graphql-tools here or show both examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted for the use of graphql tools because, being an example, I wanted to keep it as lean as possible. Inserting a code snippet (generic) for creating an executable schema or for decorating resolvers, risks being misleading for the purpose of the example, making it more complex to understand and also to reuse.
Instead, if I adopt the strategy to modify the schema ad hoc for the redact directive, we might reduce the amount of code but make the example hard to reuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Mauro, we have discussed in detail and replicating the features coming from the graphql-tools library for the sake of this example is just not worth it, and quite frankly in general it's not worth it. Nevertheless since this issue comes up quite often, we'll come up with a couple of ideas that we'll open as issues in this repo:
- one specific to this request, a way built-into mercurius (or a plugin) to make it easier to define and attach custom directives
- one generic about creating a new library alternative to graphql-tools with similar features
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have provided a more detailed argument on this issue. #989
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This pr adds a doc page and an example of implementing a custom directive.
After a few iterations, to keep this example compact and avoid working with the AST, I decided to use two libraries,
@graphql-tools/schema
and@graphql-tools/utils
.I also added some comments in the example file, but I am unsure whether to keep them.
closes #874