GraphQL Tutorial #25 - Apollo Client Setup

Net Ninja · Beginner ·🔧 Backend Engineering ·8y ago
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 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

Related AI Lessons

Up next
This Cop Was Held Accountable For His Brutality! #police #lawyer
Hampton Law
Watch →