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

feat(additionalGraphQLContextFromRequest): add res to callback #652

Merged
merged 1 commit into from
Dec 19, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ for (const [name, createServerFromHandler] of Array.from(serverCreators)) {
)
expect(additionalGraphQLContextFromRequest).toHaveBeenCalledTimes(1)
expect(additionalGraphQLContextFromRequest.mock.calls[0][0]).toBeInstanceOf(http.IncomingMessage)
expect(additionalGraphQLContextFromRequest.mock.calls[0][1]).toBeInstanceOf(http.ServerResponse)
})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ export default function createPostGraphQLHttpRequestHandler (config: {

// Provide an async function to this to add custom properties to the context
// object being provided to each graphQL resolver.
additionalGraphQLContextFromRequest?: (req: IncomingMessage) => Promise<{}>,
additionalGraphQLContextFromRequest?: (req: IncomingMessage, res: ServerResponse) => Promise<{}>,
}): HttpRequestHandler
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export default function createPostGraphQLHttpRequestHandler (options) {
const jwtToken = options.jwtSecret ? getJwtToken(req) : null

const additionalContext = typeof additionalGraphQLContextFromRequest === 'function'
? await additionalGraphQLContextFromRequest(req)
? await additionalGraphQLContextFromRequest(req, res)
: {}
result = await withPostGraphQLContext({
pgPool,
Expand Down
4 changes: 2 additions & 2 deletions src/postgraphql/postgraphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EventEmitter } from 'events'
import { createPostGraphQLSchema, watchPostGraphQLSchema } from 'postgraphile-core'
import createPostGraphQLHttpRequestHandler, { HttpRequestHandler } from './http/createPostGraphQLHttpRequestHandler'
import exportPostGraphQLSchema from './schema/exportPostGraphQLSchema'
import { IncomingMessage } from 'http'
import { IncomingMessage, ServerResponse } from 'http'

type PostGraphQLOptions = {
classicIds?: boolean,
Expand All @@ -31,7 +31,7 @@ type PostGraphQLOptions = {
appendPlugins?: Array<(builder: mixed) => {}>,
prependPlugins?: Array<(builder: mixed) => {}>,
replaceAllPlugins?: Array<(builder: mixed) => {}>,
additionalGraphQLContextFromRequest?: (req: IncomingMessage) => Promise<{}>,
additionalGraphQLContextFromRequest?: (req: IncomingMessage, res: ServerResponse) => Promise<{}>,
}

/**
Expand Down