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(options) postgraphile: add contextOptions to allow custom jwt claims #3915

Merged
merged 7 commits into from
Apr 3, 2023
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
6 changes: 6 additions & 0 deletions .changeset/afraid-boats-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-mesh/postgraphile': patch
'@graphql-mesh/types': patch
---

add contextOptions to allow customization of jwt claims
8 changes: 8 additions & 0 deletions packages/handlers/postgraphile/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ export default class PostGraphileHandler implements MeshHandler {
await this.pgCache.set(cachedIntrospection);
}

let contextOptions = await loadFromModuleExportExpression<any>(this.config.contextOptions, {
cwd: this.baseDir,
importFn: this.importFn,
defaultExportName: 'default',
});
if (typeof contextOptions !== 'function') contextOptions = () => ({});

return {
schema,
executor({
Expand All @@ -145,6 +152,7 @@ export default class PostGraphileHandler implements MeshHandler {
queryDocumentAst: document,
operationName,
variables,
...contextOptions(meshContext),
},
function withPgContextCallback(pgContext) {
return defaultExecutor({
Expand Down
4 changes: 4 additions & 0 deletions packages/handlers/postgraphile/yaml-config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type PostGraphileHandler @md {
Enables live-query support via GraphQL subscriptions (sends updated payload any time nested collections/records change) (default: true)
"""
live: Boolean
"""
A file that exports a function which takes context as a paramter and returns postgraphile context options (e.g. "./my-function#pgSettings"). See the [postgraphile docs](https://www.graphile.org/postgraphile/usage-schema/) for more information.
"""
contextOptions: Any
}

union PostgraphileExternalOptions = JSON | String
16 changes: 16 additions & 0 deletions packages/types/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2881,6 +2881,22 @@
"live": {
"type": "boolean",
"description": "Enables live-query support via GraphQL subscriptions (sends updated payload any time nested collections/records change) (default: true)"
},
"contextOptions": {
"anyOf": [
{
"type": "object",
"additionalProperties": true
},
{
"type": "string"
},
{
"type": "array",
"additionalItems": true
}
],
"description": "A file that exports a function which takes context as a paramter and returns postgraphile context options (e.g. \"./my-function#pgSettings\"). See the [postgraphile docs](https://www.graphile.org/postgraphile/usage-schema/) for more information."
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,10 @@ export interface PostGraphileHandler {
* Enables live-query support via GraphQL subscriptions (sends updated payload any time nested collections/records change) (default: true)
*/
live?: boolean;
/**
* A file that exports a function which takes context as a paramter and returns postgraphile context options (e.g. "./my-function#pgSettings"). See the [postgraphile docs](https://www.graphile.org/postgraphile/usage-schema/) for more information.
*/
contextOptions?: any;
}
export interface RAMLHandler {
source: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
* `JSON`
* `String`
* `subscriptions` (type: `Boolean`) - Enable GraphQL websocket transport support for subscriptions (default: true)
* `live` (type: `Boolean`) - Enables live-query support via GraphQL subscriptions (sends updated payload any time nested collections/records change) (default: true)
* `live` (type: `Boolean`) - Enables live-query support via GraphQL subscriptions (sends updated payload any time nested collections/records change) (default: true)
* `contextOptions` (type: `Any`) - A file that exports a function which takes context as a paramter and returns postgraphile context options (e.g. "./my-function#pgSettings"). See the [postgraphile docs](https://www.graphile.org/postgraphile/usage-schema/) for more information.