File tree 13 files changed +194
-34
lines changed
13 files changed +194
-34
lines changed Original file line number Diff line number Diff line change @@ -11,19 +11,47 @@ Webpack loader for [`graphql-import`](https://github.com/graphcool/graphql-impor
11
11
yarn add --dev graphql-import-loader
12
12
```
13
13
14
- Add the following to the ` rules ` section in your ` webpack.config.js `
14
+ ## Usage
15
+
16
+ Resolve GraphQL file import statements as a string. See the tests for more details
17
+
18
+ ``` graphql
19
+ # import { A } from 'src/schema/a.graphql'
20
+ # import { B } from 'src/schema/b.graphql'
21
+ # import { C D } from 'src/schema/cd.graphql'
22
+
23
+ type Complex {
24
+ id : ID !
25
+ a : A !
26
+ b : B !
27
+ c : C !
28
+ d : D !
29
+ }
30
+ ```
15
31
16
32
```js
17
- rules: [{
18
- exclude: / node_modules/ ,
19
- test: / \. graphql$ / ,
20
- use: [{ loader: ' graphql-import-loader' }]
21
- }],
33
+ import typeDefs from './schema .graphql'
22
34
```
23
35
24
- ## Usage
36
+ ```js
37
+ // webpack.config.js
25
38
26
- You can now ` require ` or ` import ` ` .graphql ` files (resolved as strings) in your application:
39
+ module.exports = {
40
+ module : {
41
+ rules : [
42
+ {
43
+ exclude : /node_modules /,
44
+ test : /\.graphql $/,
45
+ use : [{ loader : 'graphql -import -loader ' }]
46
+ }
47
+ ]
48
+ }
49
+ }
50
+ ```
51
+
52
+ ## Examples
53
+
54
+ Simple Server:
27
55
28
56
``` ts
29
57
import { GraphQLServer } from ' graphql-yoga'
@@ -32,4 +60,9 @@ import typeDefs from './schema.graphql'
32
60
33
61
const server = new GraphQLServer ({ typeDefs , resolvers })
34
62
server .start (() => console .log (' Server running on :4000' ))
35
- ```
63
+ ```
64
+
65
+
66
+ Advanced:
67
+
68
+ [ serverless-prisma] ( https://github.com/jgeschwendt/serverless-prisma ) : Serverless starter kit using Prisma (early-stages)
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ "roots" : [
3
+ "<rootDir>"
4
+ ] ,
5
+ "transform" : {
6
+ "^.+\\.ts?$" : "ts-jest"
7
+ } ,
8
+ "testRegex" : "test/.*\\.test\\.ts$" ,
9
+ "moduleFileExtensions" : [
10
+ "js" ,
11
+ "ts" ,
12
+ "node"
13
+ ]
14
+ }
Original file line number Diff line number Diff line change 25
25
"scripts" : {
26
26
"prepare" : " npm run build" ,
27
27
"build" : " rm -rf dist && tsc -d" ,
28
- "test" : " npm run build"
29
- },
30
- "devDependencies" : {
31
- "typescript" : " 2.7.2"
28
+ "pretest" : " npm run build" ,
29
+ "test" : " jest"
32
30
},
33
31
"dependencies" : {
34
32
"graphql-import" : " ^0.4.5"
33
+ },
34
+ "devDependencies" : {
35
+ "@types/jest" : " ^22.1.4" ,
36
+ "@types/node" : " ^9.4.6" ,
37
+ "ts-jest" : " ^22.4.1" ,
38
+ "graphql" : " ^0.13.1" ,
39
+ "jest" : " ^22.4.2" ,
40
+ "memory-fs" : " ^0.4.1" ,
41
+ "typescript" : " ^2.7.2" ,
42
+ "webpack" : " ^4.0.1"
35
43
}
36
44
}
Original file line number Diff line number Diff line change 1
1
import { importSchema } from 'graphql-import'
2
2
3
- export default source => {
4
- this . value = source
5
- return `module.exports = \`${ importSchema ( source ) } \``
3
+ export default function ( source ) {
4
+ const callback = this . async ( ) ;
5
+
6
+ this . cacheable ( )
7
+
8
+ callback ( null , `module.exports = \`${ importSchema ( source ) } \`` )
6
9
}
Original file line number Diff line number Diff line change
1
+ import * as memoryfs from 'memory-fs'
2
+ import * as path from 'path'
3
+ import * as webpack from 'webpack'
4
+ import { Stats } from 'webpack'
5
+
6
+ export default ( fixture , options = { } ) => {
7
+ const compiler = webpack ( {
8
+ mode : 'development' ,
9
+ context : path . resolve ( __dirname ) ,
10
+ entry : `./fixtures/${ fixture } ` ,
11
+ output : {
12
+ path : path . resolve ( __dirname ) ,
13
+ filename : 'bundle.js' ,
14
+ } ,
15
+ module : {
16
+ rules : [ {
17
+ test : / \. g r a p h q l $ / ,
18
+ use : [
19
+ { loader : path . resolve ( __dirname , '..' , 'dist/src' ) }
20
+ ]
21
+ } ]
22
+ }
23
+ } )
24
+
25
+ compiler . outputFileSystem = new memoryfs ( )
26
+
27
+ return new Promise < Stats > ( ( resolve , reject ) => {
28
+ compiler . run ( ( err , stats ) => {
29
+ if ( err ) reject ( err )
30
+
31
+ resolve ( stats )
32
+ } )
33
+ } )
34
+ }
Original file line number Diff line number Diff line change
1
+ type A {
2
+ id : ID !
3
+ valueA : String
4
+ }
Original file line number Diff line number Diff line change
1
+ type B {
2
+ id : ID !
3
+ valueB : String
4
+ }
Original file line number Diff line number Diff line change
1
+ type C {
2
+ id : ID !
3
+ valueC : String
4
+ }
5
+
6
+ type D {
7
+ id : ID !
8
+ valueD : String
9
+ }
Original file line number Diff line number Diff line change
1
+ # import { A } from 'test/fixtures/a.graphql'
2
+ # import { B } from 'test/fixtures/b.graphql'
3
+ # import { C D } from 'test/fixtures/cd.graphql'
4
+
5
+ type Complex {
6
+ id : ID !
7
+ a : A !
8
+ b : B !
9
+ c : C !
10
+ d : D !
11
+ }
Original file line number Diff line number Diff line change
1
+ type Simple {
2
+ id : ID !
3
+ value : String
4
+ }
Original file line number Diff line number Diff line change
1
+ import compiler from './compiler'
2
+
3
+ const simple = `module.exports = \`type Simple {
4
+ id: ID!
5
+ value: String
6
+ }
7
+ \``
8
+
9
+ const complex = `module.exports = \`type Complex {
10
+ id: ID!
11
+ a: A!
12
+ b: B!
13
+ c: C!
14
+ d: D!
15
+ }
16
+
17
+ type A {
18
+ id: ID!
19
+ valueA: String
20
+ }
21
+
22
+ type B {
23
+ id: ID!
24
+ valueB: String
25
+ }
26
+
27
+ type C {
28
+ id: ID!
29
+ valueC: String
30
+ }
31
+
32
+ type D {
33
+ id: ID!
34
+ valueD: String
35
+ }
36
+ \``
37
+
38
+ const fixtures = {
39
+ 'simple.graphql' : simple ,
40
+ 'complex.graphql' : complex ,
41
+ }
42
+
43
+ Object . keys ( fixtures ) . forEach ( fixture => {
44
+ test ( `Fixture: ${ fixture } ` , async ( ) => {
45
+ const stats = await compiler ( fixture )
46
+ const output = stats . toJson ( ) . modules [ 0 ] . source
47
+ expect ( output ) . toBe ( fixtures [ fixture ] )
48
+ } )
49
+ } )
Original file line number Diff line number Diff line change 10
10
"outDir" : " dist" ,
11
11
"lib" : [" es2015" ]
12
12
},
13
- "exclude" : [" node_modules" ]
13
+ "exclude" : [
14
+ " dist" ,
15
+ " node_modules" ,
16
+ " test"
17
+ ]
14
18
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments