- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 932
Add IRequiresResolveFieldContextAccessor #4198
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
…opedFieldResolver
…during resolution
…of IResolveFieldContextAccessor
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.
Pull Request Overview
This PR introduces a performance optimization by allowing resolvers to indicate whether they require access to IResolveFieldContextAccessor during GraphQL execution. Simple field/property resolvers that don't need the context accessor can skip this overhead, while more complex resolvers (like method calls or multi-level property access) still get it when needed.
Key Changes:
- Added IRequiresResolveFieldContextAccessorinterface to allow resolvers to declare their context accessor requirements
- Updated resolver implementations to set this flag based on their complexity (simple property/field access vs methods or nested access)
- Modified introspection types to use new ResolveNoAccessormethod for their simple synchronous resolvers
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description | 
|---|---|
| IRequiresResolveFieldContextAccessor.cs | New interface defining whether a resolver requires context accessor | 
| ResolveFieldContextAccessorVisitor.cs | Updated to check the new interface when deciding whether to wrap resolvers | 
| MemberResolver.cs | Implements new interface, sets flag to true for method resolvers | 
| ExpressionFieldResolver.cs | Implements new interface, sets flag based on whether expression is simple property/field access | 
| FuncFieldResolver.cs | Added internal FuncFieldResolverNoAccessorvariant that sets flag to false | 
| FieldBuilder.cs | Added internal ResolveNoAccessormethod for creating resolvers without context accessor | 
| __Type.cs,__Schema.cs,__InputValue.cs,__Field.cs,__EnumValue.cs,__Directive.cs,__AppliedDirective.cs,__DirectiveArgument.cs | Updated introspection types to use ResolveNoAccessorfor simple field resolvers | 
| API approval files | Updated to reflect new public interface and property additions | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Configures field expressions that point to fields or properties to indicate that the context accessor is unnecessary. For example, these would skip setting the context accessor:
Field(x => x.Name)Field("FullName", x => x.Name)However, these would not (and would still set the context accessor:
Field("CompanyName", x => x.Company.Name)Field<string>("FullName").Resolve(context => context.Source.Name)Also in type-first scenarios, the same concept holds true:
Finally, since for performance reasons the introspection types have resolvers configured (versus expressions which would need to be compiled at runtime), synchronous introspection fields now are configured to skip the context accessor also.