apollographql / apollographql/federation

Improve error messages for value types mismatches

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

Description

This PR adds a fix for how we check value types: https://github.com/apollographql/federation/pull/280 but the error message could be improved, for example:

```javascript
const [definitions] = createDocumentsForServices([
{
typeDefs: gql`
type Person {
age(relative: Boolean!): Int
}
`,
name: 'serviceA',
},
{
typeDefs: gql`
type Person {
age(relative: Boolean): Int
}
`,
name: 'serviceB',
},
]);

const errors = validateSDL(definitions, schema, [
UniqueTypeNamesWithFields,
]);
```

Returns this error:

```
[serviceA] Person -> A field's input type (`relative`) was defined differently in different services. `serviceA` and `serviceB` define `relative` as a Boolean! and Boolean respectively. In order to define `Person` in multiple places, the input values and their types must be identical.
```

It would be nice to include the field name in the error, like this:

```
[serviceA] Person.age -> A field's argument (`relative`) was defined differently in different services. `serviceA` and `serviceB` define the argument `relative` on `Person.age` as a Boolean! and Boolean respectively. In order to define `Person` in multiple places, the input values and their types must be identical.
```

Link to discussion and code: https://github.com/apollographql/federation/pull/280/files#r535572567

Contributor guide

Open the contributing guide

Research direction

Start with the validateSDL entry point and the UniqueTypeNamesWithFields rule described in the issue, then review PR #280 and its linked discussion for the existing value-type check. Update the mismatch error so it includes the field path and argument context shown in the expected message, and verify the example produces that wording.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.