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

Request with GET/HEAD method cannot have body. #374

Closed
david-plugge opened this issue Jul 6, 2022 · 5 comments
Closed

Request with GET/HEAD method cannot have body. #374

david-plugge opened this issue Jul 6, 2022 · 5 comments
Labels
Bug Something isn't working like it should

Comments

@david-plugge
Copy link
Contributor

david-plugge commented Jul 6, 2022

When using the new .fetch i get the error Request with GET/HEAD method cannot have body.

(sveltekit version 1.0.0-next.359)

src/routes/index.svelte

export const load: Load = async function (event) {
    // works
	await event.fetch('/test', {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify({
			hello: 'World'
		})
	});

    // breaks
	await GQL_Artworks.fetch({ event });

    return {};
};

My houdini client looks like this

async function fetchQuery({ fetch, text = '', variables = {}, session }: RequestHandlerArgs) {
	const headers: HeadersInit = {
		'Content-Type': 'application/json',
		apikey: import.meta.env.VITE_PUBLIC_KEY
	};
	if (session?.accessToken) {
		headers['Authorization'] = `Bearer ${session.accessToken}`;
	}

	const result = await fetch(url, {
		method: 'POST',
		headers,
		body: JSON.stringify({
			query: text,
			variables
		})
	});

	return await result.json();
}
@jycouet
Copy link
Contributor

jycouet commented Jul 6, 2022

Strange, it looks like you are doing a 'GET' somewhere? 🤔

In your first part, you query this URL: /test. Your graphql endpoint is on '/test'?
In your second part, where did you set url? Can you try with exact same headers?

Might be also the sveltekit version 1.0.0-next.359 that has some breaking changes.

@jycouet
Copy link
Contributor

jycouet commented Jul 6, 2022

Ok, it's a sveltekit version 1.0.0-next.359 issue.

Even your first part is not working, check logs, you will have the same message: Request with GET/HEAD method cannot have body.

I'm looking at what it could be. Thx for reporting 👍

@david-plugge
Copy link
Contributor Author

david-plugge commented Jul 6, 2022

Even your first part is not working

Somehow it was working, thats strange

@AlecAivazis AlecAivazis added the Bug Something isn't working like it should label Jul 6, 2022
@AlecAivazis
Copy link
Collaborator

I believe this is now fixed - will try to confirm this weekend

@AlecAivazis
Copy link
Collaborator

AlecAivazis commented Jul 9, 2022

Just confirmed this is working on sveltejs/[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working like it should
Projects
None yet
Development

No branches or pull requests

3 participants