Skip to content

FluxbaseGraphQL

GraphQL client class for executing queries and mutations

new FluxbaseGraphQL(fetch): FluxbaseGraphQL

Create a new GraphQL client

ParameterTypeDescription
fetchFluxbaseFetchThe HTTP client to use for requests

FluxbaseGraphQL

execute<T>(query, variables?, operationName?, options?): Promise<GraphQLResponse<T>>

Execute a GraphQL request with an operation name

Use this when your query document contains multiple operations and you need to specify which one to execute.

Type ParameterDefault typeDescription
TunknownThe expected response data type
ParameterTypeDescription
querystringThe GraphQL document containing one or more operations
variables?Record<string, unknown>Variables to pass to the operation
operationName?stringThe name of the operation to execute
options?GraphQLRequestOptionsAdditional request options

Promise<GraphQLResponse<T>>

Promise resolving to the GraphQL response

const { data } = await client.graphql.execute(`
query GetUser($id: ID!) {
user(id: $id) { id email }
}
query ListUsers {
users { id email }
}
`, { id: '123' }, 'GetUser')

introspect(options?): Promise<GraphQLResponse<object>>

Fetch the GraphQL schema via introspection

Returns the full schema information including types, fields, and directives. Useful for tooling and documentation.

ParameterTypeDescription
options?GraphQLRequestOptionsAdditional request options

Promise<GraphQLResponse<object>>

Promise resolving to the introspection result

const { data, errors } = await client.graphql.introspect()
if (data) {
console.log('Types:', data.__schema.types.length)
}

mutation<T>(mutation, variables?, options?): Promise<GraphQLResponse<T>>

Execute a GraphQL mutation

Type ParameterDefault typeDescription
TunknownThe expected response data type
ParameterTypeDescription
mutationstringThe GraphQL mutation string
variables?Record<string, unknown>Variables to pass to the mutation
options?GraphQLRequestOptionsAdditional request options

Promise<GraphQLResponse<T>>

Promise resolving to the GraphQL response

interface CreateUserMutation {
insertUser: { id: string; email: string }
}
const { data, errors } = await client.graphql.mutation<CreateUserMutation>(`
mutation CreateUser($data: UserInput!) {
insertUser(data: $data) {
id
email
}
}
`, { data: { email: 'user@example.com' } })

query<T>(query, variables?, options?): Promise<GraphQLResponse<T>>

Execute a GraphQL query

Type ParameterDefault typeDescription
TunknownThe expected response data type
ParameterTypeDescription
querystringThe GraphQL query string
variables?Record<string, unknown>Variables to pass to the query
options?GraphQLRequestOptionsAdditional request options

Promise<GraphQLResponse<T>>

Promise resolving to the GraphQL response

interface UsersQuery {
users: Array<{ id: string; email: string }>
}
const { data, errors } = await client.graphql.query<UsersQuery>(`
query {
users { id email }
}
`)
if (data) {
console.log(data.users)
}