Skip to content

[Schema] Implementing interfaces with covariant return types. #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2015

Conversation

leebyron
Copy link
Collaborator

This proposes loosening the definition of implementing an interface by allowing an implementing field to return a subtype of the interface field's return type.

This example would previously be an illegal schema, but becomes legal after this diff:

interface Friendly {
  bestFriend: Friendly
}

type Person implements Friendly {
  bestFriend: Person
}

@dschafer
Copy link
Contributor

This looks good. If we introduce union/interface types into the input system, we'll want to be careful (since the input type system should probably be contravariant and not covariant, but for the output type system this looks exactly right.

@leebyron
Copy link
Collaborator Author

Yeah, currently the only possible pseudo-contravariance in input types in required (non-null) vs optional (nullable) but supporting that causes other issues. I think we'll need to divorce argument requirement from argument type nullability to support argument contravariance in the future. For now, the spec and impl for inputs remains invariant.

@dschafer
Copy link
Contributor

Yeah, currently the only possible pseudo-contravariance in input types in required (non-null) vs optional (nullable) but supporting that causes other issues. I think we'll need to divorce argument requirement from argument type nullability to support argument contravariance in the future.

Yep, I don't think we should do anything differently right now, just making a mental note if we ever do.

This proposes loosening the definition of implementing an interface by allowing an implementing field to return a subtype of the interface field's return type.

This example would previously be an illegal schema, but become legal after this diff:

```graphql
interface Friendly {
  bestFriend: Friendly
}

type Person implements Friendly {
  bestFriend: Person
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants