leveluptuts / gQuery

Not like jQuery. A GraphQL Fetcher & Cache for Svelte Kit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IntrospectionQuery is failing

inta opened this issue · comments

I work on a prototype using Hasura as GraphQL backend and gQuery as client. The setup was running fine until I added authentication. Now "Load GraphQL schemas" is failing with "Could not obtain introspection result".
The introspection query is working though, if using something like Insomnia. I put a mitmproxy in between an discovered, that the request bodies differ. The request sent via Insomnia is wrapped by {"query":"...","operationName":"IntrospectionQuery"} and the one from gQuery by {"query":"..."}. The first one is working (without any credentials) and the latter is not.

I'm not sure whether this is a problem of gQuery or not.

Damn, maybe this is just a layer 8 problem an Insomnia is actually caching headers which were sent before.
By the way, how could I set headers for GFetch? Seems like they cannot be set via fetchOptions.

Ok, I was searching in the wrong place. Loading the schema has nothing to do with GFetch, but is done by the gQueryCodegen function inside the svelte.config.js. You can pass headers if you declare the schema as an object:

gQueryCodegen({
	schema: {[env.VITE_GRAPHQL_URL]: {headers: {'X-Hasura-Admin-Secret': env.VITE_AUTH_TOKEN}}},
	out: './src/lib/graphql',
	gPath: '$lib/config/g',
	debug: false,
})

@inta incredibly helpful ty ty ty