dotansimha / dotansimha/graphql-code-generator

Support @key on interface (Federation spec v2.3)

Open
#8,998 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Is your feature request related to a problem? Please describe.

The code generator correctly generates a `__resolveReference` function on types which have a @key associated with them, but not interfaces, even though @key is now supported on interfaces (https://github.com/apollographql/federation/issues/2277) and having a @key on interface implies there should be a `__resolveReference` function on it as well.

It does generate these fields for implementations of the interface, but simply not for the interface itself, which it should.

### Describe the solution you'd like

The following code:
```gql
interface Products @key(fields: "id") {
id: ID!
}
```

Should produce a resolver roughly looking like:
```ts
type ProductsResolvers = {
__resolveType: // ...
__resolveReference: // ...
}
```

It should be noted resolveReference should still be present even when onlyResolveTypeForInterfaces is set, since it's correct to have the __resolveReference on the interface as well as on the implementations of it, as far as I understand it.

### Describe alternatives you've considered

_No response_

### Is your feature request related to a problem? Please describe.

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.