-
Notifications
You must be signed in to change notification settings - Fork 48
Best approach to set headers through helix resolver in SvelteKit #45
Comments
I'm not sure if that's the best approach, but it's what works for me atm - so here is my current solution... I first had a look at the So my (simplified) code looks something like the following: const respond = async (request: Request): Promise<Response> => {
// ...
// Extract the GraphQL parameters from the request
const parameters = getGraphQLParameters(request);
const result = await processRequest({
...parameters,
request,
schema,
contextFactory: () => {
return {
request,
response: {
headers: {},
},
// ...
};
},
});
if (result.type === "RESPONSE") {
const headers: Headers = result.context?.response.headers || {};
for (const { name, value } of result.headers) {
headers[name] = value;
}
return {
headers,
body: result.payload,
status: result.status,
};
}
// ...
}; |
Thank you @benbender , I have been thinking about doing this. I just needed another opinion on doing this. |
@ibilux do you have graphql-helix working with svelte-kit? I can get it working in [email protected] but the latest 1.8 throws an error when starting svelte-kit |
@AndreasHald Simply use https://github.com/PabloSzx/graphql-ez/tree/main/examples/sveltekit - which integrates SvelteKit, Graphql-Helix & Envelop. |
@benbender seems interesting, but for now I'd like to try and get something working without a framework and build it from scratch. Do you happen to know the issue I'm having? |
@AndreasHald yes and no. The bundling process in sveltekit and vite is somewhat brittle atm. They are still figuring out how to handle all edge- and legacy-cases in their esm-packages-only-strategy. This leads to all sorts of problems with various packages in between and is changing between versions. So yes, I've encountered this (broad) class of problems, but not exactly your specific case (as I'm using graphql-ez, as said). |
@AndreasHald Yes, graphql-helix is working with svelte-kit for me. |
@benbender |
@ibilux Ah I see, that reference is using 1.2.3 however, do you have it working using the latest version of graphql-helix? |
Check sveltejs/kit#1563 and sveltejs/kit#2212, those are the reason PUSH and MULTIPART_RESPONSE are not supported |
@PabloSzx Yes, |
@AndreasHald I'm using version |
Hello,
I want to know what is the best approach to set (or return) headers (cookies to be exact) through helix resolver in SvelteKit?
After use login I need to set the
jwt
and session information in cookies. You can see the Mutation code in here:https://github.com/MirrorBytes/phorm-kit-vercel/blob/283b0c4036db13b799f22cd2b85a3f89ffab6e1b/src/resolvers/user.ts#L53
And the jwt is generated here:
https://github.com/MirrorBytes/phorm-kit-vercel/blob/283b0c4036db13b799f22cd2b85a3f89ffab6e1b/src/entities/user.ts#L98
I have noticed that
processRequest()
function return aresult
withheaders
in here:https://github.com/MirrorBytes/phorm-kit-vercel/blob/283b0c4036db13b799f22cd2b85a3f89ffab6e1b/src/routes/graphql.ts#L37
Is there is a way to access the header when processing a request (or resolving a schema) ?
Or can you suggest me a good a approach to do this ?
Thank you.
The text was updated successfully, but these errors were encountered: