Skip to content

GraphQL

Execute GraphQL queries and mutations.

2 modules

ModuleDescription
Đột biến GraphQLThực hiện đột biến GraphQL với một endpoint
Truy vấn GraphQLThực hiện truy vấn GraphQL với một endpoint

Modules

Đột biến GraphQL

graphql.mutation

Thực hiện đột biến GraphQL với một endpoint

Parameters:

NameTypeRequiredDefaultDescription
urlstringYes-URL endpoint của GraphQL
mutationstringYes-Chuỗi đột biến GraphQL
variablesobjectNo-Biến đột biến GraphQL dưới dạng cặp khóa-giá trị
headersobjectNo-Headers HTTP bổ sung để gửi cùng yêu cầu
auth_tokenstringNo-Mã Bearer để xác thực (thêm vào header Authorization)

Output:

FieldTypeDescription
dataobjectDữ liệu phản hồi GraphQL
errorsarrayLỗi GraphQL (null nếu không có lỗi)
status_codenumberMã trạng thái HTTP

Example: Create user mutation

yaml
url: https://api.example.com/graphql
mutation: mutation CreateUser($input: UserInput!) { createUser(input: $input) { id name } }
variables: {"input": {"name": "John", "email": "john@example.com"}}

Truy vấn GraphQL

graphql.query

Thực hiện truy vấn GraphQL với một endpoint

Parameters:

NameTypeRequiredDefaultDescription
urlstringYes-URL endpoint của GraphQL
querystringYes-Chuỗi truy vấn GraphQL
variablesobjectNo-Biến truy vấn GraphQL dưới dạng cặp khóa-giá trị
headersobjectNo-Headers HTTP bổ sung để gửi cùng yêu cầu
auth_tokenstringNo-Mã Bearer để xác thực (thêm vào header Authorization)

Output:

FieldTypeDescription
dataobjectDữ liệu phản hồi GraphQL
errorsarrayLỗi GraphQL (null nếu không có lỗi)
status_codenumberMã trạng thái HTTP

Example: Simple query

yaml
url: https://api.example.com/graphql
query: { users { id name } }

Example: Query with variables and auth

yaml
url: https://api.example.com/graphql
query: query GetUser($id: ID!) { user(id: $id) { id name email } }
variables: {"id": "123"}
auth_token: my-token

Released under the Apache 2.0 License.