GraphQL API 만들기

윤민상·2022년 12월 28일
0

GraphQL

목록 보기
4/5
post-thumbnail

전편 에러였던 이유는 graphql이 data의 shape을 미리 알고있어야 하기 떄문이다.

rest API는 URL의 집합체

graphql API는 많은 type들의 집합

-apollo server에 type을 설명해야된다.



server.js

import { ApolloServer, gql } from "apollo-server";

const typeDefs = gql`
  type Query {
    text: String
    hello: String
  }
`;

const server = new ApolloServer({ typeDefs });

server.listen().then(({ url }) => {
  console.log(`Running on ${url}`);
});



graphql Schema Definition Language

  • gql`` => graphql의 기능이다.
  • graphql API한테 우리가 사용할 data의 shape를 설명해주기 위해서 graphql sdl 사용
  • type Query{
    (필수로 적어줘야한다.)
    }
    모든 사용자가 request가능하다.

rest API와 비교

에러가 없으면 Running on http://localhost:4000/ 문구가있다.

다음시간에 꼐속..

profile
비전공자 개발자

0개의 댓글