GraphQL requests don't work on localhost
kwiat1990 opened this issue · 3 comments
Hi, I was following this tutorial https://hasura.io/learn/graphql/svelte-apollo/introduction/ but although I have done everything in the same way as described I cannot get the queries to work. Running and executing queries on Graphiql works just fine but on localhost all requests are blocked due to cross site cookies.
On Network Tab in Chrome I can see: Because a cookie’s SameSite attribute was not set or is invalid, it defaults to SameSite=Lax, which prevents the cookie from being set in a cross-site context. This behavior protects user data from accidentally leaking to third parties and cross-site request forgery.
Hi @kwiat1990 - The error you mentioned ideally shouldn't be the reason for why GraphQL queries are failing on localhost. Can you confirm in the Network tab the response you see for the HTTP request made?
The message you see on Chrome is probably just a warning on the console.
For instance, if a make a request to fetch all private todos in Hoppscotch, then everything works fine. Just the same as in GraphiQL. In the frontend the let todos = query(GET_MY_TODOS) stucks at loading and this request doesn't get listed under network tab.
I have the very same setup for Apollo Client as in the final app and the code in TodoPrivateList.svelte looks also the same.
It turned out that the problem was inside the Apollo constructor, where a link option got specified. In the tutorial it looks following:
const client = new ApolloClient({
httpLink,
cache,
});
However, httpLink is not a correct key and it needs to be replaced with link. After changing this line to link: httpLink it does work.