Set up an Urql GraphQL Provider in React

Ian Jones
InstructorIan Jones

Share this video with your friends

Send Tweet
Published 3 years ago
Updated a year ago

In this lesson, we create an urql client with the createClient method. Once we provide the createClient our GraphQL endpoint, we pass the client to urql's Provider component so that the urql can be used in our application.

Instructor: [0:00] Here, we have a React app that has a sad error. We're getting this error because in our app component we are firing a courseQuery to fetch courses from egghead.

[0:11] To fix this, we need to import {createClient} from 'urql'. To create an urql client, we go const client = createClient. CreateClient takes an object with a property of url. Our URL will be egghead's GraphQL API endpoint. Next, we will import Provider from urql. We will wrap our app in the Provider. We save it. Now we'll pass value={client}.

[1:20] Now, when we opened our developer tools, you'll see that data is loading. When we load it again, here's our GraphQL request. You can see that the query is being sent.