graphile / graphile/crystal

Ensure that the `preset.grafast.context.pgSettings` example in the docs actually works

Open
#2,247 0 comments 0 reactions 0 assignees View on GitHub
📄 add-to-docs
Dominant language
TypeScript
Stars
12.9k
Forks
625
Avg merge
5h 23m
Merged PRs (30d)
24

Description

Have a vague feeling you need to define it via the `pgServices` section instead due to an assertion that prevents overwriting. We should check and either remove the assertion or fix the docs.

```ts
declare global {
namespace Grafast {
interface Context {
user?: unknown
snowflakeConnection?: unknown
}
}
}
const preset: GraphileConfig.Preset = {
grafast: {
explain: true,
context(ctx) {
const user = ctx.node?.req.user;
return {
user,
snowflakeConnection: ctx.node?.req.snowflakeConnection
pgSettings: {
...args.contextValue?.pgSettings,
"jwt.claims.user_id": user?.id,
}
}
},
},
```

> ^ Note this is probably invalid currently - I think you actually have to configure the pgSettings via `pgServices: [makePgService({pgSettings(ctx){return {'jwt.claims.user_id': ctx.node?.req.user?.id}}})` call due to an over-cautious protection to prevent you accidentally overwriting pgSettings.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.