houdini icon indicating copy to clipboard operation
houdini copied to clipboard

Add pullHeaders to houdini.config.js

Open david-plugge opened this issue 3 years ago • 1 comments

I´m using supabase graphql as my backend and every request needs an apikey header, even for pulling the schema. In my case the apikey is set in an .env file and this is my current solution:

{
  "pull-and-gen": "houdini generate --pull-schema -ph apikey=$(grep \"^VITE_SUPABASE_ANON_KEY=\" .env | cut -d \"=\" -f2)",
}

It would be nice to have access to the environment variables in the houdini config while houdini is pulling the schema. Since the config is also send to the browser where process.env is undefined a function can be used:

/** @type {import('houdini').ConfigFile} */
const config = {
  ...

  pullHeaders() {
    return {
      apikey: process.env.VITE_SUPABASE_ANON_KEY
      // or maybe use 'import.meta.env' instead
    }
  }
};

Edit:

Same with the apiUrl, that is also defined as an env variable.

david-plugge avatar Jul 19 '22 19:07 david-plugge

Just a heads up, support for this will be added as part of the upcoming work to support the new KitQL api 👍

AlecAivazis avatar Aug 01 '22 21:08 AlecAivazis

For anybody stumbling upon this (like I did): This is supported as the schemaPollHeaders key in houdini.config.js, like so:

const config = {
    ...
    apiUrl: "https://your.supabase.co/graphql/v1",
    schemaPollHeaders: {
        apiKey: "you-key",
    },
}

hgiesel avatar Dec 26 '22 19:12 hgiesel