1

Edit: @helfer suggested this might be a bug. Github issue

For a new application I am using Apollo to do the graphql management for me. I have multiple types that can also contain other types.

To simplify my life as a developer I want to use fragments to avoid duplicated code.

I am trying to use fragments for different types together.

but the query results in an error, because Subject fragments cannot be used for the BusinessArea type.

Is this a bug or did I miss something?

Def:

const subjectInfo = createFragment(gql`
  fragment subjectInfo on Subject {
    id
    name
  }`
)

const businessAreaInfo = createFragment(gql`
  fragment businessAreaInfo on BusinessArea {
    id
    name
    subjects {
      ...subjectInfo
    }
  }`,
  [subjectInfo]
)

graphql(gql`
query {
  businessAreas {
    ...businessAreaInfo
  }
}
`, {
  fragments: businessAreaInfo
})

Resulting query:

{
  businessAreas {
    ...businessAreaInfo
    ...subjectInfo
  }
}

fragment businessAreaInfo on BusinessArea {
  id
  name
  subjects {
    ...subjectInfo
  }
}

fragment subjectInfo on Subject {
  id
  name
}
Julius Breckel
  • 434
  • 3
  • 14

0 Answers0