-
Notifications
You must be signed in to change notification settings - Fork 275
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
allow custom directives #53
Comments
We can add the ability to define a directive for runtime use, but (as far as I can tell) adding them for use annotating the SDL would be more difficult, due to lack of support in graphql-js:
Can you talk more about the type of directives you are looking to add and how they would be used? |
Sure, So Basically my question was motivated with context the of trying to use Nexus in already existing Project or pipeline (which is schema first)
with sth like
i understand that will be implementing workaround (until it's figured out in graphql-js) perhaps by repacing without this feature switching to Nexus seems like I have to leave behind everything that already works |
I think this should be possible to add, going to dig into what it'll take to do this properly and keep you posted. |
👋 Hellos! I'm also interested in this. Perhaps all we'd need for implementing this is the ability to specify directives for type and field creation? |
👋
Yes - you can add these in graphql-tools, but It's not quite as simple to do programmatically because they needed to be added to the AST for the schema, which is possible but takes a bit more work. I've started work on it in this branch, it's something I plan on getting to but it still needs quite a bit of work to get the type generation, etc working properly. |
Actually this looks like it might also be simple to do programmatically |
Any news on this? |
I'd also urgently need custom directives in nexus for applying authorization on query and field levels without highly repetetiv code in all resolvers. |
Any news about directives. I want to use Apollo Federation and I need to use directives on nexus. |
Oh I just found a related issue #148 |
Also relevant for caching with Apollo Server. We are trying to map out what it would take for us to migrate from |
Any movement on this @tgriesser , active or planned? |
There is movement planned, but this is blocked on longer term changes from You can read up on the related issue graphql/graphql-js#1343, but the gist of it is that the SDL was never intended to be used as the means to construct the schema, and the fragment FullType on __Type {
# ...
fields(includeDeprecated: true) {
name
# ...
isDeprecated
deprecationReason
}
enumValues(includeDeprecated: true) {
name
# ...
isDeprecated
deprecationReason
}
# ...
} The fact that handwritten directives exist in the AST when writing-SDL first is only a result of that fact that it is valid syntax, but it's not necessarily meant to be utilized in this way. So I'm planning on revisiting in the future when this is supported in the way that is intended, rather than trying to hack around this limitation. |
@tgriesser Allright, thanks, that makes sense. So for people looking to use a code-first approach with Apollo Federation, the short answer seems to be: "You can't" - at least yet, because Lee Byron and the GraphQL team does not believe that using directives in such a manner is the "intended" way of the GraphQL IDL? |
Yeah that's more or less it. I think I had seen mention there was or will be an approach of federating via code first, but I'm not positive. I'd also caution against jumping right to federation just because it's the new tech out there. Facebook, Shopify, Github, Twitter all examples of companies/codebases using GraphQL which are code-first and not federated at the GraphQL layer. If you're moving to federation because you truly have multiple independent GraphQL services you control and really want to stitch together at the GraphQL layer (say, one in Ruby, one in Scala, one in Elixir, one in JS), then yes - federation seems like a possible solution. Instead, if you're using federation to try and compartmentalize pieces of your app, I'd advise seeing how far code-first can get you. You can still come up with a set of conventions for where to place code so different teams can work on it and expose their pieces of the graph in ways that don't step on others' toes, particularly with helpers like In my view, the ideal GraphQL layer hides the implementation details of any microservices/data stores at a lower level. As soon as you federate, you will run into a host of other problems you'll need to sort out. |
I know that my comment will add nothing but currently we are at the end of March, is there any updates? Any workaround to add custom directives to use for example apollo-server cache and rateLimit library? |
Hello, I've also faced with this problem, is there any updates ? I think now we are looking for any solutions. Thanks |
bumping this as I just want to add a "@deprecated" flag to some queries/mutations |
@maxwellsmart84 you don't need directives for that. You can just set the "decprecation" property on the field/object and it will be deprecated in schema. |
see #148 (comment) i think there are two issues, allowing uses of custom directives within the schema and allowing definition of custom directives that could be used within the schema or the query... the former is debatable, and graphql-tools has joined graphql-compose/gatsby in saying that these "directive" uses should be alternatively read from the extensions... but the latter seems definitely like it should be supported maybe it is supported? i am day I used a workaround with |
just want to argue this feature would be powerful for authorization, which ought to happen at the GraphQL layer, since it handles the data schema. ideas of trust and ideas of data are forcibly linked because you can't make trust decisions without data and you can't just serve data without trust in many situations (finance, healthcare etc), so some standard way to meta-program the schema would prevent us from doing a lot of boilerplate repetition |
Is there any latest news? |
1 similar comment
Is there any latest news? |
@bionicles If your are looking to abstract your authorization in an easily consumable service, I suggest that you have a look at the field authorize plugin, it may be what you are looking for. If it is not, you can always write your own custom plugins based on your need. For authorization, I would suggest writing a plugin on the onCreateFieldResolver operation. Here are the docs it's a fairly simple task and you can always have look at the default plugins source code here for inspiration :). Good luck |
In our case, we'd like to use custom directive to expose more information to the frontend, so as to generate some fields dynamically. Is custom directive the right way to extend a GraphQL* type, or is there any better way to expose extra metadata to the frontend? |
In my use-case, I would like to replace the value of the field with null if the user is not authorized. Any updates on this feature? |
I just did a deep dive into the subject and here is my proposition @tgriesser @jasonkuhrt Recap of facts
Proposition References
|
I just want to take functions and apply them to fields or types, and read clear docs on arguments / desired outputs. IDK what it's called but I do care about having as little boilerplate as possible If plugins are an alternative, then how does the code look? Are the docs enough for a newbie to read them and attach their custom function to multiple fields or types without questions? If so, we're done! |
if i understand correctly there is only @deprecated possible so far? it there way to add custom ones?
tools out there usually depend on custom directives then i could integrate nexus into toolchain
The text was updated successfully, but these errors were encountered: