Skip to content

Commit 273ae4b

Browse files
authored
chore: avoid pgDefaultRole/pgSettings clashes (#606)
1 parent c19626a commit 273ae4b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postgraphql",
3-
"version": "3.5.0",
3+
"version": "3.5.1",
44
"description": "A GraphQL schema created by reflection over a PostgreSQL schema 🐘",
55
"author": "Caleb Meredith <[email protected]>",
66
"license": "MIT",

src/postgraphql/http/createPostGraphQLHttpRequestHandler.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ const origGraphiqlHtml = new Promise((resolve, reject) => {
6666
* @param {GraphQLSchema} graphqlSchema
6767
*/
6868
export default function createPostGraphQLHttpRequestHandler (options) {
69-
const { getGqlSchema, pgPool, pgSettings } = options
69+
const { getGqlSchema, pgPool, pgSettings, pgDefaultRole } = options
70+
71+
if (pgDefaultRole && typeof pgSettings === 'function') {
72+
throw new Error('pgDefaultRole cannot be combined with pgSettings(req) - please remove pgDefaultRole and instead always return a `role` key from pgSettings(req).')
73+
}
74+
if (pgDefaultRole && pgSettings && typeof pgSettings === 'object' && Object.keys(pgSettings).map(s => s.toLowerCase()).indexOf('role') >= 0) {
75+
throw new Error('pgDefaultRole cannot be combined with pgSettings.role - please use one or the other.')
76+
}
7077

7178
// Gets the route names for our GraphQL endpoint, and our GraphiQL endpoint.
7279
const graphqlRoute = options.graphqlRoute || '/graphql'
@@ -399,7 +406,7 @@ export default function createPostGraphQLHttpRequestHandler (options) {
399406
jwtSecret: options.jwtSecret,
400407
jwtAudiences: options.jwtAudiences,
401408
jwtRole: options.jwtRole,
402-
pgDefaultRole: options.pgDefaultRole,
409+
pgDefaultRole,
403410
pgSettings:
404411
typeof pgSettings === 'function' ? await pgSettings(req) : pgSettings,
405412
}, context => {

0 commit comments

Comments
 (0)