ApolloClient gets HTML when querying graphql-yoga endpoint in NextJS 13 RCS/app dir

I’m trying to setup ApolloClient with NextJS 13 following the tutorial here.

I’m using graphql-yoga with Next13 and it works fine, I can access the graphiql site at the endpoint correctly, the sample query works, etc.

However when I try the app with Apollo setup, it throws the error ApolloError: Unexpected token < in JSON at position 0 - I assume it’s getting HTML when it shouldn’t be.

Everything works when I switch the page to a client-component using use client. Everything works when I query the server using fetch manually using the same url: http://localhost:3000/api/graphql

It only breaks when Apollo tries as a server component. I don’t know how to see the raw response so I don’t know which HTML is being shown but I suspect something in Apollo is somehow triggering the graphiql app to show rather than actual JSON responses?

Turns out NextJS had somehow cached an auth0 error page. Nothing would work until I blew away the .next cache dir.

1 Like