File tree Expand file tree Collapse file tree 10 files changed +821
-0
lines changed
packages/graphql-playground-middleware-koa Expand file tree Collapse file tree 10 files changed +821
-0
lines changed Original file line number Diff line number Diff line change
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ node_modules
5
+ example /node_modules
6
+ example /yarn.lock
7
+
8
+ # testing
9
+ /coverage
10
+
11
+ # production
12
+ /dist
13
+
14
+ # misc
15
+ .DS_Store
16
+ .env
17
+ npm-debug.log
18
+ .idea
Original file line number Diff line number Diff line change
1
+ # GraphQL Playground Koa.js Example
2
+
3
+ ``` sh
4
+ $ yarn
5
+ $ node index.js
6
+ ```
Original file line number Diff line number Diff line change
1
+ const koa = require ( 'koa' )
2
+ const koaRouter = require ( 'koa-router' )
3
+ const koaBody = require ( 'koa-bodyparser' )
4
+ const { graphqlKoa } = require ( 'apollo-server-koa' )
5
+ const { makeExecutableSchema} = require ( 'graphql-tools' )
6
+ const koaPlayground = require ( 'graphql-playground-middleware-koa' )
7
+
8
+ const schema = makeExecutableSchema ( {
9
+ typeDefs : `
10
+ type Query {
11
+ hello: String!
12
+ }
13
+ schema {
14
+ query: Query
15
+ }
16
+ ` ,
17
+ resolvers : {
18
+ Query : {
19
+ hello : ( ) => 'world' ,
20
+ } ,
21
+ } ,
22
+ } )
23
+
24
+ const app = new koa ( ) ;
25
+ const router = new koaRouter ( ) ;
26
+ const PORT = 4000 ;
27
+
28
+ // koaBody is needed just for POST.
29
+ app . use ( koaBody ( ) ) ;
30
+
31
+ router . post ( '/graphql' , graphqlKoa ( { schema } ) ) ;
32
+
33
+ router . all ( '/playground' , koaPlayground ( {
34
+ endpoint : '/graphql'
35
+ } ) )
36
+
37
+ app . use ( router . routes ( ) ) ;
38
+ app . use ( router . allowedMethods ( ) ) ;
39
+ app . listen ( PORT ) ;
40
+
41
+ console . log ( `Serving the GraphQL Playground on http://localhost:${ PORT } /playground` )
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " koa" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " " ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords" : [],
10
+ "author" : " " ,
11
+ "license" : " ISC" ,
12
+ "dependencies" : {
13
+ "apollo-server-koa" : " ^1.2.0" ,
14
+ "graphql" : " ^0.11.7" ,
15
+ "graphql-playground-middleware-koa" : " ^1.0.0" ,
16
+ "graphql-tools" : " ^2.7.1" ,
17
+ "koa" : " ^2.3.0" ,
18
+ "koa-bodyparser" : " ^4.2.0" ,
19
+ "koa-router" : " ^7.2.1"
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments