Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stale-pandas-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@team-plain/typescript-sdk': minor
---

Add ability to fetch a user by id (`userById()`)
17 changes: 16 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
UpsertTenantDocument,
UpsertThreadFieldDocument,
UserByEmailDocument,
UserByIdDocument,
type UserPartsFragment,
WebhookTargetDocument,
type WebhookTargetPartsFragment,
Expand Down Expand Up @@ -170,7 +171,7 @@ export class PlainClient {
}

/**
* Get a paginated list of customers.
* Get a a user by email
*/
async getUserByEmail(
variables: VariablesOf<typeof UserByEmailDocument>
Expand All @@ -183,6 +184,20 @@ export class PlainClient {
return unwrapData(res, (q) => q.userByEmail || null);
}

/**
* Get a user by id
*/
async getUserById(
variables: VariablesOf<typeof UserByIdDocument>
): SDKResult<UserPartsFragment | null> {
const res = await request(this.#ctx, {
query: UserByIdDocument,
variables,
});

return unwrapData(res, (q) => q.userById || null);
}

/**
* Get a paginated list of customers.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/graphql/queries/userById.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query userById($id: ID!) {
userById: user(userId: $id) {
...UserParts
}
}
Loading
Loading