GraphQLRequest

data class GraphQLRequest<TVariables : GraphQLVariables>(val query: String, val operationName: String, val variables: TVariables? = null, val extensions: Map<String, Any?> = emptyMap())(source)

A typed GraphQL request payload.

When using the codegen Gradle plugin, generated operation objects provide .request(...) factory methods that construct GraphQLRequest instances with type-safe variable classes. For asset-based workflows, construct GraphQLRequest manually or use QueryContainerBuilder.

Example (codegen):

val request = GetMarketPlaceApps.request(first = 15, after = null)

Example (manual):

val request = GraphQLRequest(
query = "query GetCurrentUser { viewer { login } }",
operationName = "GetCurrentUser",
)

Type Parameters

TVariables

The type of variables, or EmptyGraphQLVariables for operations without variables.

See also

Constructors

Link copied to clipboard
constructor(query: String, operationName: String, variables: TVariables? = null, extensions: Map<String, Any?> = emptyMap())

Properties

Link copied to clipboard

Optional extensions map (e.g. persistedQuery).

Link copied to clipboard

The operation name.

Link copied to clipboard

The full GraphQL document string.

Link copied to clipboard

The operation variables, or null if there are none.

Functions

Link copied to clipboard
fun withPersistedQuery(sha256Hash: String, version: Int = 1): GraphQLRequest<TVariables>

Returns a copy of this request with a persisted query extension added.