GraphQL is the better REST

이동규 (Justin)·2022년 2월 1일
0

갑자기, GraphQL

목록 보기
3/3
post-thumbnail
query {
	User (id: "er3tg439frjw") {
    	name
        posts {
        	title
        }
        followers (last: 3) {
        	name
        }
    }
}

이렇게 보내면


{
	"data": {
    	"User": {
        	"name": "Mary",
            "posts": [
            	{ title: "Learn GraphQL today" }
            ],
            "followers": [
            	{ name: "John" },
                { name: "Alice" },
                { name: "Sarah }
            ]
        }
    }
}

이렇게 받을 수 있다.

Using GQL, the client can specify exactly the data it needs in a query. Notice that the struct ure of the server's response follows precisely the nested structure defined in the query.

이렇게 되면 자주 쓰는 데이터 / 아닌 데이터에 대한 분석이 가능해진다. 클라이언트에서 자주 요청하는 데이터와 아닌 데이터에 대한 데이터(?)가 생겨나는 것이다.

REST로 구성된 API일 때는 항상 고정적으로 데이터를 불러왔기 때문에 클라이언트에서 결과적으로 어떤 데이터들을 사용하는지 알 수 없었으므로 이런 데이터에 대한 데이터(?)를 수집할 수 없었지만 GQL은 데이터를 매번 다르게 요청하기 때문에, 이에 대한 모니터링과 분석이 가능해진 것.

Benefits of a Schema & Type system

GQL은 strong type system을 사용한다.

profile
Frontend Developer, JamStack, Ethereum

0개의 댓글