Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions api-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
38 changes: 25 additions & 13 deletions api-js/src/__tests__/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import request from 'supertest'
import { Server } from '../server'

const {
PORT = 4000,
DEPTH_LIMIT: maxDepth,
COST_LIMIT: complexityCost,
SCALAR_COST: scalarCost,
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down
17 changes: 8 additions & 9 deletions api-js/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down