Last active
November 8, 2024 11:22
-
-
Save benjie/78979963a26947672da77f331a37c6d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyPgContextPlugin: GraphileConfig.Plugin = { | |
name: "MyPgContextPlugin", | |
description: | |
"Extends the runtime GraphQL context with details needed to support your configured pgServices", | |
version: "0.0.0", | |
grafast: { | |
middleware: { | |
prepareArgs(next, { args }) { | |
if (!args.contextValue) args.contextValue = Object.create(null); | |
const { resolvedPreset: { pgServices: [pgService] }, requestContext: ctx } = args; | |
const contextValue = args.contextValue as Record<string, any>; | |
const { pgSettings } = pgService; | |
contextValue.pgSettings = pgSettings(ctx ?? EMPTY_OBJECT); | |
const { pgSubscriber, withPgClient } = getContextValuesForTenant(ctx.expressv4.req.tenant_id); | |
contextValue.pgSubscriber = pgSubscriber; | |
contextValue.withPgClient = withPgClient; | |
return next(); | |
}, | |
}, | |
}, | |
}; | |
// Replaces PgContextPlugin with MyPgContextPlugin | |
export const MultitenantPreset: GraphileConfig.Preset = { | |
disablePlugins: ['PgContextPlugin'], | |
plugins: [MyPgContextPlugin], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment