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

No GraphQL network requests are made #1466

Closed
janosrusiczki opened this issue Mar 18, 2023 · 1 comment
Closed

No GraphQL network requests are made #1466

janosrusiczki opened this issue Mar 18, 2023 · 1 comment

Comments

@janosrusiczki
Copy link

janosrusiczki commented Mar 18, 2023

Describe the bug
No GraphQL related network requests are made.

To Reproduce
I'm trying to upgrade my backend from Rails 6.1.7 to Rails 7.0.4 but once I upgrade, no network requests for GraphQL are made. I'm using @vue/apollo-composable 's useQuery. I would like to mention that nothing is cached, I did full reloads, restarted browser, the same. No error, not on the backend, not on the frontend.

What makes apollo not do network requests?

Apollo DevTools display the same issue (they work with Rails 6.1.7 and don't once I upgrade).

Expected behavior
GraphQL requests are made, my app works as with Rails 6.1.7.

Versions
vue: ^3.2.47
@apollo/client: ^3.7.10
@vue/apollo-composable: ^4.0.0-beta.4


More debugging.

Installed Postman, I can make the requests without issues. I tried in Firefox, Chrome and now Edge, no requests happen in any of them. Maybe it's worth noting that I'm serving the JS modules via Vite (vite_rails). But I'm using the same in Rails 6.

I'm suspecting some CORS or XSS header change on the backend makes Apollo not even try to do the requests.

@janosrusiczki janosrusiczki changed the title After backend upgrade no GraphQL related network requests are made No GraphQL network requests are made Mar 19, 2023
@janosrusiczki
Copy link
Author

Found the issue:

Found the issue. For some reason in Rails 7:

<%= csrf_meta_tags %>
<%= csp_meta_tag %>

placed in application.html.erb is not outputting anything.

In my application.js where I was building authLink I had:

const authLink = setContext((_, { headers }) => {
  const csrfToken = document.
    querySelector('meta[name="csrf-token"]').
    attributes.content.value;

  return {
    headers: {
      ...headers,
      'X-CSRF-Token': csrfToken,
      authorization: tokenStore.authorization,
    },
  }
})

Obviously something around csrfToken was failing silently.

And below I was using authLink in ApolloClient:

const apolloClient = new ApolloClient({
  link: authLink.concat(afterwareLink.concat(httpLink)),
  cache: new InMemoryCache(),
  connectToDevTools: true,
})

So my whole apolloClient was broken this is why no requests would fire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant