question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing array of fragments in query fails

See original GitHub issue

Passing array of fragments to query fails, e.g.:

query SomeQuery {
  field {
     someRuntimeGeneratedFieldsOnFragments
  }
}
${arrayOfFragments}

with error

Syntax Error GraphQL (25:1) Unexpected [

24: }
25: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
    ^
26: 

It is working as expected when using createFragments + fragments option in apollo-client, which is being deprecated in next version.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
nekitkcommented, Oct 17, 2019

found a way to insert an array of fragments into query by combining them into a single gql-tag:

gql`
    query {
        ...fragment1
        ...fragment2
    }
    
    ${fragments.reduce((acc, fragment) => gql`
        ${acc}
        ${fragment}
    `, '')}
`
1reaction
jnwngcommented, Jan 31, 2017

i think there is some use case for being able to pass both an array of fragments or map whose values are fragments (as those are often how our components are storing references to the fragments), but there hasn’t been so much pain in just being explicit about what fragments are being interpolated. closing this for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fragments - Apollo GraphQL Docs
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. ... Every fragment includes a subset...
Read more >
Use GraphQL to retrieve an object that contains an array of ...
Fragments can be defined inline within a selection set. This is done to conditionally include fields based on their runtime type.
Read more >
Querying Postgres Array types with fragment. - Google Groups
I'm trying to query a table with an array type and have been unable to get it to work successfully. The basic setup...
Read more >
Pass a list or other type to custom Ecto query - Elixir Forum
A fragment lets you execute a SQL fragment directly into the database, maybe you could try wrapping the jsonb_array_elements function call into ...
Read more >
Fragment | Android Developers
Interaction with fragments is done through FragmentManager , which can be ... a string of text based on an index of a string...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found