-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement username/usernames queries #997
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
add181b
Implement username/usernames queries
juangm f20ed44
Merge branch 'next' into T-23199/js-action-username-usernames-queries
juangm 513c73f
Merge branch 'next' into T-23199/js-action-username-usernames-queries
juangm a3ee003
Fix lint
juangm 5cf9f0f
Update packages/client/src/actions/timeline.ts
juangm 91a89ca
Update packages/client/src/actions/username.ts
juangm b04d6cb
Merge branch 'next' into T-23199/js-action-username-usernames-queries
juangm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
gql.tada
likes GQL comments, does it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't complain when I do
pnpm run check
so I guess it is fine 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
over on the types generated from it, if you get
never
it failed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juangm did you check if the type is usable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just removed the comments, when we have the rules properly defined I will add where needed