-
-
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.
- Loading branch information
1 parent
463c570
commit 8f1f497
Showing
7 changed files
with
87 additions
and
0 deletions.
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
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,22 @@ | ||
const Asset = require('../Asset'); | ||
const localRequire = require('../utils/localRequire'); | ||
|
||
class GraphqlAsset extends Asset { | ||
constructor(name, pkg, options) { | ||
super(name, pkg, options); | ||
this.type = 'js'; | ||
} | ||
|
||
async parse(code) { | ||
let gql = await localRequire('graphql-tag', this.name); | ||
return gql(code); | ||
} | ||
|
||
generate() { | ||
return { | ||
js: `module.exports=${JSON.stringify(this.ast, false, 2)};` | ||
}; | ||
} | ||
} | ||
|
||
module.exports = GraphqlAsset; |
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,33 @@ | ||
const assert = require('assert'); | ||
const gql = require('graphql-tag'); | ||
const {bundle, run, assertBundleTree} = require('./utils'); | ||
|
||
describe('graphql', function() { | ||
it('should support requiring graphql files', async function() { | ||
let b = await bundle(__dirname + '/integration/graphql/index.js'); | ||
|
||
assertBundleTree(b, { | ||
name: 'index.js', | ||
assets: ['index.js', 'local.graphql'], | ||
childBundles: [] | ||
}); | ||
|
||
let output = run(b); | ||
assert.equal(typeof output, 'function'); | ||
assert.deepEqual( | ||
output().definitions, | ||
gql` | ||
{ | ||
user(id: 5) { | ||
...UserFragment | ||
} | ||
} | ||
fragment UserFragment on User { | ||
firstName | ||
lastName | ||
} | ||
`.definitions | ||
); | ||
}); | ||
}); |
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; | ||
}; |
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,9 @@ | ||
{ | ||
user(id: 5) { | ||
...UserFragment | ||
} | ||
} | ||
fragment UserFragment on User { | ||
firstName | ||
lastName | ||
} |
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