GraphQL Tutorial #25 - Apollo Client Setup
Hey gang, in this GraphQL tutorial I'll show you how to set up React with GraphQL using Apollo. Apollo helps our front-end app to generate queries to our server, and receive the data back.
DONATE :) - https://www.paypal.me/thenetninja
----- COURSE LINKS:
+ Course files - https://github.com/iamshaunjp/graphql-playlist
+ Atom editor - https://atom.io/a
+ CMDER - http://cmder.net/
+ Node Download - https://nodejs.org/en/
======== Other Tutorials =========
----- NODE.JS TUTORIALS
https://www.youtube.com/playlist?list=PL4cUxeGkcC9gcy9lrvMJ75z9maRw4byYp
----- MONGODB TUTORIALS
https://www.youtube.com/playlist?list=PL4cUxeGkcC9jpvoYriLI0bY8DOgWZfi6u
----- REACT TUTORIALS
https://www.youtube.com/playlist?list=PL4cUxeGkcC9i0_2FF-WhtRIfIJ1lXlTZR
----- SUBSCRIBE TO CHANNEL - https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1
======== Social Links ==========
Twitter - @TheNetNinja - https://twitter.com/thenetninjauk
Patreon - https://www.patreon.com/thenetninja
What You'll Learn
Sets up Apollo Client in React to generate queries and receive data
Full Transcript
alright then gang so in order to work with graph QL on the front end and be able to make graph QL queries to our server we'll need to use what's known as a graph to our client so the graph QL client we'll be using is called Apollo so much like when we're making HTTP requests to restful api so we could use a front-end library like Axios or even jquery to help us make those requests when it comes to graph QL in order to make queries to the server we'll need to use a graph QL client Apollo and it doesn't matter that we're using react on the front end here it could be view GS or angular instead we'd still need a graph to our clients help us make those queries from the front end up to the graph to our server so in our react app here will be creating queries much like we did in graphical before and then feeding them through the graph QL client Apollo which will send the request to the server the service then going to respond feed the data back to our graph cue our client Apollo which will then pass it back into our react application so you can think of the graph QL client as the thing that's in charge with a passage of data between the front end and the server right like a data pack horse or something now there's a few different clients we can use like I said the one we're going to use is called Apollo client which is very widely used and quite well documented as well so then let's take a look at the Apollo website to see how we can set it up inside our react up alright then so I'm here on the Apollo graph QL website and this is kind of like a QuickStart installation guide so I'm gonna leave this link down below for you to check out but essentially this is how we get started with Apollo and react now we have to install a few different things here right and there's two different options we can either do NPM install Apollo clients plus all of this other different stuff as well and save those all we can do NPM install Apollo boost which includes several different packages we're going to need and bundles them together including the Apollo client we just talked about and it also wants us to install react Apollo which is kind of like a glue layer to bind Apollo react and also graph QL which is the JavaScript implementation of graph QL so those three things right there this is the option we're gonna do so I'm just going to copy that dude and open up my console and I'm gonna cancel out of this process for now pressing yep and I'll paste this in so I'm gonna install those three packages right here okay so now we have those installed we can go ahead and start setting up Apollo in our react application so let's head over now to the code and open up our routes component right here at Jas and the first thing we're going to do is up here import Apollo clients which we just installed from Apollo boost right remember Apollo boost was that package that bundles certain different things that we need together and one of those things is the Apollo client okay so we're importing that first of all and we need to now set up our Apollo client so if I will do that below components down here so a little comment and I'll say Apollo client setup all right so let's create a constant and call this client and set this equal to a new Apollo client like so and this Apollo client is going to take some options one of those is a URI so this is going to be the endpoint that we're making requests or queries to okay remember we set that up in the first half of this series and it was localhost 4000 forward slash graph QL that was the supercharged endpoint that handles all of our graph QL queries so let's pass that in here so HTTP double dot forward slash localhost and it was colon 4000 forward slash graph QL like so okay so now that's pretty much it we set up our Apollo client now Apollo knows that we're going to be making requests to this endpoint from our application all right but we also need to do one more thing inside this app JS file to set or Apolo and that thing is first of all to import the Apollo provider from oops react - Apollo alright so react Apollo is the thing that's kind of binding Apollo to react it helps react understand Apollo on what it's doing right and we need the Apollo not prove the Apollo provider to wrap our application and inject whatever data we receive from the server into our application right so the way we do this is by surrounding all of our template right here with a tag and this tag is going to be the Apollo provider type so Apollo like so provider and then if we need to say what client this is going to be using and it's gonna be this one right here that we just created so we can just copy and paste it up down here like so but we have to output it not in quotations but dynamically using these little curly braces this is how we dynamically output data in a react component right so let's place that in there and then close this off we need to also put a closing tag at the end so close that Apollo tagged Apollo provide attack if I can spell it all right Apollo provider like so we're just gonna scoot this up a little bit just to get the indentation roughly right now okay that'll do whatever so now we have our Apollo client created right we're registering that on the floor intent here to say we're making requests to this endpoint from this application then what we're doing is importing the Apollo provider from react Apollo which is surrounding our entire app here right and that is what enables us to get the data from this endpoint and inject it into whatever is inside the Apollo provider ok so it's taking the data from Apollo when it receives it from the server and injecting it into our application right so we can use it inside here so there we go now we have Apollo set up in our application on the front end and we in the next tutorial let's move on a start to actually create these queries from the front end
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 28 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
▶
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
Related AI Lessons
⚡
⚡
⚡
⚡
Connecting Frontend to Backend: A Backend Engineer’s Reality Check
Medium · Programming
Build Secure Authentication System Using Access and Refresh Tokens
Medium · Python
5 PHP Features You're Probably Not Using (But Should)
Dev.to · Mahdyar
How to Use the any Type and When to Avoid It
Dev.to · Krunal Kanojiya
🎓
Tutor Explanation
DeepCamp AI