Skip to content

Conversation

@Shane32
Copy link
Member

@Shane32 Shane32 commented Oct 22, 2025

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:

class PersonGraph : AutoRegisteringObjectGraphType<Person> { }

class Person
{
    [Name("FullName")]
    public string Name { get; set; }     // does not set the context accessor

    public string FirstName;             // fields are skipped by AutoRegisteringObjectGraphType

    public string CompanyName()          // sets the context accessor
    {
        return "test";
    }
}

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.

@Shane32 Shane32 added this to the 8.7.0 milestone Oct 22, 2025
@Shane32 Shane32 requested review from Copilot and gao-artur October 22, 2025 21:03
@Shane32 Shane32 self-assigned this Oct 22, 2025
Copy link
Contributor

Copilot AI left a 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 IRequiresResolveFieldContextAccessor interface 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 ResolveNoAccessor method 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 FuncFieldResolverNoAccessor variant that sets flag to false
FieldBuilder.cs Added internal ResolveNoAccessor method 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 ResolveNoAccessor for 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.

Base automatically changed from contextaccessor1 to master October 23, 2025 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants