apollographql / apollo-client-nextjs

Apollo Client support for the Next.js App Router
https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support
MIT License
358 stars 25 forks source link

query returning 404 on valid endpoint #183

Closed c0rdeiro closed 2 months ago

c0rdeiro commented 3 months ago

@apollo/client: 3.8.10 @apollo/experimental-nextjs-app-support: 0.6.0

I have a simple query that has 1 string variable that is defined only when the component is mounted

My query looks something like

const GET_SENTIENCE5_HOLDER = gql`
  query sentience5($id: String!) {
     ...
    }
  }
`

and my hook looks like

const { data } = useSuspenseQuery(
    GET_SENTIENCE5_HOLDER,
    address
      ? {
          variables: {
            id: address,
          },
          queryKey: ['sentience5', address],
        }
      : skipToken
  )

I'm using skipToken to only run the query when the address is defined

I've confirmed that the problem is not the endpoint nor the query because if instead of the variable I pass a direct string it works perfectly.

If someone knows what might be the problem here I would love the help, thank you

phryneas commented 3 months ago

If there's a 404, that's coming from the server you are querying - we do not "interpret" data in any way. Are you sure the url you pass into your HttpLink is reachable both from your browser and server, and even if the Next.js server is not started (e.g. during build)?

c0rdeiro commented 3 months ago

@phryneas I think so because if I do something like

const { data } = useSuspenseQuery(
    GET_SENTIENCE5_HOLDER,
     {
          variables: {
            id: 'test',
          },
          queryKey: ['sentience5'],
        }
  )

it works, so I ruled out that the HttpLink was not the problem but something related to my variable and the way I was using skipToken (although I followed the documentation to this argument, and why I am confused with the error)

phryneas commented 3 months ago

Yeah, but again: a 404 is not caused by any code, neither in this package nor in @apollo/client.

I'm not exactly sure where you're seeing a 404, but that would either be sendtby Next.js (if your browser ends up on a 404 error page), or by your GraphQL server (if the request comes back with a 404 error).

c0rdeiro commented 3 months ago

@phryneas it is a 404 error from GraphQL, so can I assume the error is not in my skipToken logic?

phryneas commented 3 months ago

Definitely not - it's something in how your server reacts to this specific query, so I'd look into the server.

c0rdeiro commented 3 months ago

Thanks, I'll take a look

phryneas commented 2 months ago

I think this can be closed now - I hope you found the source of your problem!

github-actions[bot] commented 2 months ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.