-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
Schema directives support #77
Comments
@19majkel94 Why this is blocked? at face seems less complicated. |
Go to the link in first post and read the discussion 😉 |
This sadly prevents anybody from being able to use |
@ntziolis So there should be no problem to use Prisma along with your GraphQL API build with TypeGraphQL. Of course, the tighter integration (defining prisma model and your API GraphQL Object Type in one class with decorators) would help in reducing boilerplate, but I think it's not a deal breaker 😉 |
And to report an update about the status of the issue - now I think I understand where is the problem with directives in So as with |
This comment has been minimized.
This comment has been minimized.
Hi @19majkel94 I was trying to undestand the problem for long hours 😄 As far as I found apollo graphql-tools is doing simple job for schema directives. It just finds fields with directives and overrides their resolvers with enhanced version that applies that specific directive. So as TypeGraphQL stores metadata for first part, the second part can be done the same way. I don't know what you want to provide for prisma. The datamodel of the prisma is not a graphql thing. it's a customized version so I think it has nothing to do with TypeGraphQL that cares about server - client relation. |
@Hossein-s So show me a proof of concept how to apply directive to a field using |
@19majkel94 |
@Hossein-s I also took quite a long time to find a possible solution for programatically declare directives for a node, but no luck so far. So I am also keen to see your finding. If I understand correctly, your statement here is not quite right:
A In the case of apollo, you also need to implement SchemaDirectiveVisitor for specific directives. |
@zhenwenc Do you know any case that astNode definitions needed by server? I'm new on this topic. |
After investigating more, I found implementation of schema directives in apollo and graphql-yoga very similar to TypeGraphQL middlewares that are already available (But you can pass arguments to them). @19majkel94 I don't know where schema directives sit in TypeGraphQL. 😞 |
The problem (or difficulty) here is not about executing the directive, since apollo already provided a way to handle it (via SchemaDirectiveVisitor), but how to add the directive into the GraphQLSchema without using DSL. If I understand it correctly, the reason why TypeGraphQL can use Middleware to implement cache control is because you can easily manipulate the cache control store since apollo injected it into the resolve info, which doesn't actually needs to involve directive at all. |
@19majkel94 @zhenwenc It does something like |
@zhenwenc So I think it's possible to patch the resulting schema and add the astNode if there is need 🤔 I will work on it... |
I have updated PoC repository so that it adds astNode to GraphQLField. you can see it here. So apollo cache control can read directives in this function. But other directives work without astNode. It's very minimal just to show the posibility of feature. |
@Hossein-s |
@19majkel94 |
@Hossein-s |
@19majkel94 |
Hey @Hossein-s @19majkel94 , |
Yes please I would love to add field meta data from directives as well for use in the UI. My intent was to convert the schema in full server side and hang somewhere so the client can pull in all the meta data for UI auto generation. |
Hey @Hossein-s, is your solution working ? |
@Hossein-s Thanks for your idea, and I finally finished my workaroud repo. @MichalLytek This is an in-doing, buggy work for schema directive. I'm wondering if this is the right approach? |
This issue is partially solved by #369 but it doesn't support all the directives locations like scalars or arguments. So I will leave this issue open to track the work needs to be done in the future. |
Are there plans to support Directives on Subscriptions? |
Feel free to open a PR with added support for subscriptions. |
Because of #546 and other issues, I've decided to rollback the support for JS-like syntax - now only the SDL string way is supported. Sorry for that, better now than after stable release 😝 @glentakahashi |
@MichalLytek thanks for the update! And to clarify, do you mean that directives on subscriptions should now work with the SDL method? Or that they will work in a future method. |
@glentakahashi I've only added a test case that is passing: So it was working in November - if it still doesn't work for you (with the SDL approach), please open an issue with and provide a repository with minimal reproducible code example. |
Aha! Sorry my confusion was actually in how to implement the SchemaVisitor for the directive. For all other types (query, field, mutation) you override the So yes it has worked the whole time, I just didn't understand what I was doing |
Partially solved by #369
Currently blocked by graphql/graphql-js#1343
Ability to define any arbitrary graphql directive to be passed to the compiled schema:
Which should be equivalent to:
It might be also implemented as a separate decorator that would make possible to create custom decorators like
@CacheControl({ maxAge: 240 })
:The text was updated successfully, but these errors were encountered: