forked from wappla/graphql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateGraphqlRequestHandler.ts
More file actions
32 lines (31 loc) · 927 Bytes
/
Copy pathcreateGraphqlRequestHandler.ts
File metadata and controls
32 lines (31 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { IncomingMessage, ServerResponse } from 'http'
import processGraphqlRequest from './processGraphqlRequest'
import { readRequestBody } from './utils'
import GraphqlQueryStore from './GraphqlQueryStore'
export default function createGraphqlRequestHandler(
store: GraphqlQueryStore,
context: any,
processFileUploads?: (req: IncomingMessage) => Promise<any>
) {
return async (
req: IncomingMessage,
res: ServerResponse
) => {
const { status, text, body } = await processGraphqlRequest(req, {
store,
context,
processFileUploads,
readRequestBody,
})
if (text) {
res.writeHead(status)
res.end(text)
}
if (body) {
res.writeHead(status, {
'Content-Type': 'application/json',
})
res.end(JSON.stringify(body))
}
}
}