houdini
houdini copied to clipboard
Add pullHeaders to houdini.config.js
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.
Just a heads up, support for this will be added as part of the upcoming work to support the new KitQL api 👍
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",
},
}