open:introduction-to-graphql

Introduction to GraphQL

GraphQL, 작동 방식 및 사용 방법에 대해 알아보세요. GraphQL 서비스를 구축하는 방법에 대한 문서를 찾고 계십니까? 다양한 언어로 GraphQL을 구현하는 데 도움이 되는 라이브러리가 있습니다. 실용적인 튜토리얼을 통한 심층 학습 경험은 How to GraphQL을 참조하십시오. 무료 온라인 과정인 Exploring GraphQL: A Query Language for API를 확인하십시오.1)

GraphQL은 API용 쿼리 언어이며 데이터에 대해 정의한 유형 시스템을 사용하여 쿼리를 실행하기 위한 서버 측 런타임입니다. GraphQL은 특정 데이터베이스나 스토리지 엔진에 연결되어 있지 않으며 대신 기존 코드와 데이터로 뒷받침됩니다.2)

GraphQL 서비스는 해당 유형의 유형과 필드를 정의한 다음 각 유형의 각 필드에 대한 기능을 제공하여 생성됩니다. 예를 들어 로그인한 사용자(나)와 해당 사용자의 이름을 알려주는 GraphQL 서비스는 다음과 같을 수 있습니다. 3)

type Query {
  me: User
}
 
type User {
  id: ID
  name: String
}

각 유형의 각 필드에 대한 기능과 함께: 4)

function Query_me(request) {
  return request.auth.user;
}
 
function User_name(user) {
  return user.getName();
}

GraphQL 서비스가 실행된 후(일반적으로 웹 서비스의 URL에서), GraphQL 쿼리를 수신하여 유효성을 검사하고 실행할 수 있습니다. 서비스는 먼저 쿼리가 정의된 유형과 필드만 참조하는지 확인한 다음 제공된 함수를 실행하여 결과를 생성합니다. 5)

예를 들어 쿼리는 다음과 같습니다. 6)

{
  me {
    name
  }
}

다음 JSON 결과를 생성할 수 있습니다.7)

{
  "me": {
    "name": "Luke Skywalker"
  }
}


1)
Learn about GraphQL, how it works, and how to use it. Looking for documentation on how to build a GraphQL service? There are libraries to help you implement GraphQL in many different languages. For an in-depth learning experience with practical tutorials, see How to GraphQL. Check out the free online course, Exploring GraphQL: A Query Language for APIs.
2)
GraphQL is a query language for your API, and a server-side runtime for executing queries using a type system you define for your data. GraphQL isn't tied to any specific database or storage engine and is instead backed by your existing code and data.
3)
A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type. For example, a GraphQL service that tells you who the logged in user is (me) as well as that user's name might look like this:
4)
Along with functions for each field on each type:
5)
After a GraphQL service is running (typically at a URL on a web service), it can receive GraphQL queries to validate and execute. The service first checks a query to ensure it only refers to the types and fields defined, and then runs the provided functions to produce a result.
6)
For example, the query:
7)
Could produce the following JSON result:
  • open/introduction-to-graphql.txt
  • 마지막으로 수정됨: 2022/08/31 01:31
  • 저자 127.0.0.1