Skip to content
Myr

feat: show stack-trace at graphql-server middleware (#161)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent c9053eb · Browse files · 3 files+10 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+10 added−1 removed

  • tests:+3 added−0 removed
  • other:+7 added−1 removed

3 files+10 added−1 removed

modified:src/middleware/graphql-server/index.test.ts+3 added
6 unmodified lines
7} from 'graphql'8import { Hono } from '@/hono'9import { errorMessages, graphqlServer } from '@/middleware/graphql-server'1011// Do not show `console.error` messages12jest.spyOn(console, 'error').mockImplementation()1314describe('errorMessages', () => {15 const messages = errorMessages(['message a', 'message b'])16 expect(messages).toEqual({17 errors: [
549 unmodified lines
modified:src/middleware/graphql-server/index.ts+4 added-1 removed
53 unmodified lines
54 try {55 params = await getGraphQLParams(c.req)56 } catch (e) {57 if (e instanceof Error) {58 console.error(`${e.stack || e.message}`)59 c.res = c.json(errorMessages([e.message], [e]), 400)60 }61 return62 }
20 unmodified lines
83 documentAST = parse(new Source(query, 'GraphQL request'))84 } catch (syntaxError: unknown) {85 // Return 400: Bad Request if any syntax errors errors exist.86 if (syntaxError instanceof Error) {87 console.error(`${syntaxError.stack || syntaxError.message}`)88 const e = new GraphQLError(syntaxError.message, {89 originalError: syntaxError,90 })91 c.res = c.json(errorMessages(['GraphQL syntax error.'], [e]), 400)
44 unmodified lines
136 operationName: operationName,137 })138 } catch (contextError: unknown) {139 if (contextError instanceof Error) {140 console.error(`${contextError.stack || contextError.message}`)141 const e = new GraphQLError(contextError.message, {142 originalError: contextError,143 nodes: documentAST,144 })
94 unmodified lines
239 }),240 }241}242240export const graphiQLResponse = () => {}243// export const graphiQLResponse = () => {}
modified:src/middleware/graphql-server/parse-body.ts+3 added