I have this error when i use client side with this code it will get product details but some products get data and some can’t get data and receiver this [Unhandled Rejection (Error): Response not successful: Received status code 400 new ApolloError]. My code is down below
I’m missing a bit of context here - is this Next.js with the App directory?
A few thoughts here:
in Next.js, you generally should never have a global client as you seem here, since that would be shared between multiple users, potentially leaking private user data
in Next.js, “use client” component cannot use async..await
you seem to be await without async in ProductDetails, which is not valid JavaScript
Beyond that, I’d need a bit more description on when exactly you are getting those errors. Generally, a 400 error is an error from your server, so looking at your server logs might give you some information.
I see and I use 2 type of connect which is makeClient that you said and global client because I want to get MetaData to SEO of each product so do you have any suggest to me.
NEXT_PUBLIC_GRAPHQL_ENDPOINT is my config in file .env to my server using sandbox apollo studio and Graphql
On usage, but I think it fixed maybe that I install [@apollo/experimental-nextjs-app-support] lost some thing then I just install it when you said to me.
Even for generateMetadata, I would advise you to create a new unique Apollo Client instance in each invocation - const client = makeClien() as the first line of each generateMetadata call.
We’ll look into making this better in some way in the future, but we’re a bit bound by Next.js here.
One additional note: ssrMode is for legacy React "renderToString` SSR. You don’t need it with Next.js.
So your GraphQL server is a different server than the Next.js server?
Hmm. I’m sorry, but without a lot more context on when and how exactly this error occurs, I kinda fear I won’t be able to help.
But I still highly suggest that you look at your GraphQL server log. The 400 is returned from your GraphQL server, so if anything goes wrong, that’s the first place to look.