Strapi Crash Course (with React & GraphQL) #9 - Apollo Client Setup
Key Takeaways
This video demonstrates setting up Apollo Client in a React application to connect to a Strapi GraphQL server, including installing necessary packages, configuring the Apollo Client, and providing the client connection to the React application.
Full Transcript
all right gang so graphql is now set up on the strap here back end right and now we can handle incoming graphql queries but we also need to set up our react application to be able to make those queries and to do that we need to install two packages first of all the apollo client package which helps us to manage and make queries in our react components and also the graphql package itself which is needed to pass graphql queries so to do this open up a terminal and type the following npm install and then we want to grab at apollo forward slash clients so that's the first package then a space the second one is graphql so hit enter and then this is going to install those two packages for us okay then so now they're installed the first thing we need to do is configure the apollo client to connect to the strappy graphql server so at the top of the root app component right here import a couple of things from the apollo client library we need three things in total so first of all we have the apollo client which is used to create a new connection to the graphql server the in memory cache is used by the apollo client to cache responses from the server for us and the apollo provider is used to wrap our entire react application and it provides it with the ability to use the apollo client connection that we set up to make queries so let's use the apollo client first of all to make a new connection so we'll create a new constant and give this a name i'm going to call it clients and then we set it equal to new and then it's the apollo client which we import and we invoke it so this generates a new clients it makes a new instance of the apollo client and stores it in this constant now we also need to pass in some configuration into this so create an object as an argument inside the parentheses and the first property on this object is going to be a uri property now this is basically the entry point to the graphql server that strap it is using and that address is http call on forward slash forward slash local host and it's port one three three seven forward slash graphql okay so that's the uri property the next property is cache and this tells apollo what to use to cache our query responses in our case this will be the in memory cache which we already imported so let's grab that and paste it in cool so now we have this initial client connection to the graphql server next we need to provide this to our application now we do that by using the apollo provider component that we imported up here so this is going to go inside the router but it's going to surround everything else so it's going to surround the div with the class of app so let's just do that now in older versions placing the provider inside the router like this can cause problems but the more modern versions don't cause this issue if you do have problems you can try surrounding the router component with the provider instead anyway this now takes a prop called client and then this prop as a value takes in the client that we made so whatever you called your constant up here pass that into the apollo provider and now we're basically providing that client connection to the graphql server to our entire react application inside this component so now in the future we can make graphql queries to our strappy backend from any of these components inside the app and we'll see how to do that in the next lesson
Original Description
🐱💻 Access the course files on GitHub:
https://github.com/iamshaunjp/Strapi-Crash-Course
🐱👤 Get access to extra premium courses on Net Ninja Pro:
https://netninja.dev
🐱💻Starter Project CSS (lesson 5):
https://github.com/iamshaunjp/Strapi-Crash-Course/blob/lesson-5/frontend/src/index.css
🐱💻 Full React Course:
https://www.youtube.com/watch?v=j942wKiXFu8&list=PL4cUxeGkcC9gZD-Tvwfod2gaISzfRiP9d
🐱💻 Social Links:
Facebook - https://www.facebook.com/thenetninjauk
Twitter - https://twitter.com/thenetninjauk
Instagram - https://www.instagram.com/thenetninja/
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
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
28
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 Reads
🎓
Tutor Explanation
DeepCamp AI