While each Modus SDK offers similar capabilities, the APIs and usage may vary between languages.

Modus GraphQL APIs documentation is available on the following pages:

The Modus GraphQL APIs allow you to securely call and fetch data from any GraphQL endpoint.

Import

To begin, import the graphql package from the SDK:

import "github.com/hypermodeinc/modus/sdk/go/pkg/graphql"

GraphQL APIs

The APIs in the graphql package are below, organized by category.

We’re constantly introducing new APIs through ongoing development with early users. Please open an issue if you have ideas on what would make Modus even more powerful for your next app!

Functions

Execute

Execute a GraphQL statement to call a query or apply mutation against a GraphQL endpoint.

Execute[T any](
  connection,
  statement string,
  variables map[string]any
) (*Response[T], error)
T
required

Type of object to use for the data returned from the query. This can be any type, including a custom type defined in your project. It should match the shape of the data returned from the GraphQL query.

Define custom types in the project’s source code. All types must be JSON serializable. You can also use built-in types such as strings, numbers, slices, and maps.

connection
string
required

Name of the connection, as defined in the manifest.

statement
string
required

GraphQL statement containing the query or mutation operation to execute.

While it’s possible to directly include parameter values into your GraphQL statement, it’s highly recommended to pass a variables map instead. This can help to prevent against injection attacks and other security vulnerabilities.

variables
map[string]any

Optional variables to include with the query.

The key should be the name of the GraphQL variable. The value can be of any type that’s JSON serializable, including strings, numbers, boolean values, slices, maps, and custom structs.

Types

Response

type Response[T any] struct {
  Errors []ErrorResult
  Data   *T
}

A response object from the GraphQL query.

Either Errors or Data is present, depending on the result of the query.

Errors
[]ErrorResult

An slice of errors incurred as part of your GraphQL request, if any.

Each error in the slice is an ErrorResult object. If there are no errors, this field is nil.

Data
*T

The resulting data selected by the GraphQL operation.

The data is a pointer to an object the type specified in the call to the Execute function. If data is absent due to errors, this field is nil.

ErrorResult

type ErrorResult struct {
  Message   string
  Locations []CodeLocation
  Path      []string
}

The details of an error incurred as part of a GraphQL operation.

Message
string

Description of the error incurred.

Path
[]string

Path to the area of the GraphQL statement related to the error.

Each item in the slice represents a segment of the path.

Locations
[]CodeLocation

An slice of CodeLocation objects that point to the specific location of the error in the GraphQL statement.

CodeLocation

type CodeLocation struct {
  Line   uint32
  Column uint32
}

The location of specific code within a GraphQL statement.

Line
uint32

Line number within the GraphQL statement for the code.

Column
uint32

Column number within the GraphQL statement for the code.