how to change kitQLClient URL during runtime with process.env? #155
Answered
by
jycouet
N3rdArtiste
asked this question in
Q&A
-
Session store is not accessible in non .svelte files. so I am unable to access it in kitQLClient.ts file. |
Beta Was this translation helpful? Give feedback.
Answered by
jycouet
Jul 4, 2022
Replies: 2 comments 2 replies
-
Hello, You want to change url via env file? You have multiple graphql endpoint? Or you want to set it once via env? |
Beta Was this translation helpful? Give feedback.
2 replies
-
Check out the Announcement here Now you can hook up before or after the fetch, Here is an example 👇 import type { RequestHandlerArgs } from '$houdini';
import { HoudiniClient } from '$houdini';
import { stry } from '@kitql/helper';
// For Query & Mutation
async function fetchQuery({
fetch,
text = '',
variables = {},
session,
metadata
}: RequestHandlerArgs) {
// Prepare the request
const url = import.meta.env.VITE_GRAPHQL_ENDPOINT || 'http://localhost:4000/graphql';
// regular fetch (Server & Client)
const result = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${session?.token}` // session usage example
},
body: JSON.stringify({
query: text,
variables
})
});
// return the result as a JSON object to Houdini
const json = await result.json();
// metadata usage example
if (metadata?.logResult === true) {
console.info(stry(json, 0));
}
return json;
}
// Export the Houdini client
export const houdiniClient = new HoudiniClient(fetchQuery); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jycouet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out the Announcement here
Now you can hook up before or after the fetch,
Here is an example 👇