I have a schema like:
interface WithStaff {
staff: [Collaboration!]!
}
interface Metadata {
id: String! @id @search(by: [hash])
createdAt: DateTime!
modifiedAt: DateTime!
generation: Int!
version: Int!
}
interface Collaborator {
collaborations: [Collaboration!]!
}
type Anime implements Metadata & WithStaff {
name: String
}
type Collaboration implements Metadata {
"""
Organization or Person
"""
collaborator: Collaborator! @hasInverse(field: collaborations)
"""
Episode, Anime, Manga, Volume, Chapter, ...
"""
content: WithStaff! @hasInverse(field: staff)
}
type Organization implements Metadata & Collaborator {
foundation: Date
name: String
}
type Person implements Metadata & Collaborator {
name: String
}
if I run the query
query {
queryAnime(filter: {id: {eq: "AS0N2fOigo8X-ViL"}}) {
staff {
collaborator {
__typename
... on Organization {
id
}
}
}
}
}
I expect to get all the organization involved with this anime (reading the GraphQL doc when a fragment is specified, it returns the fields inside of the fragment only for the entities which are of the fragment type)
Instead i get
{
"data": {
"queryAnime": [
{
"staff": [
{
"collaborator": {
"__typename": "Organization",
"id": "AS0vZTJ78C7wLIb3"
}
},
{
"collaborator": {
"__typename": "Organization",
"id": "AS0i6UMuZ7Fd2BqJ"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS0MqA6d8p7Rwpq_"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS0CDrNrC4LIUsJZ"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS0ZAJZC77Rys1gU"
}
},
{
"collaborator": {
"__typename": "Organization",
"id": "AS0OqJKJ4lTUKSrs"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS0Q7qCjHlmjlJ8K"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS0_89Yzr8G8lIZk"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS0_89Yzr8G8lIZk"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS0USJ2_3ePCXWZ9"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS05buZfC262v7AQ"
}
},
{
"collaborator": {
"__typename": "Person",
"id": "AS0R2qEUF3PSQEh2"
}
}
]
}
]
},
"extensions": {
"touched_uids": 60
}
}
Wich is a mix between all the entities, regardless the type.
I think it’s a bug derived from the fact that both Organization and Person implement the Metadata interface and both have the id field. I’m not an ace with GraphQL, but i feel like the objects returned should depend on the fragment declaration and not if the underlying entity satisfies or not the fields inside the fragment itself