Graphql-tag: When including a document node with sub fragments in gql tag include all fragments

Created on 28 Sep 2017  Â·  8Comments  Â·  Source: apollographql/graphql-tag

Say I have a fragment A which has two fragments B and C

fragmentA.gql:

#import "fragmentB"
#import "fragmentC"

fragment A {
  ...B
  items {
      ...C
   }
}

which I import like so:

import fragmentA from './fragmentA.gql'

if I use fragment A in query D like so:

export const queryD = gql`
query getSomeAlphabet {
      id
      ...A
}
${fragmentA}`

The document node queryD only has 2 definitions, the getSomeAlphabet query and A but not the definitions for B and C.

Is this a bug, or am I doing something wrong here?

bug duplicate

Most helpful comment

i believe this is resolved by #105 and has to do with how we serialize stuff using the webpack loader.

All 8 comments

Apologies for brevity, on my phone.

You need to interpolate the fragment B and C in your initial definition of
fragment A, too. The document needs the interpolated value of all the
fragments you're using.
On Wed, Sep 27, 2017 at 5:04 PM Kenneth Bambridge notifications@github.com
wrote:

Say I have a fragment A which has two fragments B and C

fragmentA.gql:

fragment A {
...B
items {
...C
}
}

which I import like so:

import fragmentA from './fragmentA.gql'

if I use fragment A in query D like so:

export const queryD = gqlquery getSomeAlphabet { id ...A}${fragmentA}

The document node queryD only has 2 definitions, the getSomeAlphabet
query and A but not the definitions for B and C.

Is this a bug, or am I doing something wrong here?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/apollographql/graphql-tag/issues/125, or mute the
thread
https://github.com/notifications/unsubscribe-auth/ABERRhypusNUGveC3R67NLYe6h_GTqTHks5smuKPgaJpZM4Pmjkf
.

Thanks @jnwng for the quick response. I forgot to include in the original fragment, but there are two #import statements pulling in the other fragments that are used. Is that what you were referring to?

Ah, yes. If you have the webpack loader set up properly I'd expect the

import statements to include the definitions for those fragments into the

document. I'd double check that that is actually happening - maybe check
what's in fragment A when you're defining query D. Might be something up
with the imports.
On Wed, Sep 27, 2017 at 5:12 PM Kenneth Bambridge notifications@github.com
wrote:

Thanks @jnwng https://github.com/jnwng for the quick response. I forgot
to include in the original fragment, but there are two #import statements
pulling in the other fragments that are used. Is that what you were
referring to?

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/apollographql/graphql-tag/issues/125#issuecomment-332690547,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABERRqskowosCCLbe4t_ezA2HKHsOo2Iks5smuRSgaJpZM4Pmjkf
.

I logged the equivalent of fragmentA and i double checked it had all the definitions, but when putting it into queryD it only had to the top level fragment from fragmentA unfortunately.

The way I got around this was to make a separate .gql file for queryD and #import fragmentA

Ah, yes now I recall that there's an issue interpolating fragments that are
loaded via the webpack loader. Glad you figured it out!
On Wed, Sep 27, 2017 at 6:12 PM Kenneth Bambridge notifications@github.com
wrote:

The way I got around this was to make a separate .gql file for queryD and

import fragmentA

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/apollographql/graphql-tag/issues/125#issuecomment-332698772,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABERRpsDkyr9gL3dx8xxnBzxPG1YIMtsks5smvKJgaJpZM4Pmjkf
.

@jnwng Is that being tracked elsewhere? Sometimes its more convenient to use the gql tag because its the only way I know of to allow multiple import/exports (until #102 is completed)

i believe this is resolved by #105 and has to do with how we serialize stuff using the webpack loader.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jnwng picture jnwng  Â·  10Comments

good-idea picture good-idea  Â·  3Comments

codepunkt picture codepunkt  Â·  7Comments

hopewise picture hopewise  Â·  8Comments

val-samonte picture val-samonte  Â·  9Comments