Questions tagged [graphql-fragments]

9 questions
5
votes
1 answer

Can you nest fragments in GraphQL?

Say you have fragment B, which depends on fragment A. I wonder whether you can plug-and-play fragment B in a query.
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
3
votes
0 answers

GraphQL: Nesting Reusable Interface Fragment within a Type Fragment

I'm new to GraphQL and Apollo Client. I'm trying to write DRY queries as much possible and found that Fragments can be of great help. Here is how my GraphQL schema would look like: interface header { # Implemented by multiple types uuid: ID! …
Code.Decode
  • 3,736
  • 4
  • 25
  • 32
2
votes
2 answers

Deep merging fragments

I'm using a GraphQL API (which I do not own) to access data. I make extensive use of fragments and one problem I've run into more than once is that fragments don't seem to deep-merge. Consider the following query: fragment BasicInfo on Person { …
Sandy Gifford
  • 7,219
  • 3
  • 35
  • 65
1
vote
1 answer

Shouldn't variables be defined on fragment calls in GraphQL?

I'm new to GraphQL. I was going through the documentation and found something which I feel is odd. The way to pass data to variables in fragments is to do it through the root query the fragments are part of. The example given in the docs is repeated…
StackMatch
  • 99
  • 1
  • 12
1
vote
1 answer

How to check requested GraphQL fields in Java with fragments?

I have a GraphQL query similar to this: query { getPosts { ...PostFragment } } fragment SpecificPostFragment on SpecificPost { owner { id name } } fragment PostFragment on Post { id object ... on SpecificPost { …
Climooo
  • 255
  • 2
  • 13
0
votes
1 answer

Apollo GraphQL client data is undefined when using fragments

I've a Next.js project using the Apollo GraphQL client 3.7.17, where the following code works for me: const { loading, data, error } = useQuery(gql` query GetTeamCurrentWeek($teamId: ID!) { team(id: $teamId, idType: DATABASE_ID) { …
linucks
  • 687
  • 1
  • 8
  • 14
0
votes
0 answers

NestJS + GraphQL mutation: how to return asked relations?

Here is a mutation to create a new Company: mutation CompanyCreate($input: RegisterInput!) { companyCreate(input: $input) { ...CompanyFields } } Creating this company triggers also the creation of other entities, such as User These entities…
frinux
  • 2,052
  • 6
  • 26
  • 47
0
votes
1 answer

GraphQL cursor pagination and fragments?

So I jumped in the middle of some project, and I'm supposed to add cursor pagination in GraphQL to a list within an object. The query (fetches only a single object, within which do we get the data we need to paginate): export const GET_OBJECT =…
-2
votes
1 answer

Is there a way to define a GraphQL fragment using TypeGraphQL?

Couldn't find anything related to GraphQL fragments in the TypGraphQL docs. Am I missing something or is it not possible to do so.