Client: Client

Isolated

The Ballerina generic client for GraphQL(https://graphql.org/) APIs.

Constructor

Gets invoked to initialize the connector.

init (string serviceUrl, ClientConfiguration clientConfig)
  • serviceUrl string
  • URL of the target service

  • clientConfig ClientConfiguration {}
  • The configurations to be used when initializing the connector

Remote Methods

executeWithType

Executes a GraphQL document and data binds the GraphQL response to a record with data and extensions which is a subtype of GenericResponse.

execute

Executes a GraphQL document and data binds the GraphQL response to a record with data, extensions and errors which is a subtype of GenericResponseWithErrors.

executeWithType

function executeWithType(string document, map<anydata>? variables, string? operationName, map<string | string[ ]>? headers, typedesc<GenericResponse | record {} | json> targetType) returns targetType | ClientError
Isolated Function
Remote Function

Executes a GraphQL document and data binds the GraphQL response to a record with data and extensions which is a subtype of GenericResponse.

Parameters

  • document string
  • The GraphQL document. It can include queries & mutations. For example query OperationName($code:ID!) {country(code:$code) {name}}.

  • variables map<anydata>? (default ())
  • The GraphQL variables. For example {"code": "<variable_value>"}.

  • operationName string? (default ())
  • The GraphQL operation name. If a request has two or more operations, then each operation must have a name. A request can only execute one operation, so you must also include the operation name to execute.

  • headers map<string | string[ ]>? (default ())
  • The GraphQL API headers to execute each query

  • targetType typedesc<GenericResponse | record {} | json> (default <>)
  • The payload, which is expected to be returned after data binding. For example type CountryByCodeResponse record {| map<json?> extensions?; record {| record{|string name;|}? country; |} data;

Return Type

(targetType | ClientError)

The GraphQL response or a graphql:ClientError if failed to execute the query

execute

function execute(string document, map<anydata>? variables, string? operationName, map<string | string[ ]>? headers, typedesc<GenericResponseWithErrors | record {} | json> targetType) returns targetType | ClientError
Isolated Function
Remote Function

Executes a GraphQL document and data binds the GraphQL response to a record with data, extensions and errors which is a subtype of GenericResponseWithErrors.

Parameters

  • document string
  • The GraphQL document. It can include queries & mutations. For example query countryByCode($code:ID!) {country(code:$code) {name}}.

  • variables map<anydata>? (default ())
  • The GraphQL variables. For example {"code": "<variable_value>"}.

  • operationName string? (default ())
  • The GraphQL operation name. If a request has two or more operations, then each operation must have a name. A request can only execute one operation, so you must also include the operation name to execute.

  • headers map<string | string[ ]>? (default ())
  • The GraphQL API headers to execute each query

  • targetType typedesc<GenericResponseWithErrors | record {} | json> (default <>)
  • The payload (GenericResponseWithErrors), which is expected to be returned after data binding. For example type CountryByCodeResponse record {| map<json?> extensions?; record {| record{|string name;|}? country; |} data; ErrorDetail[] errors?; |};

Return Type

(targetType | ClientError)

The GraphQL response or a graphql:ClientError if failed to execute the query