diff --git a/api-js/index.js b/api-js/index.js index 61995c0eb..df366688a 100644 --- a/api-js/index.js +++ b/api-js/index.js @@ -24,10 +24,17 @@ const { options: databaseOptions({ rootPass }), }) - Server(PORT, maxDepth, complexityCost, scalarCost, objectCost, listFactor, { - query, - collections, - transaction, + Server({ + maxDepth, + complexityCost, + scalarCost, + objectCost, + listFactor, + context: { + query, + collections, + transaction, + }, }).listen(PORT, (err) => { if (err) throw err console.log(`🚀 Server ready at http://localhost:${PORT}/graphql`) diff --git a/api-js/src/__tests__/server.test.js b/api-js/src/__tests__/server.test.js index 939abb5ac..d547310ba 100644 --- a/api-js/src/__tests__/server.test.js +++ b/api-js/src/__tests__/server.test.js @@ -2,7 +2,6 @@ import request from 'supertest' import { Server } from '../server' const { - PORT = 4000, DEPTH_LIMIT: maxDepth, COST_LIMIT: complexityCost, SCALAR_COST: scalarCost, @@ -41,19 +40,18 @@ describe('parse server', () => { describe('endpoint is alive', () => { it('returns 200', async () => { const response = await request( - Server( - PORT, + Server({ maxDepth, complexityCost, scalarCost, objectCost, listFactor, - { + context: { query: jest.fn(), collections: jest.fn(), transaction: jest.fn(), }, - ), + }), ) .post('/graphql') .set('Accept', 'application/json') @@ -66,10 +64,17 @@ describe('parse server', () => { describe('query cost is too high', () => { it('returns an error message', async () => { const response = await request( - Server(PORT, maxDepth, 1, 100, 100, 100, { - query: jest.fn(), - collections: jest.fn(), - transaction: jest.fn(), + Server({ + maxDepth, + complexityCost: 1, + scalarCost: 100, + objectCost: 100, + listFactor: 100, + context: { + query: jest.fn(), + collections: jest.fn(), + transaction: jest.fn(), + }, }), ) .post('/graphql') @@ -85,10 +90,17 @@ describe('parse server', () => { describe('query depth is too high', () => { it('returns an error message', async () => { const response = await request( - Server(PORT, 1, 1000, 1, 1, 1, { - query: jest.fn(), - collections: jest.fn(), - transaction: jest.fn(), + Server({ + maxDepth: 1, + complexityCost: 1000, + scalarCost: 1, + objectCost: 1, + listFactor: 1, + context: { + query: jest.fn(), + collections: jest.fn(), + transaction: jest.fn(), + }, }), ) .post('/graphql') diff --git a/api-js/src/server.js b/api-js/src/server.js index 663a849e0..6826b0f07 100644 --- a/api-js/src/server.js +++ b/api-js/src/server.js @@ -39,15 +39,14 @@ const createValidationRules = ( } export const Server = ( - // TODO refactor - // no longer used but preserved because of coupling to argument order - _PORT = '4000', - maxDepth, - complexityCost, - scalarCost, - objectCost, - listFactor, - context = {}, + { + maxDepth, + complexityCost, + scalarCost, + objectCost, + listFactor, + context = {}, + }, ) => { const app = express()