-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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.
- Loading branch information
1 parent
95f5eb6
commit 297d6e3
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/core/parcel/test/integration/graphql-import/another.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fragment AnotherUserFragment on User { | ||
address | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/core/parcel/test/integration/graphql-import/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var local = require('./local.graphql'); | ||
|
||
module.exports = function () { | ||
return local; | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/core/parcel/test/integration/graphql-import/local.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# import './other.graphql' | ||
|
||
{ | ||
user(id: 6) { | ||
...UserFragment | ||
...AnotherUserFragment | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/core/parcel/test/integration/graphql-import/other.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# import './another.graphql' | ||
|
||
fragment UserFragment on User { | ||
firstName | ||
lastName | ||
} |