Writing GraphQL server-side Resolver functionsCreating Resolver Functions for Query Types

Author: Zen and the Art of Computer Programming

1 Introduction

The Query type is a data type in GraphQL, which is mainly used to return the data required for the query to the user. In practical applications, the client can send a query request to the server and obtain the corresponding data results. Different from the Mutation type, the Query type is generally only responsible for reading data operations, that is, reading data information from storage media such as databases or caches. When developing the GraphQL server, you need to define a Resolver function for the Query type to process the query request sent by the client and return the corresponding data results. This article will explain how to write the GraphQL server-side Resolver function, the parameters of the Resolver function and the role of the parameters, the execution order of the Resolver function, the implementation method of field-level permission control, and the solution for catching Resolver function exceptions.

2. Basic concepts and terms

2.1 GraphQL

GraphQL is a type system-based API query language that provides a declarative data query method. GraphQL provides GraphQL Schema through DSL (Domain-specific Language) to define the data model and its relationships. A typical GraphQL Schema includes multiple object types (ObjectType), and each object type includes several fields (Field). Each field corresponds to a resolver function, which is used to calculate or access the value of the specified field.

2.2 Query

Query refers to the request sent by the client to the server, which contains the query statement and corresponding parameters, requesting the server to perform the corresponding query operation and return the query results. GraphQL's definition of query is relatively simple, with only a string type name and a Map<String, Objec

Guess you like

Origin blog.csdn.net/universsky2015/article/details/132785443