graphql / graphql/graphql-spec

Polymorphic name

Open
#933 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Hi,

I haven't found a way to give an alias to a type, so I was wondering if we could have alias for type only on polymorph fragments.

Consider we have a type called `Background` which is an interface that has `Simple` and `Image` as possible types.
Using them are ok with fragments:

```graphql
query {
background { # our interface: Background
id
...on Simple { # sub type Simple
foo color
}
...on Image { # sub type Image
bar url
}
}
}
```

That is simple and works, however, consider we have some nested stuff that has `background` info but as not as much as the above type, so they aren't phyisically the same:

```graphql
query {
some {
nested {
stuff {
background { # here we have another interface, which has less info than the original background
...on NestedSimple {
color # we can't access foo here
}
...on NesteImage {
url # we can't access bar here
}
}
}
}
}
}
```

`NestedSimple` is basically a `Simple` with less accessible fields, so would be nice to be able to use `Simple` instead of `NestedSimple` in the fragment call.
`__typename` would still be `NestedSimple`

This was just a simple example, but as the nesting go deeper, the uglier the typename become.

I've implemented this in my Dart graphql server and is working like a charm and thought it could be a nice addition to the spec.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.