apollographql / apollographql/federation

Make it possible to add `@requires` on a non-entity

Open
#2,280 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
727
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

If im correct you cant extend upon objects, only entities

e.g. lets say we have the following graph
```
type Seller @key(fields: "id") {
id: ID!
rating: Rating
}
type Rating{
score: Int
}
```

and i would like to extend upon the Rating Object in a different service by using the `@requires` keyword like this:
```
type Seller @key(fields: "id language") @extends {
id: ID! @external
rating: Rating @external
}
type Rating @extends {
score: Int @external
description: String @requires(fields: "score")
}
```

This leads to an error
`Seller.rating -> is marked as @external but is not used by a @requires, @key, or @provides directive.`

if i were to move the description to the top level like so
```
type Seller @key(fields: "id language") @extends {
id: ID! @external
rating: Rating @external
description: String @requires(fields: "rating {score}")
}
type Rating @extends {
score: Int @external

}
```

then it would work.. However that is not ideal as it would lead to the Seller becoming full of fields over time as we keep on growing.

My Feature request is to make it possible to extend upon object fields of entities

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two schemas in the issue and the reported validation error involving Seller.rating and @external. Determine the federation validation and composition behavior needed to support @requires on fields of a non-entity object, then verify that the nested Rating example composes while preserving the existing top-level alternative.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.