Replies: 2 comments 8 replies
-
We had discussions like this before. One fundamental problem is that a GraphQLSchema is immutable. Allowing arbitrary metadata would break that. I think we were open to add something like Map<String,String> to it, which would not break immutability. Cc @bbakerman |
Beta Was this translation helpful? Give feedback.
-
After giving it another thought and chatting with @bbakerman and @dondonz I believe that any metadata tracked outside of elements is not a good experience. The lifecycle and "scoping" of the data is most likely per element. Tracking it outside of a GraphQLSchema puts a big burden on the user and maybe even more important, often you only have a GraphQLSchemaElement available (e.g. visitor or other APIs). Adding first class support for data tracked outside of the schema everywhere is likely not feasible. But just adding some data construct like Map<String,Object> or even GraphQLContext is also not great as I fear the abuse or misuse especially when a Schema or GraphQLElement is transformed. I propose to explicitly encode the behavior when an element is transformed and at same time leave it to the user to decide what exactly transforming or coping metadata means. I am thinking about an interface like this to be added to every element: interface SchemaElementMetadata {
Object transform();
Object getData();
}
public interface GraphQLSchemaElement {
SchemaElementMetadata getMetadata();
} Additionally we would offer some default implementations like While not perfect, it would enforce an explicit thinking about your metadata behavior, which I think is good enough. What do you think? @bbakerman @xuorig @tinnou |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Extending GraphQL schema element objects with custom metadata can be really useful. For example, back a few years ago it was possible to set arbitrary metadata on GraphQL Ruby elements using its
metadata
propertyfield.metadata[:visibility] = :hidden
. (Since then this has changed and is now possible through inheritance)Most of us probably use directives (applied directives 😉 ) to do so at the moment and that makes sense when building schemas using the SDL and where this metadata is defined by the schema builder. However there are still use cases where metadata needs to be applied but a directive is not necessary or wanted:
Would you be open to an extension/metadata system for
GraphQLSchemaElement
objects? One possible downside is that this may introduce 2 ways of doing similar things for some folks, but I think this may lead to a better extension system than serializing / deserializing metadata from a GraphQL directive. Let me know what you think 👂cc @tinnou
Beta Was this translation helpful? Give feedback.
All reactions