GraphQLEntityClient class
Type-safe fluent client for reading and mutating a single Data API Builder
entity. Instances are typically obtained via the DataApi proxy
(dataApi.<Entity>) rather than constructed directly.
Query methods (select, where, orderBy, first) return a chainable
GraphQLQueryBuilder; call .execute() to run the query. Direct
methods (findMany, findFirst, findById) and mutation methods
(create, update, delete, upsert) execute immediately.
Example
const users = await dataApi.User
.select(['id', 'name', 'email'])
.where({ isActive: { eq: true } })
.orderBy({ createdAt: 'desc' })
.execute();
const created = await dataApi.User.create({ name: 'Jane', email: 'jane@example.com' });
Methods
| create(Create |
Create a new record. |
| delete(Where |
Delete a record identified by its primary key. |
| find |
Fetch a single record by its primary key. |
| find |
Fetch the first record matching an optional filter. |
| find |
Fetch all records matching an optional filter. |
| first(number) | Start a query limited to the first |
| order |
Start a query ordered by the given fields. |
| select<TFields>(TFields) | Start a query selecting the given fields. |
| update(Where |
Update an existing record identified by its primary key. |
| upsert(Where |
Update a record if it exists, otherwise create it. |
| where(Filter |
Start a query filtered by the given conditions. |
Constructor Details
GraphQLEntityClient<TSchema, TEntity>(GraphQLClient, TEntity)
new GraphQLEntityClient(graphqlClient: GraphQLClient, entityName: TEntity)
Parameters
- graphqlClient
- GraphQLClient
The underlying GraphQLClient used to send requests.
- entityName
-
TEntity
The entity name this client operates on.
Method Details
create(CreateInput<TSchema[TEntity]>)
Create a new record.
function create(input: CreateInput<TSchema[TEntity]>): Promise<TSchema[TEntity]>
Parameters
- input
-
CreateInput<TSchema[TEntity]>
The fields for the new record. Relationship objects are converted to their foreign-key values.
Returns
Promise<TSchema[TEntity]>
The created record.
delete(WhereUniqueInput<TSchema[TEntity]>)
Delete a record identified by its primary key.
function delete(where: WhereUniqueInput<TSchema[TEntity]>): Promise<TSchema[TEntity]>
Parameters
- where
-
WhereUniqueInput<TSchema[TEntity]>
The unique key identifying the record to delete.
Returns
Promise<TSchema[TEntity]>
The deleted record.
findById(string)
Fetch a single record by its primary key.
function findById(id: string): Promise<null | TSchema[TEntity]>
Parameters
- id
-
string
The primary key value to look up.
Returns
Promise<null | TSchema[TEntity]>
The matching record, or null if not found.
findFirst(FilterInput<TSchema[TEntity]>)
Fetch the first record matching an optional filter.
function findFirst(filter?: FilterInput<TSchema[TEntity]>): Promise<null | TSchema[TEntity]>
Parameters
- filter
-
FilterInput<TSchema[TEntity]>
Optional filter conditions.
Returns
Promise<null | TSchema[TEntity]>
The first matching record, or null if none match.
findMany(FilterInput<TSchema[TEntity]>)
Fetch all records matching an optional filter.
function findMany(filter?: FilterInput<TSchema[TEntity]>): Promise<TSchema[TEntity][]>
Parameters
- filter
-
FilterInput<TSchema[TEntity]>
Optional filter conditions. Omit to fetch all records.
Returns
Promise<TSchema[TEntity][]>
The matching records.
first(number)
Start a query limited to the first count results.
function first(count: number): GraphQLQueryBuilder<TSchema, TEntity>
Parameters
- count
-
number
The maximum number of records to return.
Returns
GraphQLQueryBuilder<TSchema, TEntity>
A chainable GraphQLQueryBuilder; call .execute() to run it.
orderBy(OrderByInput<TSchema[TEntity]>)
Start a query ordered by the given fields.
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>
A chainable GraphQLQueryBuilder; call .execute() to run it.
select<TFields>(TFields)
Start a query selecting the given fields.
function select<TFields>(fields: TFields): GraphQLQueryBuilder<TSchema, TEntity>
Parameters
- fields
-
TFields
The fields (and nested selections) to return.
Returns
GraphQLQueryBuilder<TSchema, TEntity>
A chainable GraphQLQueryBuilder; call .execute() to run it.
update(WhereUniqueInput<TSchema[TEntity]>, Partial<MutationInput<TSchema[TEntity]>>)
Update an existing record identified by its primary key.
function update(where: WhereUniqueInput<TSchema[TEntity]>, data: Partial<MutationInput<TSchema[TEntity]>>): Promise<TSchema[TEntity]>
Parameters
- where
-
WhereUniqueInput<TSchema[TEntity]>
The unique key identifying the record to update.
- data
-
Partial<MutationInput<TSchema[TEntity]>>
The fields to change.
Returns
Promise<TSchema[TEntity]>
The updated record.
upsert(WhereUniqueInput<TSchema[TEntity]>, CreateInput<TSchema[TEntity]>, Partial<MutationInput<TSchema[TEntity]>>)
Update a record if it exists, otherwise create it.
function upsert(where: WhereUniqueInput<TSchema[TEntity]>, create: CreateInput<TSchema[TEntity]>, update: Partial<MutationInput<TSchema[TEntity]>>): Promise<TSchema[TEntity]>
Parameters
- where
-
WhereUniqueInput<TSchema[TEntity]>
The unique key used to check for an existing record.
- create
-
CreateInput<TSchema[TEntity]>
The fields to use when creating a new record.
- update
-
Partial<MutationInput<TSchema[TEntity]>>
The fields to apply when updating an existing record.
Returns
Promise<TSchema[TEntity]>
The created or updated record.
where(FilterInput<TSchema[TEntity]>)
Start a query filtered by the given conditions.
function where(conditions: FilterInput<TSchema[TEntity]>): GraphQLQueryBuilder<TSchema, TEntity>
Parameters
- conditions
-
FilterInput<TSchema[TEntity]>
The filter conditions to apply.
Returns
GraphQLQueryBuilder<TSchema, TEntity>
A chainable GraphQLQueryBuilder; call .execute() to run it.