Skip to content

Commit

Permalink
Merge branch 'next' into T-23255/js-actions-add-username-mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
juangm committed Dec 11, 2024
2 parents 54816ab + 129ae5a commit ae5ee42
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/actions/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function fetchTimeline(
}

/**
* Fetch fetchTimelineHighlights from an account.
* Fetch Timeline Highlights for an account.
*
* ```ts
* const result = await fetchTimelineHighlights(anyClient, {
Expand Down
48 changes: 48 additions & 0 deletions packages/client/src/actions/username.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ import type {
CreateUsernameResult,
UnassignUsernameFromAccountRequest,
UnassignUsernameToAccountResult,
Username,
UsernameRequest,
UsernamesRequest,
} from '@lens-protocol/graphql';
import {
AssignUsernameToAccountMutation,
CreateUsernameMutation,
UnassignUsernameFromAccountMutation,
UsernameQuery,
UsernamesQuery,
} from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

import type { AnyClient } from '../clients';
import type { Paginated } from '../types';

/**
* Create a username
*
Expand Down Expand Up @@ -81,3 +89,43 @@ export function unassignUsernameFromAccount(
): ResultAsync<UnassignUsernameToAccountResult, UnauthenticatedError | UnexpectedError> {
return client.query(UnassignUsernameFromAccountMutation, { request });
}

/**
* 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 });
}
1 change: 1 addition & 0 deletions packages/graphql/src/fragments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './SponsoredTransactionRequest';
export * from './SelfFundedTransactionRequest';
export * from './TransactionWillFail';
export * from './username';
export * from './namespace';
27 changes: 27 additions & 0 deletions packages/graphql/src/fragments/namespace.ts
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>;
22 changes: 10 additions & 12 deletions packages/graphql/src/fragments/username.ts
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>;
28 changes: 28 additions & 0 deletions packages/graphql/src/username.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { FragmentOf } from 'gql.tada';
import {
PaginatedResultInfo,
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
TransactionWillFail,
Username,
} from './fragments';
import { type RequestOf, graphql } from './graphql';

Expand Down Expand Up @@ -133,3 +135,29 @@ export const UnassignUsernameFromAccountMutation = graphql(
export type UnassignUsernameFromAccountRequest = RequestOf<
typeof UnassignUsernameFromAccountMutation
>;

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>;

0 comments on commit ae5ee42

Please sign in to comment.