GraphQLQueryBuilder class

Fluent GraphQL query builder for constructing and executing complex queries.

Constructors

GraphQLQueryBuilder<TSchema, TEntity>(GraphQLClient, string)

Creates a query builder for a single entity.

Methods

after(string)

Continue pagination after the given cursor.

execute()

Execute the query and return all matching records.

executePaginated()

Execute the query and return a paginated result with cursor metadata.

findFirst()

Execute the query and return only the first matching record.

first(number)

Limit the result to the first count records.

orderBy(OrderByInput<TSchema[TEntity]>)

Add an order-by clause. Repeated calls append additional sort keys.

select<TFields>(TFields)

Select the fields (and nested relationship fields) to return.

where(FilterInput<TSchema[TEntity]>)

Add filter conditions. Repeated calls are merged together.

Constructor Details

GraphQLQueryBuilder<TSchema, TEntity>(GraphQLClient, string)

Creates a query builder for a single entity.

new GraphQLQueryBuilder(graphqlClient: GraphQLClient, entityName: string)

Parameters

graphqlClient
GraphQLClient

The GraphQL client used to execute the built query.

entityName

string

The entity name to query (pluralized internally for DAB).

Method Details

after(string)

Continue pagination after the given cursor.

function after(cursor: string): GraphQLQueryBuilder<TSchema, TEntity>

Parameters

cursor

string

The endCursor from a previous paginated result.

Returns

GraphQLQueryBuilder<TSchema, TEntity>

This builder, for chaining.

execute()

Execute the query and return all matching records.

function execute(): Promise<TSchema[TEntity][]>

Returns

Promise<TSchema[TEntity][]>

The matching records.

executePaginated()

Execute the query and return a paginated result with cursor metadata.

function executePaginated(): Promise<PagedResult<TSchema[TEntity]>>

Returns

Promise<PagedResult<TSchema[TEntity]>>

A PagedResult containing the items plus endCursor and hasNextPage.

findFirst()

Execute the query and return only the first matching record.

function findFirst(): Promise<null | TSchema[TEntity]>

Returns

Promise<null | TSchema[TEntity]>

The first matching record, or null if none match.

first(number)

Limit the result to the first count records.

function first(count: number): GraphQLQueryBuilder<TSchema, TEntity>

Parameters

count

number

The maximum number of records to return.

Returns

GraphQLQueryBuilder<TSchema, TEntity>

This builder, for chaining.

orderBy(OrderByInput<TSchema[TEntity]>)

Add an order-by clause. Repeated calls append additional sort keys.

function orderBy(order: OrderByInput<TSchema[TEntity]>): GraphQLQueryBuilder<TSchema, TEntity>

Parameters

order

OrderByInput<TSchema[TEntity]>

The order-by specification (field to 'asc'/'desc').

Returns

GraphQLQueryBuilder<TSchema, TEntity>

This builder, for chaining.

select<TFields>(TFields)

Select the fields (and nested relationship fields) to return.

function select<TFields>(fields: TFields): GraphQLQueryBuilder<TSchema, TEntity>

Parameters

fields

TFields

The field selection. Use dot notation (e.g. 'author.name') for nested fields.

Returns

GraphQLQueryBuilder<TSchema, TEntity>

This builder, for chaining.

where(FilterInput<TSchema[TEntity]>)

Add filter conditions. Repeated calls are merged together.

function where(conditions: FilterInput<TSchema[TEntity]>): GraphQLQueryBuilder<TSchema, TEntity>

Parameters

conditions

FilterInput<TSchema[TEntity]>

The filter conditions to apply.

Returns

GraphQLQueryBuilder<TSchema, TEntity>

This builder, for chaining.