ChilliCream / ChilliCream/graphql-platform

Support using [ReferenceResolver] when using resolver types with schema first.

Open
#5,538 0 comments 21 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate Area: Apollo Federation
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Is your feature request related to a problem?

AFAIK, the only option to integrate schema first with Apollo Federation (specifically entity resolution) is to add a type extension that completely overwrites the the key/field and specifies the reference resolver. This seems to go against the idea of doing schema first as extensions seem to occur after the schema is bound. (Unsure if overwriting types with extensions during schema first is really supported)

The solution you'd like

I'd like to be able to use AddResolver<TResolver> and be able to decorate a method on the TResolver class with the [ReferenceResolver] attribute.

Full example:

// Configuration
builder.AddDocumentFromFile("./schema.graphql")
  .BindRunetimeType<UserDto>("User")
  .AddResolver<UserResolver>("User");

// UserResolver
public class UserResolver
{
  [ReferenceResolver]
  public Task<UserDto?> ReferenceResolver(int id)
  {
    return new UserDto(id);
  }
}

public record UserDto(string Id);
# schema.graphql
extend schema
  @link(url: "https://specs.apollo.dev/federation/v2.0",
        import: ["@key"])

type User @key(fields: "id") {
  id: ID!
}

Stretch goal, if we could get a schema first example under the Apollo Federation project.

Product

Hot Chocolate

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing schema-first binding through AddDocumentFromFile, BindRunetimeType, and AddResolver, then inspect how [ReferenceResolver] methods are discovered. Done means the provided UserResolver and schema-first Apollo Federation example work without a type extension, with coverage for the demonstrated configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.