apollographql / apollographql/federation

Referencing types of another service that implement an interface

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

Description

**Version:** @apollo/gateway@0.17.0
**Reproduction:** https://github.com/mmuth/apollo-federation-interface-referencing
**Related to:** apollographql/federation#336

Hi there!
I am using Apollo Federation in order to make references to types of other Services. I have a Project Service that offers several Project Types (`SoftwareDevelopmentProject`, `MarketingProject` etc) that implement a `Project` interface. Then I have a Service for the Access rights, where I basically just try to reference the Projects from the project Service by their ID. Due to apollographql/federation#336 my current approach is to try using the concrete types (not the interface) to make references to the other Service. Unfortunately I cannot get the Project Service / Gateway to finally resolve the references.

My schema in the Projects Service looks like this:
```
type Query {
projects: [Project]
}

interface Project {
id: ID!
niceName: String!
status: String!
}

type SoftwareDevelopmentProject implements Project @key(fields: "id") {
id: ID!
niceName: String!
status: String!
requiredEffortHours: Int!
}

type MarketingProject implements Project @key(fields: "id") {
id: ID!
niceName: String!
status: String!
budget: Int!
}
```

And the Rights service with the types using `extend` and `@key` looks like this:
```
type Query {
user: User
}

type User {
id: String!
name: String!
accessibleProjects: [Project]
}

extend interface Project {
id: ID! @external
}

extend type SoftwareDevelopmentProject implements Project @key(fields: "id") {
id: ID! @external
}

extend type MarketingProject implements Project @key(fields: "id") {
id: ID! @external
}
```

I did an analysis and the Apollo Gateway seems to request the Access-Rights Service for all Project IDs and then performs a Request to the Project Service. This request looks like:

```
Query:
"query($representations:[_Any!]!){_entities(representations:$representations){...on Project{niceName}}}"

Variables:
{
"representations": []
}
```
What I would expect is that the representations Array is filled with the IDs and typenames of the Projects.
Also I noticed the `...on Project` in the request, which is the interface, not the implementing types (even though `__resolveType` was called previously in the access rights Service), however this is might be not a real problem as I think it could be handled by the Projects Service.

Contributor guide

Open the contributing guide

Research direction

Use the linked reproduction with Apollo Gateway and inspect the federation request from the Access-Rights service to the Projects service. Start with the generated _entities query and its representations variable, then compare the observed request with the issue’s expected IDs, typenames, and fragment behavior. Done means references to implementing Project types resolve through the gateway.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.