⚠️ This lesson is retired and might contain outdated information.

Set up an Urql GraphQL Provider in React

Ian Jones
InstructorIan Jones
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 2 years 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.

egghead
egghead

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today