Skip to content

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

@david-plugge

Description

@david-plugge

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working like it should

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions