Skip to content

Commit d16ed41

Browse files
authored
Add ability to get user by id (#174)
* Add ability to get user by id * Update .changeset/stale-pandas-jump.md
1 parent 31eda5a commit d16ed41

File tree

4 files changed

+128
-63
lines changed

4 files changed

+128
-63
lines changed

.changeset/stale-pandas-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@team-plain/typescript-sdk': minor
3+
---
4+
5+
Add ability to fetch a user by id (`userById()`)

src/client.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import {
8989
UpsertTenantDocument,
9090
UpsertThreadFieldDocument,
9191
UserByEmailDocument,
92+
UserByIdDocument,
9293
type UserPartsFragment,
9394
WebhookTargetDocument,
9495
type WebhookTargetPartsFragment,
@@ -170,7 +171,7 @@ export class PlainClient {
170171
}
171172

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

187+
/**
188+
* Get a user by id
189+
*/
190+
async getUserById(
191+
variables: VariablesOf<typeof UserByIdDocument>
192+
): SDKResult<UserPartsFragment | null> {
193+
const res = await request(this.#ctx, {
194+
query: UserByIdDocument,
195+
variables,
196+
});
197+
198+
return unwrapData(res, (q) => q.userById || null);
199+
}
200+
186201
/**
187202
* Get a paginated list of customers.
188203
*/

src/graphql/queries/userById.gql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query userById($id: ID!) {
2+
userById: user(userId: $id) {
3+
...UserParts
4+
}
5+
}

0 commit comments

Comments
 (0)