12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
05 : 09 : 49 : 10
Become a member
to unlock all features

    Set up an Urql GraphQL Provider in React

    Ian JonesIan Jones

    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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    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.