1. 6
    Query Data with GraphQL in Next.js from a Fauna Database
    1m 14s

Query Data with GraphQL in Next.js from a Fauna Database

InstructorShadid Haque

Share this video with your friends

Send Tweet

Now that Apollo Client is set up and ready to be used, we can finally query data from Fauna to use in our application.

We'll go to the Fauna GraphiQL playground and copy the findShopById query that we ran previously. This query will be passed into Apollo's useQuery hook.

Chris Baucom
~ 2 years ago

Did I miss the step of wrapping the app in ApolloProvider?

Shadid Haqueinstructor
~ 2 years ago

Hey Chris, what's the error you are getting ? I can help 😃

Chris Baucom
~ 2 years ago

Maybe I missed it in the video but I was missing <ApolloProvider client={client}> in _app.tsx

Shadid Haqueinstructor
~ 2 years ago

Ahh glad it's working now. You can always refer to the code. Feel free to reach out if you have any questions

Bruno Ribeiro
~ 2 years ago

I had the same problem Chris had. Luckily I've worked with Apollo before. I think the video should show the ApolloProvider part too.

Shadid Haqueinstructor
~ 2 years ago

Good call Bruno. I'll update this video. Thanks for the feedback

rraghav123
~ 2 years ago

Do we need to configure something right now I am getting a CORS error

localhost/:1 Access to fetch at 'https://dashboard.fauna.com/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Eduardo Orozco
~ 2 years ago

Yeah, adding the apollo Provider step is something not included in the video

Shadid Haqueinstructor
~ 2 years ago

Hey Eduardo, what's the error message you are getting?

Eduardo Orozco
~ 2 years ago

You get Invariant Violation: Could not find "client" in the context or passed in as an option. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options.

The way to fix it is the way Chris says, adding <ApolloProvider client={client}> in _app.tsx

~ a year ago

I get 404 in console after running the app or refreshing the page. And data is undefined for me.

~ a year ago

Even after adding ApolloProvider to app.tsx file.

Shadid Haqueinstructor
~ a year ago

Can you please share the code? I can help