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

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

Open
benjie opened this issue Nov 25, 2024 · 0 comments
Labels

Comments

@benjie
Copy link
Member

benjie commented Nov 25, 2024

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.

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.

@github-project-automation github-project-automation bot moved this to 🌳 Triage in V5.0.0 Nov 25, 2024
@benjie benjie moved this from 🌳 Triage to 🐭 Shrew in V5.0.0 Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🐭 Shrew
Development

No branches or pull requests

1 participant