-
Notifications
You must be signed in to change notification settings - Fork 341
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: add GraphQLContextBuilder #1663
feat: add GraphQLContextBuilder #1663
Conversation
… into feat/graphql-request-context-factory
Hello 👋 class MyCustomSpringContextFactory(val provider: SomeContextProviders) : DefaultSpringGraphQLContextFactory() {
override suspend fun generateContext(request: ServerRequest): GraphQLContext {
return super.generateContext(request).plus(
// whatever logic goes here
// iterate over and call the providers OR call individual functions
)
}
suspend fun foo1(): Map<Any, Any> {
// or split it up by functions
}
} The major change is the addition of parsed --- edit --- |
request: Request, | ||
graphQLRequest: GraphQLServerRequest, | ||
): GraphQLContext = | ||
producers.fold(mutableMapOf<Any, Any?>()) { accumulator, producer -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: while producers define their invoke
function as suspend
, logic below invokes it sequentially - was the intent to run them in parallel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that there is an accumulator the idea is to execute them sequentially.
Was just thinking - it seems like the major feature that this PR brings is the ability to do some logic around parsed GraphQL request. Maybe we should generalize it and provide some server execution hooks? i.e.
What we are missing is the ability to customize server behavior - yes, folks can provide their own server and override the methods but it is pretty cumbersome. Default server logic is as follows
Wondering whether we should update it to (hook names TBD)
|
the
the main concern i have with this is that we are already adding some extra entries in the Context. |
I agree that this functionality can be achieved with the current |
Change is not backwards compatible as it changes the factory method signature. |
📝 Description
The GraphQLContextFactory allows people to easily create the GraphQLContext that will be used during the execution of a graphQL operation, depending on each client, this context could contain a lot of entries, the process of creating a particular entry could involve IO operations, or expensive in memory operations.
This PR attempts to add another way to create the GraphQLContext by using composition of producers by entry in the context.
when a Factory becomes to large the maintainability could be a problem, the testability also could become a headache.
using a factory by entry will make the process of creating the context more flexible, testable and maintainable.
the
GraphQLContextFactory
will still be available, as both,GraphQLContextFactory
andGraphQLContextBuilder
implement a base interfaceGraphQLContextProvider
Server will be fully agnostic of which
GraphQLContextProvider
implementation was used