its different from rest api because it allows us to get specific data from the api
sample graphql user data query vs get all users
// graphql
query {
users {
id
username
email
}
} // get all users and returns only id, username and email// rest api
/users // get all users and returns all data
Installing graphql for strapi
on admin panel go to
marketplace -> graphql or npm i strapi-plugin-graphql
Setting up react to use graphql
npm i @apollo/client graphql appolo client will help us to use graphql in react
add appolo to app.js and create connection to graphql
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
ApploClient creates a new connection to graphql server
InMemoryCache is a cache that stores data from graphql server
ApolloProvider is a provider that allows us to use graphql in react