movio / bramble

A federated GraphQL API gateway
https://movio.github.io/bramble/
MIT License
497 stars 55 forks source link

Fragment not working as expected for interface types #151

Closed azadasanali closed 2 years ago

azadasanali commented 2 years ago

Problem Statement

When an interface type is implemented in graphql schema, we are able to query with spread operator and on Type pattern. But the same cannot be achieved by using Fragments as exemplified below

Example Request

interface Book {
  title: String!
}

type Textbook implements Book {
  title: String! # Must be present
  author: String!
}

type Magazine implements Book {
  title: String! # Must be present
  publisher: String!
}

type Query {
  books: [Book!] # Can include Textbook objects
}

fragment TextBookFragment on Textbook {
      author # Only present in Textbook
}

fragment MagazineFragment on Magazine {
      publisher # Only present in Magazine
}

# this fails
query GetBooks {
  books {
    __typename
    title
    ... TextBookFragment
    ... MagazineFragment
  }
}

# this passes
query GetBooks {
  books {
    __typename
    title
    ... on Textbook {
     author
    }
    ... on Magazine {
      publisher
    }
  }
}

Response if TextBook is not found in federated query we are getting

{
  "errors": [
    {
      "message": "got a null response for non-nullable field \"author\"",
    }
}
lucianjon commented 2 years ago

Thanks @azadasanali, I've managed to reproduce it and we'll get onto fixing it.

azadasanali commented 2 years ago

@lucianjon When this will be released?

lucianjon commented 2 years ago

@azadasanali We’ll get a release out when we’re back in the office on Monday

nmaquet commented 2 years ago

@azadasanali Here you go! https://github.com/movio/bramble/releases/tag/v1.4.0