diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 829ca42..088c234 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 16.9 + node-version: 20 - run: npm i - run: npm run lint - run: npm test @@ -27,9 +27,9 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 16.9 + node-version: 20 - run: npm i - - run: npm run coverage + - run: npm run test:coverage - uses: codecov/codecov-action@v1 publish-npm: @@ -42,7 +42,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 16.9 + node-version: 20 registry-url: https://registry.npmjs.org/ scope: '@hydre' - run: npm ci diff --git a/package.json b/package.json index eafa002..c3c98e4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "./tinyhttp": "./src/tinyhttp.js" }, "scripts": { - "test": "node --test test/**/*.test.js", + "test": "node --test test/*.test.js", "test:coverage": "c8 --reporter=text --reporter=html --reporter=lcov npm test", "typecheck": "tsc --noEmit", "lint": "eslint . && prettier . --check", diff --git a/src/fastify.js b/src/fastify.js index daab086..95ecdd6 100644 --- a/src/fastify.js +++ b/src/fastify.js @@ -9,8 +9,16 @@ const Fastify = ({ body }, reply) => { } catch (error) { const graphql_error = error instanceof GraphQLError ? error : new GraphQLError(error.message) - reply.status(200).type('application/json').send({ errors: [graphql_error] }) - return { query: null, variable_values: null, operation_name: null, reply: () => {} } + reply + .status(200) + .type('application/json') + .send({ errors: [graphql_error] }) + return { + query: null, + variable_values: null, + operation_name: null, + reply: () => {}, + } } const { query, variables, operationName, operation_name } = body diff --git a/src/koa.js b/src/koa.js index fbfb1a3..d204b11 100644 --- a/src/koa.js +++ b/src/koa.js @@ -14,7 +14,12 @@ const Koa = context => { context.status = 200 context.type = 'application/json' context.body = { errors: [graphql_error] } - return { query: null, variable_values: null, operation_name: null, reply: () => {} } + return { + query: null, + variable_values: null, + operation_name: null, + reply: () => {}, + } } const { query, variables, operationName, operation_name } = request_body diff --git a/src/lambda.js b/src/lambda.js index 92d14b1..ba5d4c5 100644 --- a/src/lambda.js +++ b/src/lambda.js @@ -7,7 +7,7 @@ const Lambda = ({ body: raw_body }, context, reply) => { let parsed try { parsed = JSON.parse(raw_body) - } catch (error) { + } catch { reply(null, { statusCode: 400, body: JSON.stringify({ @@ -24,7 +24,9 @@ const Lambda = ({ body: raw_body }, context, reply) => { reply(null, { statusCode: 200, body: JSON.stringify({ - errors: [error instanceof GraphQLError ? error : { message: error.message }], + errors: [ + error instanceof GraphQLError ? error : { message: error.message }, + ], }), }) return { query: null, variable_values: null, operation_name: null, reply } diff --git a/src/tinyhttp.js b/src/tinyhttp.js index 1188d64..21340e3 100644 --- a/src/tinyhttp.js +++ b/src/tinyhttp.js @@ -10,7 +10,12 @@ const TinyHttp = ({ body = {} }, response) => { const graphql_error = error instanceof GraphQLError ? error : new GraphQLError(error.message) response.status(200).json({ errors: [graphql_error] }) - return { query: null, variable_values: null, operation_name: null, reply: () => {} } + return { + query: null, + variable_values: null, + operation_name: null, + reply: () => {}, + } } const { query, variables, operationName, operation_name } = body diff --git a/test/fastify.test.js b/test/fastify.test.js index 78f1382..4e89df7 100644 --- a/test/fastify.test.js +++ b/test/fastify.test.js @@ -10,12 +10,12 @@ import graphql_http from '../src/fastify.js' async function create_server(options) { const fastify = Fastify() fastify.post('/', graphql_http(options)) - await fastify.listen({ port: 3001 }) + await fastify.listen({ port: 3002 }) return fastify } async function request({ query, variables = {}, operation_name = null } = {}) { - const response = await fetch('http://localhost:3001', { + const response = await fetch('http://localhost:3002', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/test/index.test.js b/test/index.test.js index bce20c0..f310c38 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -145,12 +145,15 @@ test('koa adapter', async t => { } }) - await t.test('should return error for query exceeding size limit', async () => { - const huge_query = `{ ${'me { name } '.repeat(20000)} }` - const { errors } = await request({ query: huge_query }) - assert.ok(errors) - assert.ok(errors[0].message.toLowerCase().includes('too large')) - }) + await t.test( + 'should return error for query exceeding size limit', + async () => { + const huge_query = `{ ${'me { name } '.repeat(20000)} }` + const { errors } = await request({ query: huge_query }) + assert.ok(errors) + assert.ok(errors[0].message.toLowerCase().includes('too large')) + }, + ) await t.test('should timeout slow build_context', async () => { const Koa = (await import('koa')).default diff --git a/test/lambda.test.js b/test/lambda.test.js index 59b01ad..55f9e35 100644 --- a/test/lambda.test.js +++ b/test/lambda.test.js @@ -146,18 +146,21 @@ test('lambda adapter', async t => { assert.ok(body.errors[0].message.toLowerCase().includes('json')) }) - await t.test('should return error for query exceeding size limit', async () => { - const huge_query = `{ ${'me { name } '.repeat(20000)} }` - const event = create_lambda_event({ - query: huge_query, - }) - const result = await invoke_lambda(event) - - assert.strictEqual(result.statusCode, 200) - const body = JSON.parse(result.body) - assert.ok(body.errors) - assert.ok(body.errors[0].message.toLowerCase().includes('too large')) - }) + await t.test( + 'should return error for query exceeding size limit', + async () => { + const huge_query = `{ ${'me { name } '.repeat(20000)} }` + const event = create_lambda_event({ + query: huge_query, + }) + const result = await invoke_lambda(event) + + assert.strictEqual(result.statusCode, 200) + const body = JSON.parse(result.body) + assert.ok(body.errors) + assert.ok(body.errors[0].message.toLowerCase().includes('too large')) + }, + ) await t.test('should return error for non-object request body', async () => { const event = {