spring-projects / spring-projects/spring-graphql

Make SchemaMapping @Repeatable

Open
#1,103 10 comments 1 reaction 1 assignee View on GitHub

@rstoyanchev is already working on this.

Since Jan 15, 2026.

status: feedback-provided status: waiting-for-triage
Dominant language
Java
Stars
1.6k
Forks
336
PR merge metrics
No merged PRs in 30d

Description

This is a minor inconvenience for me. It's just some boilerplate that I would love not to write. Motivation:

In my own usage of @SchemaMapping I often end up deprecating and renaming fields while their schema mapping method doesn't change:

type ... {
  count: Number @deprecated(reason: "use userCount"),
  userCount: Number
}

I'll need two @SchemaMappings:

@SchemaMapping
int count(SOURCE s) { ... }

@SchemaMapping
int userCount(SOURCE s) { ... }

Both have the same source object. So it's possible to register the same data fetcher with both fields.

Another case is when separating types based on access:

type AdminProduct {
  commonField: String
  ...
}
type Product {
  commonField: String
  ...
}

In the controller:

@SchemaMapping(typeName = "AdminProduct")
int commonField(SOURCE s) { ... }

@SchemaMapping(typeName = "Product")
int commonField(SOURCE s) { ... } // COMPILE ERROR: same signature 

@SchemaMapping(typeName = "Product", fieldName = "commonField")
int adminCommonField(SOURCE s) { ... } // COMPILES: but I have to specify fieldName

It's possible to share an interface between Product and AdminProduct and register the schema mapping on the interface type, but that is not often possible and it adds considerable code to the schema. Making SchemaMapping repeatable provides an ad-hoc way of achieving the same thing with much less boilerplate

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.