graphql / graphql/graphql-spec
Spec Bug...? ProvidedRequiredArgumentsRule fails to evaluate all potential runtime types
- Dominant language
- JavaScript
- Stars
- 14.6k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Consider the following schema:
```graphql
type Query {
someInterface: SomeInterface
}
interface SomeInterface {
echo(value: String! = "default"): String
}
type SomeType implements SomeInterface {
echo(value: String!): String
}
```
As mentioned by @vepanimas at https://github.com/graphql/graphql-js/issues/3214 => types implementing interfaces have to conform to their types, but not to their default values, and so the above is now considered valid.
Consider the following operation:
```graphql
{
someInterface {
echo
}
}
```
The ProvidedRequiredArgumentsRule as specified and implemented within the reference evaluation states that an argument for `echo` on `SomeInterface` is not required, because a default value exists, but at runtime, the execution portion of the spec and the implementation take default values from the concrete runtime type, ignoring the interface. The operation will validate successfully, but throw a runtime error.
Thoughts:
1. We either should (A) not allow default values on interface fields (because they are currently apparently never used) or (B) require that implementing types also have default values.
2. We can solve the validation/execution discrepancy either via option (B), or by (Z) changing the Validation Rule to inspect all the possible runtime types.
I think option (B) is a breaking change in terms of 1, because some schemas will break.
I think fixing the validation rule via option (B) or (Z) may also be a breaking change in terms of 2, because some operations will break => but does it count if it is a bug fix? Seems like it does, similar to https://github.com/graphql/graphql-spec/pull/1059
Contributor guide
Assessment
This issue has not been assessed yet.