Skip to content
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

feat: remove usage of GraphQLContext interface #1580

Merged
merged 5 commits into from
Oct 27, 2022

Conversation

samuelAndalon
Copy link
Contributor

📝 Description

Removing all references of GraphQLContext in favor of context map.
GraphQL context map is the official approved context mechanism.

🔗 Related Issues

#1548

@Deprecated(message = "The generic context object is deprecated in favor of the context map", replaceWith = ReplaceWith("generateContextMap(request)"))
suspend fun generateContext(request: Request): Context? = null

interface GraphQLContextFactory<Request> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can default to GraphQLContext.of() to be extra clear what the object here is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we could make a MUCH more significant change and instead start using GraphQLContext as the type everywhere instead of Map<*, Any>?.

We end up mapping back to a builder anyway in GraphQLRequest.toExecutionInput() so if we let everyone just call the builder themselves to modify that might be eaiser

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require everyone to migrate though, and almost certainly break existing code.Tthis is at least a breaking change but will possibly only require removal as someone could have migrated to the new Map methods

Copy link
Contributor Author

@samuelAndalon samuelAndalon Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think for simplicity it was decided to just return a Map and let the GraphQLContextFactory build the GraphQLContext using that map.
i would keep it like that for simplicity and to not add another breaking change bc of the potential change of the return type

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it is a breaking change anyway -> lets approach it from a new user perspective, what would be a better user experience?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So DataFetchingEnvironment.getGraphQlContext returns GraphQLContext not Map<> so I think it would sense that the factory sets an object and that is the one you get back out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied the updates to return a GraphQLContext object instead of a Map

@samuelAndalon samuelAndalon marked this pull request as ready for review October 24, 2022 16:30
@smyrick
Copy link
Contributor

smyrick commented Oct 24, 2022

Make sure you add the proper PR labels

@dariuszkuc dariuszkuc added changes: major Changes require a major version module: generator Issue affects the schema generator and federation code module: server Issue affects the server code labels Oct 24, 2022
}

/**
* Helper method to get values from a registered DataLoader.
*/
@Deprecated(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are useful. I don't think we need to deprecate these. I was referring to the methods to get values from context directly on DataFetchingEnvironment, ie lines 57+ in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh ok, well we added those extensions bc of a feature request, where ppl stores in context using KClass, so is definetely more idiomatic do to

dataFetchingEnvironment.getFromContext<CoroutineScope>()

than

dataFetchingEnvironment.graphQLContext.get(CoroutineScope::class)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But with the extension methods here you can do this

dataFetchingEnvironment.graphQLContext.get<CoroutineScope>()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i still find it useful, but yes, it looks like an unneeded indirection, i can remove these in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they should be deleted just yet, maybe just deprecated, but yes that can be a separate PR

@samuelAndalon samuelAndalon merged commit bffbf01 into master Oct 27, 2022
@samuelAndalon samuelAndalon deleted the feat/remove-graphql-context-interface branch October 27, 2022 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: major Changes require a major version module: generator Issue affects the schema generator and federation code module: server Issue affects the server code
Development

Successfully merging this pull request may close these issues.

None yet

3 participants