-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #997 from lens-protocol/T-23199/js-action-username…
…-usernames-queries Co-authored-by: Cesare Naldi <[email protected]>
- Loading branch information
Showing
8 changed files
with
116 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { Username, UsernameRequest, UsernamesRequest } from '@lens-protocol/graphql'; | ||
import { UsernameQuery, UsernamesQuery } from '@lens-protocol/graphql'; | ||
import type { ResultAsync } from '@lens-protocol/types'; | ||
|
||
import type { AnyClient } from '../clients'; | ||
import type { UnexpectedError } from '../errors'; | ||
import type { Paginated } from '../types'; | ||
|
||
/** | ||
* Fetch username details. | ||
* | ||
* ```ts | ||
* const result = await fetchUsername(anyClient, { | ||
* username: { localName: 'wagmi' }, | ||
* }); | ||
* ``` | ||
* | ||
* @param client - Any Lens client. | ||
* @param request - The query request. | ||
* @returns The username details. | ||
*/ | ||
export function fetchUsername( | ||
client: AnyClient, | ||
request: UsernameRequest, | ||
): ResultAsync<Username | null, UnexpectedError> { | ||
return client.query(UsernameQuery, { request }); | ||
} | ||
|
||
/** | ||
* Fetch usernames owned by an address. | ||
* | ||
* ```ts | ||
* const result = await fetchUsernames(anyClient, { | ||
* owner: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'), | ||
* }); | ||
* ``` | ||
* | ||
* @param client - Any Lens client. | ||
* @param request - The query request. | ||
* @returns The list of owned usernames. | ||
*/ | ||
export function fetchUsernames( | ||
client: AnyClient, | ||
request: UsernamesRequest, | ||
): ResultAsync<Paginated<Username> | null, UnexpectedError> { | ||
return client.query(UsernamesQuery, { request }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { FragmentOf } from 'gql.tada'; | ||
import { graphql } from '../graphql'; | ||
|
||
export const UsernameNamespace = graphql( | ||
`fragment UsernameNamespace on UsernameNamespace { | ||
__typename | ||
address | ||
namespace | ||
createdAt | ||
metadata { | ||
__typename | ||
description | ||
id | ||
} | ||
owner | ||
# TODO: Implement rules | ||
# rules { | ||
# anyOf { | ||
# ...RULE | ||
# } | ||
# required { | ||
# ...RULE | ||
# } | ||
# } | ||
}`, | ||
); | ||
export type UsernameNamespace = FragmentOf<typeof UsernameNamespace>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
import type { FragmentOf } from 'gql.tada'; | ||
import { graphql } from '../graphql'; | ||
import { UsernameNamespace } from './namespace'; | ||
|
||
export const Username = graphql(` | ||
fragment Username on Username { | ||
export const Username = graphql( | ||
`fragment Username on Username { | ||
__typename | ||
id | ||
value | ||
namespace { | ||
address | ||
namespace | ||
metadata { | ||
description | ||
id | ||
} | ||
} | ||
localName | ||
linkedTo | ||
ownedBy | ||
timestamp | ||
} | ||
`); | ||
namespace { | ||
...UsernameNamespace | ||
} | ||
}`, | ||
[UsernameNamespace], | ||
); | ||
export type Username = FragmentOf<typeof Username>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { PaginatedResultInfo, Username } from './fragments'; | ||
import { type RequestOf, graphql } from './graphql'; | ||
|
||
export const UsernameQuery = graphql( | ||
`query Username($request: UsernameRequest!) { | ||
value: username(request: $request) { | ||
...Username | ||
} | ||
}`, | ||
[Username], | ||
); | ||
export type UsernameRequest = RequestOf<typeof UsernameQuery>; | ||
|
||
export const UsernamesQuery = graphql( | ||
`query Usernames($request: UsernamesRequest!) { | ||
value: usernames(request: $request) { | ||
__typename | ||
items { | ||
...Username | ||
} | ||
pageInfo { | ||
...PaginatedResultInfo | ||
} | ||
} | ||
}`, | ||
[Username, PaginatedResultInfo], | ||
); | ||
export type UsernamesRequest = RequestOf<typeof UsernamesQuery>; |