apollographql / apollographql/federation

Federation subgraphs skipping interface's resolveType on graphql-js schemas

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

Description

### Issue Description

If you use graphql-js to define a schema with an interface (GraphQLInterfaceType) and then buildSubgraphSchema to build a subgraph, interface's resolveType in the schema are not being copied over, which leads to the runtime error:

```
"Abstract type \"Character\" must resolve to an Object type at runtime for field \"Query.character\". Either the \"Character\" type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."
```

I created https://github.com/juampynr/subgraph-interface to illustrate this bug.

### Link to Reproduction

https://github.com/juampynr/subgraph-interface

### Reproduction Steps

Run the following commands to see the error:

```
git clone git@github.com:juampynr/subgraph-interface.git
cd subgraph-interface
nvm use
npm i
node index.js
curl --location 'http://localhost:4000/graphql' \
--header 'Content-Type: application/json' \
--data '{"query":"query {\n character(id: \"1\") {\n id\n name\n ... on Hero {\n superpower\n }\n ... on Villain {\n evilPlan\n }\n }\n}","variables":{}}'
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked subgraph-interface reproduction, especially its index.js entry point, and trace buildSubgraphSchema when it receives a graphql-js schema containing GraphQLInterfaceType. Confirm the failing curl query, then verify that the interface's resolveType is retained and the same query resolves the concrete type without the runtime error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.