Skip to content

Commit

Permalink
move around
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-lee committed Mar 31, 2022
1 parent 6696141 commit c4d7a90
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
52 changes: 24 additions & 28 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,33 @@ const core = async <TContext>({
if (isPreflight) {
return new Response(null, { status: 204, headers })
}
try {
const helixRequest = await createHelixRequest(request)

const { operationName, query, variables } =
getGraphQLParameters(helixRequest)
const helixRequest = await createHelixRequest(request)

const result = await processRequest({
operationName,
query,
variables,
request: helixRequest,
schema,
parse,
validate,
execute,
contextFactory,
})
const { operationName, query, variables } = getGraphQLParameters(helixRequest)

switch (result.type) {
case 'RESPONSE':
return getResponse(result, headers)
case 'PUSH':
// @todo cors headers
return getPushResponseSSE(result, request)
case 'MULTIPART_RESPONSE':
return getMultipartResponse(result, Response, ReadableStream as any)
default:
return new Response('Not supported.', { status: 405 })
}
} catch {
return new Response('Bad Request', { status: 400 })
const result = await processRequest({
operationName,
query,
variables,
request: helixRequest,
schema,
parse,
validate,
execute,
contextFactory,
})

switch (result.type) {
case 'RESPONSE':
return getResponse(result, headers)
case 'PUSH':
// @todo cors headers
return getPushResponseSSE(result, request)
case 'MULTIPART_RESPONSE':
return getMultipartResponse(result, Response, ReadableStream as any)
default:
return new Response('Not supported.', { status: 405 })
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/helix-flare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ const helixFlare = async <TContext>(
schema: GraphQLSchema,
{ middlewares = [], access, contextFactory }: Options<TContext> = {},
) => {
return core({
request,
schema: applyMiddleware(schema, ...middlewares),
contextFactory,
access,
})
try {
return core({
request,
schema: applyMiddleware(schema, ...middlewares),
contextFactory,
access,
})
} catch (e) {
if (e instanceof SyntaxError) {
return new Response('Bad request', {
status: 400,
headers: { 'Content-Type': 'text/plain' },
})
}
}
}

export default helixFlare

0 comments on commit c4d7a90

Please sign in to comment.