GraphQL 3

GraphQL API

GraphQL의 사전적 정의와 서버가동은 이전 포스트에 있습니다. (이전포스트: https://mason-lee.tistory.com/19) GraphQL을 사용하기 위해서는 기본적으로 typeDefs와 resolvers를 작성해 주어야됩니다. 기본사용 typeDefs typeDefs에서는 입력값(인자)와 출력값의 타입을 정해 놓습니다(Type Definition). import { gql } from "apollo-server"; const typeDefs = gql` type Movie { title: String! genres: String description: String } type Query { allMovies: [Movie]! } type Mutation { addMovie(title: ..

Nodejs 2022.12.29

GraphQL에서 파일 업로드

기존의 아폴로 서버에서 파일 업로드를 하기 위해선 express를 설치해주어야한다. 기존의 아폴로 서버 import { ApolloServer, gql } from "apollo-server"; import schema from "./schema"; //typeDefs와 resolvers의 통합 const server = new ApolloServer({ schema, }); server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`); }); 기존의 아폴로 서버에서 npm을 이용하여 express와 graphql-upload를 설치 npm install apollo-server-express express graphql-uplo..

Nodejs 2022.12.24

GraphQl과 Apollo

GraphQL이란? GraphQL이란 페이스북에서 제작한 API를 위한 쿼리 언어이다. GraphQL만의 특징으로는 사용자에게 전체 데이터가아닌 필요한 데이터만을 골라 제공할수있다. 또한 REST API와 다르게 단일 엔드포인트를 사용한다. 예를 들어 REST API의 경우 "example.com/home", "example.com/user"와 같이 URL의 엔드포인트를 이용하여 통신이 되지만 GraphQL의 경우 "example.com/graphql" 하나로 원하는 데이터를 가저올수 있다. npm install @apollo/server graphql 먼저 npm을 이용해 apollo와 graphql을 설치 server.js (index.js) import { ApolloServer, gql } fro..

Nodejs 2022.12.23