apollographql / apollographql/federation
federation: resolveType of extended interface without knowledge of concrete type
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
Our existing services and clients utilize the node interface for object resolution and I haven't been able to figure out a way to implement this with federation
Given the following services:
**Product Service**
```
const typeDefs = gql`
interface Node {
id: ID!
}
type Product implements Node @key(fields: "id") {
id: ID!
status: String
}
`
const resolvers = {
Product: {
__resolveReference({ id }) {
return { id, status: 'in_stock' }
},
},
}
```
**Node Resolution Service**
```
const typeDefs = gql`
interface Node @key(fields: "id") @extends {
id: ID! @external
}
extend type Query {
node(id: ID!): Node
}
`
const resolvers = {
Node: {
__resolveType(object) {
return object.__typename
},
},
Query: {
node(_, args) {
const [__typename, decodedId] = Base64.decode(args.id).split('-')
return { __typename, id: decodedId }
},
},
}
```
I am unable to lookup a product via the node field with its encoded id. Intuitively, this makes sense because the node resolution service is unaware of any types returned from `__resolveType`. How feasible would it be for `__resolveType` to allow for arbitrary types if it's extended?
Or am I thinking about this problem in the wrong way - have there been any other ideas for implementing the node interface with federation and gateway?
Contributor guide
Research direction
Start with the federated Node interface and Query.node examples in the issue, then trace how the gateway handles __resolveType for an extended interface. A useful outcome would be a documented, reproducible answer on whether arbitrary concrete types are supported and what implementation path or alternative is expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100