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

Refactor field resolution closer to schema types #573

Conversation

dackroyd
Copy link
Contributor

Much of the work of executing resolvers relates to the resolvable portion of fields, rather than the selection made for the request. With the introduction of directive visitors, these were being recreated for each request, instead of being built once, and re-used.

By pushing the resolution of fields down into the resolvable.Field, directives applied to the field definition can be setup just once when the schema is created, and re-used across all requests. Small exceptions to this exist for field types that embed this to provide request specific values (resolver instance and arguments), which get passed along with the call.

The chain of directive visitor functions still needs to be recreated for each resolve call, because the inner resolve function needs to accept the request specific field resolver instance, but other per-request overheads should be removed.

Copy link
Member

@pavelnikolov pavelnikolov left a comment

Choose a reason for hiding this comment

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

Thank you, Dave! I left a few comments but other than that it looks good to me.

return f.resolveInternal(ctx, resolver, args)
}

currResolver := func(ctx context.Context, args interface{}) (output interface{}, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

(nitpick) I'd rename currResolver -> wrapResolver.

@pavelnikolov pavelnikolov added this to the v1.6.0 milestone Feb 16, 2023
@pavelnikolov pavelnikolov marked this pull request as ready for review February 16, 2023 09:40
dackroyd and others added 2 commits February 18, 2023 13:07
Much of the work of executing resolvers relates to the resolvable
portion of fields, rather than the selection made for the request.
With the introduction of directive visitors, these were being recreated
for each request, instead of being built once, and re-used.

By pushing the resolution of fields down into the `resolvable.Field`,
directives applied to the field definition can be setup just once when
the schema is created, and re-used across all requests.
Small exceptions to this exist for field types that embed this to
provide request specific values (resolver instance and arguments),
which get passed along with the call.

The chain of directive visitor functions still needs to be recreated
for each resolve call, because the inner resolve function needs to
accept the request specific field resolver instance, but other
per-request overheads should be removed.
@pavelnikolov pavelnikolov force-pushed the refactor-field-resolution-closer-to-schema-types branch from fd952fa to 6f1c3fe Compare February 18, 2023 11:10
@pavelnikolov pavelnikolov merged commit 8d0aad8 into graph-gophers:master Feb 18, 2023
KNiepok pushed a commit to spacelift-io/graphql-go that referenced this pull request Feb 28, 2023
* Refactor field resolution closer to schema types

Much of the work of executing resolvers relates to the resolvable
portion of fields, rather than the selection made for the request.
With the introduction of directive visitors, these were being recreated
for each request, instead of being built once, and re-used.

By pushing the resolution of fields down into the `resolvable.Field`,
directives applied to the field definition can be setup just once when
the schema is created, and re-used across all requests.
Small exceptions to this exist for field types that embed this to
provide request specific values (resolver instance and arguments),
which get passed along with the call.

The chain of directive visitor functions still needs to be recreated
for each resolve call, because the inner resolve function needs to
accept the request specific field resolver instance, but other
per-request overheads should be removed.

* Fix feedback

---------

Co-authored-by: Pavel Nikolov <[email protected]>
KNiepok pushed a commit to spacelift-io/graphql-go that referenced this pull request Feb 28, 2023
* Refactor field resolution closer to schema types

Much of the work of executing resolvers relates to the resolvable
portion of fields, rather than the selection made for the request.
With the introduction of directive visitors, these were being recreated
for each request, instead of being built once, and re-used.

By pushing the resolution of fields down into the `resolvable.Field`,
directives applied to the field definition can be setup just once when
the schema is created, and re-used across all requests.
Small exceptions to this exist for field types that embed this to
provide request specific values (resolver instance and arguments),
which get passed along with the call.

The chain of directive visitor functions still needs to be recreated
for each resolve call, because the inner resolve function needs to
accept the request specific field resolver instance, but other
per-request overheads should be removed.

* Fix feedback

---------

Co-authored-by: Pavel Nikolov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants