Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependencies security audit #650

Closed
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
23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
"version": "0.0.0-semantic-release",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": ["dist"],
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/prisma/graphql-yoga.git"
},
"keywords": ["graphql", "server", "api", "graphql-server", "apollo"],
"keywords": [
"graphql",
"server",
"api",
"graphql-server",
"apollo"
],
"author": "Johannes Schickling <[email protected]>",
"license": "MIT",
"bugs": {
Expand All @@ -19,8 +27,7 @@
"scripts": {
"prepublish": "yarn build",
"build": "rm -rf dist && tsc -d",
"lint":
"tslint --project tsconfig.json {src,test}/**/*.ts && prettier-check --ignore-path .gitignore {src,.}/{*.ts,*.js}",
"lint": "tslint --project tsconfig.json {src,test}/**/*.ts && prettier-check --ignore-path .gitignore {src,.}/{*.ts,*.js}",
"format": "prettier --write --ignore-path .gitignore {src,.}/{*.ts,*.js}",
"test": "yarn lint && yarn build && ava",
"watch:tsc": "tsc --watch",
Expand All @@ -31,7 +38,9 @@
"branch": "master"
},
"ava": {
"files": ["dist/**/*.test.js"]
"files": [
"dist/**/*.test.js"
]
},
"dependencies": {
"@types/aws-lambda": "8.10.13",
Expand Down Expand Up @@ -59,7 +68,7 @@
},
"devDependencies": {
"@types/request-promise-native": "1.0.15",
"ava": "0.25.0",
"ava": "^2.4.0",
"aws-lambda": "^0.1.2",
"npm-run-all": "4.1.3",
"prettier": "1.12.1",
Expand All @@ -69,7 +78,7 @@
"tslint": "5.11.0",
"tslint-config-prettier": "1.12.0",
"tslint-config-standard": "7.1.0",
"typescript": "3.1.3",
"typescript": "^3.9.7",
"yarn": "1.10.1"
}
}
42 changes: 20 additions & 22 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import test, { TestContext, Context } from 'ava'
import test from 'ava'
import { inflate } from 'graphql-deduplicator'
import { GraphQLServer, Options } from './index'
import { promisify } from 'util'
import { middleware } from 'graphql-middleware'
import { AddressInfo } from 'net'
import * as request from 'request-promise-native'

async function startServer(t: TestContext & Context<any>, options?: Options) {
const randomId = () =>
Math.random()
.toString(36)
.substr(2, 5)
async function startServer(t, options?: Options) {
const randomId = () => Math.random().toString(36).substr(2, 5)

const typeDefs = `
type Author {
Expand Down Expand Up @@ -51,7 +49,7 @@ async function startServer(t: TestContext & Context<any>, options?: Options) {

const server = new GraphQLServer({ typeDefs, resolvers })
const http = await server.start({ port: 0, ...options })
const { port } = http.address()
const { port } = http.address() as AddressInfo
const uri = `http://localhost:${port}/`

if (t.context.httpServers) {
Expand All @@ -66,17 +64,17 @@ async function startServer(t: TestContext & Context<any>, options?: Options) {
return t.context
}

test.afterEach.always('stop graphql servers', async t => {
const { httpServers } = t.context
test.afterEach.always('stop graphql servers', async (t) => {
const httpServers = (t.context as any).httpServers;

if (httpServers && httpServers.length) {
await Promise.all(
httpServers.map(server => promisify(server.close).call(server)),
httpServers.map((server) => promisify(server.close).call(server)),
)
}
})

test('works with simple hello world server', async t => {
test('works with simple hello world server', async (t) => {
const { uri } = await startServer(t)

const query = `
Expand All @@ -99,7 +97,7 @@ test('works with simple hello world server', async t => {
})
})

test('Response data can be deduplicated with graphql-deduplicator', async t => {
test('Response data can be deduplicated with graphql-deduplicator', async (t) => {
const {
uri,
data: { book },
Expand Down Expand Up @@ -159,7 +157,7 @@ test('Response data can be deduplicated with graphql-deduplicator', async t => {
t.deepEqual(body.data, inflate(deduplicated.data))
})

test('graphql-deduplicated can be completely disabled', async t => {
test('graphql-deduplicated can be completely disabled', async (t) => {
const {
uri,
data: { book },
Expand Down Expand Up @@ -200,7 +198,7 @@ test('graphql-deduplicated can be completely disabled', async t => {
})
})

test('Works with graphql-middleware', async t => {
test('Works with graphql-middleware', async (t) => {
const typeDefs = `
type Book {
id: ID!
Expand Down Expand Up @@ -233,7 +231,7 @@ test('Works with graphql-middleware', async t => {
middlewares: [middleware],
})
const http = await server.start({ port: 0 })
const { port } = http.address()
const { port } = http.address() as AddressInfo
const uri = `http://localhost:${port}/`

const query = `
Expand Down Expand Up @@ -264,7 +262,7 @@ test('Works with graphql-middleware', async t => {
})
})

test('Works with graphql-middleware generator.', async t => {
test('Works with graphql-middleware generator.', async (t) => {
const typeDefs = `
type Book {
id: ID!
Expand All @@ -287,7 +285,7 @@ test('Works with graphql-middleware generator.', async t => {
},
}

const middlewareGenerator = middleware(schema => {
const middlewareGenerator = middleware((schema) => {
return async (resolve, parent, args, ctx, info) => {
return 'pass'
}
Expand All @@ -299,7 +297,7 @@ test('Works with graphql-middleware generator.', async t => {
middlewares: [middlewareGenerator],
})
const http = await server.start({ port: 0 })
const { port } = http.address()
const { port } = http.address() as AddressInfo
const uri = `http://localhost:${port}/`

const query = `
Expand Down Expand Up @@ -330,7 +328,7 @@ test('Works with graphql-middleware generator.', async t => {
})
})

test('Works with array of resolvers', async t => {
test('Works with array of resolvers', async (t) => {
const typeDefs = `
type Book {
id: ID!
Expand All @@ -355,13 +353,13 @@ test('Works with array of resolvers', async t => {

const bookIdResolver = {
Book: {
id: root => `book-${root.id}`,
id: (root) => `book-${root.id}`,
},
}

const bookNameResolver = {
Book: {
name: root => `book-${root.name}`,
name: (root) => `book-${root.name}`,
},
}

Expand All @@ -371,7 +369,7 @@ test('Works with array of resolvers', async t => {
middlewares: [],
})
const http = await server.start({ port: 0 })
const { port } = http.address()
const { port } = http.address() as AddressInfo
const uri = `http://localhost:${port}/`

const query = `
Expand Down
22 changes: 12 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { createServer, Server as HttpServer } from 'http'
import { createServer as createHttpsServer, Server as HttpsServer } from 'https'
import * as path from 'path'
import { SubscriptionServer } from 'subscriptions-transport-ws'
import { AddressInfo } from 'net'

import {
SubscriptionServerOptions,
Expand Down Expand Up @@ -365,14 +366,14 @@ export class GraphQLServer {

start(
options: Options,
callback?: ((options: Options) => void),
callback?: (options: Options) => void,
): Promise<HttpServer | HttpsServer>
start(
callback?: ((options: Options) => void),
callback?: (options: Options) => void,
): Promise<HttpServer | HttpsServer>
start(
optionsOrCallback?: Options | ((options: Options) => void),
callback?: ((options: Options) => void),
callback?: (options: Options) => void,
): Promise<HttpServer | HttpsServer> {
const options =
optionsOrCallback && typeof optionsOrCallback === 'function'
Expand All @@ -381,20 +382,21 @@ export class GraphQLServer {
const callbackFunc = callback
? callback
: optionsOrCallback && typeof optionsOrCallback === 'function'
? optionsOrCallback
: () => null
? optionsOrCallback
: () => null

const server = this.createHttpServer(options as Options)

return new Promise((resolve, reject) => {
const combinedServer = server
const port = typeof this.options.port !== "number"
? parseInt(this.options.port)
: this.options.port
const port =
typeof this.options.port !== 'number'
? parseInt(this.options.port, 10)
: this.options.port
combinedServer.listen(port, this.options.host, () => {
callbackFunc({
...this.options,
port: combinedServer.address().port,
port: (combinedServer.address() as AddressInfo).port,
})
resolve(combinedServer)
})
Expand All @@ -416,7 +418,7 @@ export class GraphQLServer {
// The following should be replaced when SubscriptionServer accepts a formatError
// parameter for custom error formatting.
// See https://github.com/apollographql/subscriptions-transport-ws/issues/182
connection.formatResponse = value => ({
connection.formatResponse = (value) => ({
...value,
errors:
value.errors &&
Expand Down
Loading