File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ const { createServer } = require ( "http" ) ;
4
+ const { makeCompileQuery } = require ( "@benzene/jit" ) ;
5
+ const { Benzene, makeHandler, parseGraphQLBody } = require ( "@benzene/http" ) ;
6
+ const { createApolloSchema } = require ( "../lib/schemas/createApolloSchema" ) ;
7
+
8
+ const rawBody = ( req , done ) => {
9
+ let body = "" ;
10
+ req . on ( "data" , ( chunk ) => ( body += chunk ) ) ;
11
+ req . on ( "end" , ( ) => done ( body ) ) ;
12
+ } ;
13
+
14
+ const schema = createApolloSchema ( ) ;
15
+
16
+ const GQL = new Benzene ( {
17
+ schema,
18
+ compileQuery : makeCompileQuery ( ) ,
19
+ } ) ;
20
+
21
+ const graphqlHTTP = makeHandler ( GQL ) ;
22
+
23
+ const server = createServer ( ( req , res ) => {
24
+ rawBody ( req , ( rawBody ) =>
25
+ graphqlHTTP ( {
26
+ method : req . method ,
27
+ headers : req . headers ,
28
+ body : parseGraphQLBody ( rawBody , req . headers [ "content-type" ] ) ,
29
+ } ) . then ( ( result ) => {
30
+ res . writeHead ( result . status , result . headers ) ;
31
+ res . end ( JSON . stringify ( result . payload ) ) ;
32
+ } ) ,
33
+ ) ;
34
+ } ) ;
35
+
36
+ server . listen ( 4001 ) ;
Original file line number Diff line number Diff line change 28
28
"license" : " MIT" ,
29
29
"dependencies" : {
30
30
"@benzene/http" : " ^0.4.0" ,
31
+ "@benzene/jit" : " ^0.1.3" ,
31
32
"@graphql-tools/schema" : " ^8.3.1" ,
32
33
"apollo-opentracing" : " ^2.1.64" ,
33
34
"apollo-server-express" : " ^3.5.0" ,
You can’t perform that action at this time.
0 commit comments