Private
headersPrivate
hookPrivate
pluginPrivate
transformersAdds multiple graphile engine plugins to appendPlugins
array of postgraphile options object.
setAdditionalGraphQLContextFromRequest
and addGraphileBuildOptions
methods can be used to pass parameters to said plugins.
Explicit condition parameter is used to make a decision if plugins should be used or not (use if true, omit if false).
Example:
new PostgraphileOptionsBuilder()
.addConditionalPlugins(config.isDev || config.enablePopulatePlugins, PopulateMoviesPlugin, PopulateTvshowsPlugin)
Rest
...plugins: Plugin[]Comma-separated list of Graphile Engine schema plugins to load after the default plugins.
Adds properties to resulting graphileBuildOptions
property of postgraphile options object. Useful for modifying default postgraphile plugin settings.
Example:
new PostgraphileOptionsBuilder()
.addGraphileBuildOptions({ pgSkipInstallingWatchFixtures: true })
Additional Options to pass through into the graphile schema building system (received via the second argument of a plugin).
This function takes a PostGraphilePlugin object and attaches it as a Postgraphile Hook when build() is called.
This is a PostGraphilePlugin object.
new PostgraphileOptionsBuilder()
.addHookPluginFunction(subscriptionAuthorizationHook)
This builder option must be used if the Hook Plugin requires PostGraphileOptions in the logic. A function which returns a PostGraphilePlugin should be passed into this method. That function will use PostGraphileOptions created in the build() method and attach the plugin returned from the function as a Postgraphile Hook.
This is a function which takes an argument of type PostGraphileOptions<Request, Response> and returns a PostGraphilePlugin object.
new PostgraphileOptionsBuilder()
.addHookPluginFactory(customHookFactory)
Adds multiple graphile engine plugins to appendPlugins
array of postgraphile options object. setAdditionalGraphQLContextFromRequest
and addGraphileBuildOptions
methods can be used to pass parameters to said plugins.
Example:
new PostgraphileOptionsBuilder()
.addPlugins(
PgSimplifyInflectorPlugin,
ScalarTypesPlugin,
SmartTagsPlugin,
ValidationDirectivesPlugin,
)
Rest
...plugins: Plugin[]Comma-separated list of Graphile Engine schema plugins to load after the default plugins.
Builds a postgraphile options object with previously used extension methods.
Private
buildSets all necessary postgraphile properties to enable subscriptions. Example:
new PostgraphileOptionsBuilder()
.enableSubscriptions({
plugin: SubscriptionsPlugin,
websocketMiddlewares: middlewares,
hookFactory: subscriptionAuthorizationHookFactory
})
Results in something like this:
import PgPubsub from '@graphile/pg-pubsub';
import { makePluginHook } from 'postgraphile';
//.........
{
appendPlugins: [SubscriptionsPlugin], // Other plugins will be included if they were added using other methods
pluginHook: makePluginHook([PgPubsub, subscriptionAuthorizationHook]),
subscriptions: true,
websocketMiddlewares, // Empty array if websocketMiddlewares are not specified
subscriptionEventEmitterMaxListeners: 0, // unlimited
}
To make sure that Postgraphile is able to correctly establish WebSockets
connection, additional changes should be done by using
enhanceHttpServerWithSubscriptions
.
See more here: https://www.graphile.org/postgraphile/subscriptions/#advanced-setup
To customize the maximum number of listeners use:
import PgPubsub from '@graphile/pg-pubsub'; // must be imported to extend the PostGraphileOptions type with the pg-pubsub options.
...
new PostgraphileOptionsBuilder()
.setProperties({
subscriptionEventEmitterMaxListeners: 42,
})
Optional
hookOptional
websocketAdds additionalGraphQLContextFromRequest
property to postgraphile options object. Define only once. Multiple calls will not expand previous calls, but will override them.
Example:
new PostgraphileOptionsBuilder()
.setAdditionalGraphQLContextFromRequest(async req => {
const { subject } = await getManagementAuthenticationContext(req);
return { subject, serviceId: config.serviceId };
})
Some Graphile Engine schema plugins may need additional information available on the context argument to the resolver - you can use this function to provide such information based on the incoming request - you can even use this to change the response , e.g. setting cookies.
Sets properties of postgraphile options object to be used based on some condition (use if true, omit if false). Additional calls will override and add properties. Example:
new PostgraphileOptionsBuilder()
.setConditionalProperties(config.isDev, {
exportGqlSchemaPath: './src/generated/schema.graphql',
watchPg: true,
graphiql: true,
enhanceGraphiql: true,
allowExplain: true,
})
An object containing postgraphile options.
Sets default values for properties that we see as best practices which most services should start from. This includes the default GraphQL errors handler, suggested default properties, development properties in dev-environments, and excludes the 'NodePlugin'.
Sets handleErrors
property of postgraphile options object.
Example:
new PostgraphileOptionsBuilder()
.setErrorsHandler((errors, req) => {
return enhanceGraphqlErrors(
result.errors,
req.body?.operationName,
customizeGraphQlErrorFields(defaultPgErrorMapper),
logGraphQlError(defaultWriteLogMapper, req.authContext?.subject, this.logger),
);
}
})
Enables ability to modify errors before sending them down to the client. Optionally can send down custom responses. If you use this then showErrorStack and extendedError may have no effect.
Enables or disables graphiql GUI depending on a passed condition parameter. Enable if true, disable if false.
Sets 3 postgraphile properties: graphiql
, enhanceGraphiql
and allowExplain
.
Example:
new PostgraphileOptionsBuilder()
.setGraphiql(config.graphqlGuiEnabled)
Sets a response header for each GraphQL request.
header name
header value
Sets pgSettings
property of postgraphile options object.
Example:
new PostgraphileOptionsBuilder()
.setPgSettings(async req => {
const { subject } = await getManagementAuthenticationContext(req, idServiceParams);
return buildPgSettings(subject, config.dbGqlRole, config.serviceId);
})
A plain object specifying custom config values to set in the PostgreSQL transaction (accessed via current_setting('my.custom.setting')) or an (optionally asynchronous) function which will return the same (or a Promise to the same) based on the incoming web request (e.g. to extract session data).
Sets properties of postgraphile options object to be used in without any conditions. Additional calls will override and add properties. Example:
new PostgraphileOptionsBuilder()
.setProperties({
enableCors: true,
dynamicJson: true,
ignoreRBAC: false,
legacyRelations: 'omit',
setofFunctionsContainNulls: false,
})
An object containing postgraphile options.
Skips multiple default postgraphile plugins by adding them to skipPlugins
array of postgraphile options object .
Example:
new PostgraphileOptionsBuilder()
.skipPlugins(NodePlugin, MutationPayloadQueryPlugin)
Rest
...plugins: Plugin[]Comma-separated list of Graphile Engine schema plugins to skip.
Generated using TypeDoc
A builder class that allows construction of postgraphile options using multiple dedicated extension methods.