-
Notifications
You must be signed in to change notification settings - Fork 362
[generator] Replace GraphQLContext annotation with interface #610
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
Conversation
There are some cases where devs don't have the capability to add an interface to the class they want to use like when it's coming from a library. |
@gscheibel So about having a class that you can't implement as the context object. This is a similar question to returning a class in the schema which you can't add new fields to but you want to add more things in the schema. We had a feature request to support extension methods as part of the schema for this purpose but we decided against it as we instead want to have the schema be declared and managed by the GraphQL server and it's developers. This means that you can use the classes from other places but if you want to add more fields you should probably create your own class as a wrapper class or maybe your own recreation of the schema you actually want. Should the same thing go here? If you can't control the implementation of your GraphQLContext should you really be using that class? Maybe instead you should create your own class for the context and then you are free to add fields inside of it of any type. |
Ok, so taking this feedback I have made the change backwards compatible now. I have created the new interface of the same name which will allow us to use the new marker, but still support those that want to use the annotation on every argument still. |
I personally like the explicit annotation of the parameters to indicate they are "special" and won't be exposed in the schema. That being said we currently do have inconsistency that GraphQL context requires annotation whereas I'm also not a big fan of overloaded name used for both interface and annotation. As @gscheibel mentioned there are some use cases where this might not be ideal but I'd still make the change from annotation to interface. |
Instead of using an annotation and having to remember to include it in function arguments, we can create a marker interface for the GraphQLContext which library users can implement on a class to indicate that this class is the GraphQLContext. This moves the declaration from the arguments to the class itself which I think makes it more clear. This is obviously a large breaking change to fundamental part of our library. It requires heavy documentation changes and review to take place before the 2.0 release. Please review and provided feedback on the interface package path as well
Undo the deletion of the old annotation and instead make these changes a minor feature addition
b3c3033
to
2e93bff
Compare
Do we need the annotation? Keeping two ways of doing things is not ideal. |
@gscheibel @dariuszkuc I have updated the PR now to remove the annotation. So this is now back to being a breaking change. However I have left the |
|
@dariuszkuc That is what I had initially, but as mentioned, the concern was that this forces the factory to have a class that implements the new interface. This means if you did not control the implementation of the class you want to use for the context, you could not use the Now I personally agree with you that if you do not control the implementation of your context, then you should make a new context class and wrap any classes you want inside of it. But this was the initial concern by @gscheibel. Do you think we should force this standard going forward that more implementation details should be controlled within the server and not external? |
@smyrick IMHO moving towards the interface not only highlights the intent but also makes the underlying contract clearer. Since the default logic in |
...r/src/test/kotlin/com/expediagroup/graphql/generator/extensions/KFunctionExtensionsKtTest.kt
Outdated
Show resolved
Hide resolved
...-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/execution/ContextWebFilter.kt
Outdated
Show resolved
Hide resolved
Instead of having a generic of a GraphQLContextFactory, we can make the generic for the type required of the context factory
...r/src/test/kotlin/com/expediagroup/graphql/generator/extensions/KFunctionExtensionsKtTest.kt
Outdated
Show resolved
Hide resolved
…Group#610) * BREAKING CHANGE: Change GraphQLContext from annotation to interface Instead of using an annotation and having to remember to include it in function arguments, we can create a marker interface for the GraphQLContext which library users can implement on a class to indicate that this class is the GraphQLContext. This moves the declaration from the arguments to the class itself which I think makes it more clear. This is obviously a large breaking change to fundamental part of our library. It requires heavy documentation changes and review to take place before the 2.0 release. Please review and provided feedback on the interface package path as well * Change GraphQLContextFactory to return the interface * Combine interface and default implementation into single file * Revert deletion of annotation class Undo the deletion of the old annotation and instead make these changes a minor feature addition * Update context docs * Update docs wording * typos * typo * typos, minor wording changes * typos, minor wording changes * Remove context annotation * Update the docs * GraphQLContextFactory must accept a GraphQLContext type * Change generic type of ContextWebFilter Instead of having a generic of a GraphQLContextFactory, we can make the generic for the type required of the context factory * Simplify kFunction unit tests Co-authored-by: Shane Myrick <[email protected]> Co-authored-by: Robert Del Favero <[email protected]>
📝 Description
Instead of using an annotation and having to remember to include it in function arguments, we can create a marker interface for the
GraphQLContext
which library users can implement on a class to indicate that this class is theGraphQLContext
. This moves the declaration from the arguments to the class itself which I think makes it more clear.With this change though I think it makes it line up with some of our other features:
DataFetchingEnvironment
as an argument without any extra annotations and that does not appear as part of the schema.GraphQLContext
is the only one used for execution changes.