-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Import directive within GraphQL files #1477
Comments
Haven't seen anyone working on it. |
@hmaurer did you ever get around implementing this feature? I am not even sure how else do you share fragments between queries/mutations unless you are able to import them in the |
HI @agonbina ! No, sorry :( I moved away from |
There is a workaround to get this to work and still keep your fragments in
It is more cumbersome but on the other hand you don't need to use the |
I created PR #1817 to add this feature |
An alternative to #1817 that doesn't rely on using `graphql-tag/loader`, which is a Webpack loader. #### What this does: 1. Recursively traverse the GraphQL files. 2. Collect all the imports into a map. 3. Concatenate them. 4. Parse the result into an AST. #### What this doesn't do: This PR (as of time of writing) does not have feature parity with `graphql-tag/loader`, meaning that: * It does not de-duplicate fragments that have the same name. _This is a behavior that I personally disapprove of since it can lead to surprising results instead of throwing an error if a user accidentally (however unlikely) reuses an already defined fragment name._ * It does not collect multiple defined queries/mutations and make them individually require-able from a JavaScript parent. If the above behaviours are desired then I can implement them.
An alternative to #1817 that doesn't rely on using `graphql-tag/loader`, which is a Webpack loader. #### What this does: 1. Recursively traverse the GraphQL files. 2. Collect all the imports into a map. 3. Concatenate them. 4. Parse the result into an AST. #### What this doesn't do: This PR (as of time of writing) does not have feature parity with `graphql-tag/loader`, meaning that: * It does not de-duplicate fragments that have the same name. _This is a behavior that I personally disapprove of since it can lead to surprising results instead of throwing an error if a user accidentally (however unlikely) reuses an already defined fragment name._ * It does not collect multiple defined queries/mutations and make them individually require-able from a JavaScript parent. If the above behaviours are desired then I can implement them.
Hi!
I am opening this issue to ask whether the addition of an import directive in GraphQL (.graphql) files has been considered and/or is currently being worked on. To be more specific, I am referring to the
#import
syntax used bywebpack-graphql-loader
, like so:The implementation by
webpack-graphql-loader
is a little dirty but pragmatic (they essentially do a search-and-replace for "#import" directives).Since this is also the recommended approach in Apollo's documentation, I think that it would be a useful addition to Parcel.
I did not open this issue as a feature request because if this is not something currently being worked on I would be happy to contribute myself.
The text was updated successfully, but these errors were encountered: