-
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
RFC: Extra property on field definition to pass extra metadata #1527
Comments
Yes. It's explicitly forbidden in Flow typings: graphql-js/src/type/definition.js Lines 810 to 822 in 3789a87
Note:
@JCMais Agree 👍 Plus it provides a clean solution to #1343 without changing directive semantics. |
I'm all for it! 👍 When you want to modularize the typeDefs + resolvers definitions across your codebase, it's great to be able to pass additional metadata for consumption by third-party libraries such as graphql-middleware. Why not add an |
+1 for Ideally libraries using this would allow to customize the key name, to reduce possibility of key collisions. |
what can be done to move this forward? |
I think the first part is to remove exact types on flow definitions |
+1 this could help fix issues with join-monster that requires extra metadata for fields |
I would treat this exact Flow definition as a bug because this quote from @leebyron (#1262 (comment)):
So I treat this pattern as a recomended way to have some metadata on types/fields like directives allows use to do in SDL. |
This quote is about actual
It basically says you can do: const someType = new GraphQLObjectType({
name: 'Foo',
// ...
});
someType.customProperty = "Custom Value"; Personally, I think it's a workaround especially for clients who use Flow/TS at the same time I think config types should remain exact. The alternative proposal would be: const someType = new GraphQLObjectType({
name: 'Foo',
// ...
extensions: {
customProperty: "Custom Value",
},
}); Where @JCMais What do you think about this proposal? |
@IvanGoncharov that was exactly the kind of alternative I was looking for. Just a specific key that we can be sure it will be available later on, from the |
So how to place metadata on fields and args like directives do by using this way? Should we mutate this object later (by using |
@19majkel94 It should work fine as a workaround until we ship an I will work on adding immutable |
🛑Before shipping this we should consider how Add type User {
name @extensions(cost: { complexity: 2 })
} We MUST provide a unified solution for SDL and configObjects. And will be nice if it will be covered by the static analysis (if possible of course). For now Via SDL it can be extended somehow via directive config. With Flowtype/Typescript it can be validated via explicitly provided type for extensions config object. |
@nodkz this sounds good, since it has been some time since I last used That would be like a schema directive that apollo has, correct? Do we have support for that currently? Last time I checked (which has been some time ago) custom directives were one of the most dark features from an user pov, when using |
Currently, directives cannot be extended. There was no purpose. But for unified |
We've been using it very effectively at Gatsby through graphql-compose extensions. Adding it here as an example of "usage in the wild". |
Yes, except it would be
I will make
Definitely, also I need to support it in other places, e.g. |
Maybe string and symbol for keys? This can ensure we don't have collisions |
@cliedeman We can definitely use Symbols for solving collisions inside in-memory schema but it will just push the problem down the road. For example, I have a long term plan to figure out how to allow exposing So my proposal is to keep everything simple for the first release and figure out how to solve problems only if they will happen in the wild. BTW, you can also have collisions of directive names so it's not a new problem in GraphQL world. |
@IvanGoncharov This push will make my week. :) |
Quick update: #2037 taking more time than I initially expected so now I'm pushing for releasing at the end of this month. Thanks for the patience. |
In preparation for graphql#1527
I see movement! Yay! :p |
In preparation for graphql#1527
In preparation for graphql#1527
It took longer than I planned but I finally merged it in #2097 |
Thank you @IvanGoncharov ! |
@IvanGoncharov holy moly, the GraphQL world is going to get so much better now. :) Thanks! |
I'm currently adding extra properties to some graphql object field definitions, like the following:
And then using them later on via the
info
argument inside some middlewares (usinggraphql-middleware
):For more details, see the following medium post: graphql mutation arguments validation using yup
The thing is, this is relying on internal behavior.
The following code spreads all properties given to the field:
graphql-js/src/type/definition.js
Lines 720 to 724 in 8171974
Is that something expected to not change? If yes, then no need for any other extra property or for this issue. 😄
But if this is something that can change in future versions, I would love the possibility of having an extra field for that extra metadata.
I'm available to work on adding this, if it's approved.
The text was updated successfully, but these errors were encountered: