Skip to content

FluxbaseGraphQL

GraphQL client class for executing queries and mutations

new FluxbaseGraphQL(fetch): FluxbaseGraphQL

Create a new GraphQL client

Parameter Type Description
fetch FluxbaseFetch The 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 Parameter Default type Description
T unknown The expected response data type
Parameter Type Description
query string The GraphQL document containing one or more operations
variables? Record<string, unknown> Variables to pass to the operation
operationName? string The name of the operation to execute
options? GraphQLRequestOptions Additional 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<{ __schema: IntrospectionSchema; }>>

Fetch the GraphQL schema via introspection

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

Parameter Type Description
options? GraphQLRequestOptions Additional request options

Promise<GraphQLResponse<{ __schema: IntrospectionSchema; }>>

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 Parameter Default type Description
T unknown The expected response data type
Parameter Type Description
mutation string The GraphQL mutation string
variables? Record<string, unknown> Variables to pass to the mutation
options? GraphQLRequestOptions Additional 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 Parameter Default type Description
T unknown The expected response data type
Parameter Type Description
query string The GraphQL query string
variables? Record<string, unknown> Variables to pass to the query
options? GraphQLRequestOptions Additional 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)
}