[graphQL] Setup
GraphQL is a powerful query language. It allows for a more flexible and efficient approach than RESTful API.
REST API approach
You might have to send multiple http request for getting multiple data.
Endpoint for getting particular book
- title, genre, reviews, authorID
domain.com/books/:id
Endpoint for getting author info
- name, age, bookID
domain.com/authors/info
GraphQL approach
You only send a single http request for getting multiple data.
{
book(id: 123) {
title
genre
reviews
author {
name
age
books {
name
}
}
}
}
Setup Apollo
Installation
npm install @apollo/client graphql apollo-boost @apollo/react-hooks
apollo-boost
or@apollo/client
Create Client
apollo.js
import { ApolloClient, InMemoryCache } from '@apollo/client';
const client = new ApolloClient({
uri: 'https://movieql.now.sh/',
cache: new InMemoryCache(),
});
export default client;
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import { ApolloProvider } from '@apollo/client';
import client from './apollo';
ReactDOM.render(
<React.StrictMode>
<ApolloProvider client={client}>
<App />
</ApolloProvider>
</React.StrictMode>,
document.getElementById('root')
);
Author And Source
이 문제에 관하여([graphQL] Setup), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@suyeonme/graphQL-Setup저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)