Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recurse through #import in GQL files #35

Closed
amcvitty opened this issue Oct 4, 2018 · 7 comments
Closed

Recurse through #import in GQL files #35

amcvitty opened this issue Oct 4, 2018 · 7 comments

Comments

@amcvitty
Copy link

amcvitty commented Oct 4, 2018

I'm trying to upgrade our app to Create React App 2.0 right now and in the process switching from graphql-tag/loader (used with some custom config in react-app-rewired)

So our syntax changes from

import QUERY from "myquery.gql"

to

import { loader } from "graphql.macro";
const QUERY = loader("myquery.graphql")

So that's fine, but I'm noticing that the #import macro also doesn't work like in graphql-loader.

If I have

myquery.gql:
#import "fields.gql"

query { 
  myobject {
    ...Fields
  }
}


fields.gql:
#import "subfields.gql"

fragment Fields on myobject {
  field1 { 
    ...SubFields
  }
} 

subfields.gql:

fragment SubFields on Field1 { 
   subfield1
   subfield2
}

The query that results is just


fragment Fields on myobject {
  field1 {
    ...SubFields
  }
}

{
  myobject {
    ...Fields
  }
}

That is - it doesn't recurse and parse the imports in the file it's imporing to do that second level of importing. We have a few objects with nested references to other objects and to avoid duplicating the same common fields in those objects we make frequent use of this.

The workaround right now is to make sure all the nested fragments are explicitly imported in the query, which is not super hard, but it gets more tricky if you want to add an import in a fragment that is used in multiple queries because you have to find and update all those queries. In short, I preferred the graphql-loader implementation.

So - is this a deliberate choice, or could this behaviour be added here?

@erictaylor
Copy link

+1 to this issue. Having the same difficulty.

@smilexu
Copy link

smilexu commented Nov 1, 2018

same issue for me

@bebbi
Copy link

bebbi commented Nov 20, 2018

Referencing my issue posted in CRA as the cause is likely here.

@henrykuzmick
Copy link

Same issue

evenchange4 pushed a commit that referenced this issue Jan 24, 2019
This PR adds recursive imports processing which allows imported files to import other files. It solves #35
@evenchange4
Copy link
Owner

Release v1.2.0 with recursive import feature.

@FezVrasta
Copy link
Contributor

@evenchange4 should we close this issue since it's fixed?

@evenchange4
Copy link
Owner

Sure, close it. Please feel free to reopen this issue if the problem still occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants