Strapi Crash Course (with React & GraphQL) #8 - GraphQL Plugin & Overview
Key Takeaways
Sets up GraphQL with Strapi using the GraphQL plugin and provides a GraphQL refresh
Full Transcript
all right then gang so far we've been using strappy's rest api and endpoints to fetch data using the use fetch hook and that's completely fine if you want to work that way but now i want to take a side step and i want to show you how to use graphql with strappy instead to query and fetch our data and how that works inside our react application so to begin with we need to install the graphql plugin for strappy so head to the admin area and then into the marketplace over here then click on the download button next to graphql this should download and install the graphql plugin for this instance of strappy now sometimes this takes a little while to install and you might get a message saying something like the server is taking a long time to restart or something like that if that happens don't worry just sit it out and it will finish after about a minute at most if it doesn't install after about three minutes just try refreshing the page and installing it again to see if it works so then now that's installed for us strap it is set up and ready to work with graphql now behind the scenes it's generated all the graphql scheme as it needs to run on the server for our content types and you can see them in the export folder inside graphql right here so this contains schemas for our content types the user content type and other things that strappy uses and this is what strappy will use to handle our queries when we use graphql to fetch data now before we start making queries using graphql in our application i just want to cover the basics of graphql for those that need a refresh or an introduction and to do that we can use a graphql playground tool that strappy gives to us to test out graphql queries it's a tiny bit like postman but for graphql instead now to see that tool open up a browser tab and go to localhost port 1337 then forward slash graphql and hit enter so then over here on the left is where we write our queries then we press the play button to run them and the response is going to appear on the right over here now if you don't feel like you need a refresh on graphql then by all means feel free to skip to the next lesson but for the rest of us let's try out a few simple queries so my friends graphql is a query language it gives us a different way to query data from a server than a rest api in a rest api we would use something like fetch or axios to make requests to a specific endpoint that sends back a bunch of data right instead in graphql we construct what's known as queries to be very specific about the data that we want to get back from the server and it's much more flexible than using a rest api and it's really helpful when you start to work with relational data as we'll see later on in the course so what does a query look like well typically we start it with the query keyword and then we give our query a name which i'm going to call get reviews and then after that we need to open up some curly braces and the actual query what we want to get goes inside these curly braces so all we need to do is say what data we want what types of data now i want to get all of the reviews so i just say reviews and this name right here must match the content type that we have now that on its own is not enough we also have to specify what fields from the reviews that we want to get so we open our curly braces again and specify those inside for example if i just want the title field of each review i just say title and now this is a completely valid query so i could press play now and we'll see the response from strappy on the right and we can see that it's a json object with a data property now inside that is a reviews property which is an array of reviews each review is an object and the only property inside is the title which we specified we wanted so now we have a list of reviews with just their titles if we want more fields we have to specify them in the query so after title i might want also the id so i comma separate these i could do the id and also after that the rating as well so now i'm saying get me all the reviews of each one get me the title the id and the rating and now if we press play strappy sends us back the list of reviews with the title id and rating of each review included so this is really cool graphql allows us to ask for only the data fields that we want i can also add the body field into this if i wanted to so let's do that at the end and then once we've done that we can hit play and this time the body field is added to the response that we get back so this is the kind of query we'll be making soon from our react application to get the data we need now just quickly if you want you can take away the query keyword and the name that we give to this query and we just leave the curly braces to surround the rest and this will still work we don't technically need the query keyword and the name of the query but i will be using them because they're going to allow us to later on use query variables which is a way to pass dynamic values into a query and we'll see how they work later on anyway that's a quick overview of the basics and how to make queries we will be diving deeper into these queries over the coming videos and some of them will become a little bit more complex especially when we start to work with relational data the next step though is to set up our react application to be able to make these types of graphql queries and we're going to do that in the next lesson
Original Description
In this tutorial we'll see how to set up GraphQL with Strapi using the GraphQL plugin & also have a little GraphQL refresh.
🐱💻 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/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
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
More on: React
View skill →
🎓
Tutor Explanation
DeepCamp AI