From d981066dea4c925e5712098cf34946a2dbc29392 Mon Sep 17 00:00:00 2001 From: Juan Garcia Date: Mon, 9 Dec 2024 10:51:33 +0100 Subject: [PATCH] Implement creation for feed/graph/namespace --- packages/client/src/actions/feed.ts | 24 +++++++++++++++ packages/client/src/actions/graph.ts | 24 +++++++++++++++ packages/client/src/actions/index.ts | 5 +++- packages/client/src/actions/namespace.ts | 30 +++++++++++++++++++ packages/graphql/src/feed.ts | 37 ++++++++++++++++++++++++ packages/graphql/src/graph.ts | 37 ++++++++++++++++++++++++ packages/graphql/src/index.ts | 3 ++ packages/graphql/src/namespace.ts | 37 ++++++++++++++++++++++++ 8 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 packages/client/src/actions/feed.ts create mode 100644 packages/client/src/actions/graph.ts create mode 100644 packages/client/src/actions/namespace.ts create mode 100644 packages/graphql/src/feed.ts create mode 100644 packages/graphql/src/graph.ts create mode 100644 packages/graphql/src/namespace.ts diff --git a/packages/client/src/actions/feed.ts b/packages/client/src/actions/feed.ts new file mode 100644 index 000000000..ee7533cf9 --- /dev/null +++ b/packages/client/src/actions/feed.ts @@ -0,0 +1,24 @@ +import type { CreateFeedRequest, CreateFeedResult } from '@lens-protocol/graphql'; +import { CreateFeedMutation } from '@lens-protocol/graphql'; +import type { ResultAsync } from '@lens-protocol/types'; + +import type { SessionClient } from '../clients'; +import type { UnauthenticatedError, UnexpectedError } from '../errors'; + +/** + * Create a Feed + * + * ```ts + * const result = await createFeed(sessionClient); + * ``` + * + * @param client - The session client logged as a builder. + * @param request - The mutation request. + * @returns Tiered transaction result. + */ +export function createFeed( + client: SessionClient, + request: CreateFeedRequest, +): ResultAsync { + return client.mutation(CreateFeedMutation, { request }); +} diff --git a/packages/client/src/actions/graph.ts b/packages/client/src/actions/graph.ts new file mode 100644 index 000000000..75ac6145e --- /dev/null +++ b/packages/client/src/actions/graph.ts @@ -0,0 +1,24 @@ +import type { CreateGraphRequest, CreateGraphResult } from '@lens-protocol/graphql'; +import { CreateGraphMutation } from '@lens-protocol/graphql'; +import type { ResultAsync } from '@lens-protocol/types'; + +import type { SessionClient } from '../clients'; +import type { UnauthenticatedError, UnexpectedError } from '../errors'; + +/** + * Create a Graph + * + * ```ts + * const result = await createGraph(sessionClient); + * ``` + * + * @param client - The session client logged as a builder. + * @param request - The mutation request. + * @returns Tiered transaction result. + */ +export function createGraph( + client: SessionClient, + request: CreateGraphRequest, +): ResultAsync { + return client.mutation(CreateGraphMutation, { request }); +} diff --git a/packages/client/src/actions/index.ts b/packages/client/src/actions/index.ts index d3c97fe25..5734004ec 100644 --- a/packages/client/src/actions/index.ts +++ b/packages/client/src/actions/index.ts @@ -1,8 +1,11 @@ export * from './account'; export * from './app'; export * from './authentication'; +export * from './feed'; export * from './follow'; +export * from './graph'; +export * from './namespace'; export * from './post'; export * from './posts'; -export * from './transactions'; export * from './timeline'; +export * from './transactions'; diff --git a/packages/client/src/actions/namespace.ts b/packages/client/src/actions/namespace.ts new file mode 100644 index 000000000..f4a22c2df --- /dev/null +++ b/packages/client/src/actions/namespace.ts @@ -0,0 +1,30 @@ +import type { + CreateUsernameNamespaceRequest, + CreateUsernameNamespaceResult, +} from '@lens-protocol/graphql'; +import { CreateUsernameNamespaceMutation } from '@lens-protocol/graphql'; +import type { ResultAsync } from '@lens-protocol/types'; + +import type { SessionClient } from '../clients'; +import type { UnauthenticatedError, UnexpectedError } from '../errors'; + +/** + * Create a Namespace + * + * ```ts + * const result = await createUsernameNamespace(sessionClient, { + * symbol: 'NAME', + * namespace: 'custom-namespace', + * }); + * ``` + * + * @param client - The session client logged as a builder. + * @param request - The mutation request. + * @returns Tiered transaction result. + */ +export function createUsernameNamespace( + client: SessionClient, + request: CreateUsernameNamespaceRequest, +): ResultAsync { + return client.mutation(CreateUsernameNamespaceMutation, { request }); +} diff --git a/packages/graphql/src/feed.ts b/packages/graphql/src/feed.ts new file mode 100644 index 000000000..166312318 --- /dev/null +++ b/packages/graphql/src/feed.ts @@ -0,0 +1,37 @@ +import type { FragmentOf } from 'gql.tada'; +import { SelfFundedTransactionRequest, TransactionWillFail } from './fragments'; +import { type RequestOf, graphql } from './graphql'; + +const CreateFeedResponse = graphql( + `fragment CreateFeedResponse on CreateFeedResponse { + __typename + hash + }`, +); +export type CreateFeedResponse = FragmentOf; + +const CreateFeedResult = graphql( + `fragment CreateFeedResult on CreateFeedResult { + ...on CreateFeedResponse { + ...CreateFeedResponse + } + ...on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ...on TransactionWillFail { + ...TransactionWillFail + } + }`, + [CreateFeedResponse, SelfFundedTransactionRequest, TransactionWillFail], +); +export type CreateFeedResult = FragmentOf; + +export const CreateFeedMutation = graphql( + `mutation CreateFeed($request: CreateFeedRequest!) { + value: createFeed(request: $request) { + ...CreateFeedResult + } + }`, + [CreateFeedResult], +); +export type CreateFeedRequest = RequestOf; diff --git a/packages/graphql/src/graph.ts b/packages/graphql/src/graph.ts new file mode 100644 index 000000000..2e19d76ed --- /dev/null +++ b/packages/graphql/src/graph.ts @@ -0,0 +1,37 @@ +import type { FragmentOf } from 'gql.tada'; +import { SelfFundedTransactionRequest, TransactionWillFail } from './fragments'; +import { type RequestOf, graphql } from './graphql'; + +const CreateGraphResponse = graphql( + `fragment CreateGraphResponse on CreateGraphResponse { + __typename + hash + }`, +); +export type CreateGraphResponse = FragmentOf; + +const CreateGraphResult = graphql( + `fragment CreateGraphResult on CreateGraphResult { + ...on CreateGraphResponse { + ...CreateGraphResponse + } + ...on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ...on TransactionWillFail { + ...TransactionWillFail + } + }`, + [CreateGraphResponse, SelfFundedTransactionRequest, TransactionWillFail], +); +export type CreateGraphResult = FragmentOf; + +export const CreateGraphMutation = graphql( + `mutation CreateGraph($request: CreateGraphRequest!) { + value: createGraph(request: $request) { + ...CreateGraphResult + } + }`, + [CreateGraphResult], +); +export type CreateGraphRequest = RequestOf; diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index a4190f76b..757260a81 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -2,10 +2,13 @@ export * from './accounts'; export * from './app'; export * from './authentication'; export * from './enums'; +export * from './feed'; export * from './follow'; export * from './fragments'; +export * from './graph'; export * from './graphql'; export * from './health'; +export * from './namespace'; export * from './notifications'; export * from './post'; export * from './timeline'; diff --git a/packages/graphql/src/namespace.ts b/packages/graphql/src/namespace.ts new file mode 100644 index 000000000..aee15631c --- /dev/null +++ b/packages/graphql/src/namespace.ts @@ -0,0 +1,37 @@ +import type { FragmentOf } from 'gql.tada'; +import { SelfFundedTransactionRequest, TransactionWillFail } from './fragments'; +import { type RequestOf, graphql } from './graphql'; + +const CreateNamespaceResponse = graphql( + `fragment CreateNamespaceResponse on CreateNamespaceResponse { + __typename + hash + }`, +); +export type CreateNamespaceResponse = FragmentOf; + +const CreateUsernameNamespaceResult = graphql( + `fragment CreateUsernameNamespaceResult on CreateUsernameNamespaceResult { + ...on CreateNamespaceResponse { + ...CreateNamespaceResponse + } + ...on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ...on TransactionWillFail { + ...TransactionWillFail + } + }`, + [CreateNamespaceResponse, SelfFundedTransactionRequest, TransactionWillFail], +); +export type CreateUsernameNamespaceResult = FragmentOf; + +export const CreateUsernameNamespaceMutation = graphql( + `mutation CreateUsernameNamespace($request: CreateUsernameNamespaceRequest!) { + value: createUsernameNamespace(request: $request) { + ...CreateUsernameNamespaceResult + } + }`, + [CreateUsernameNamespaceResult], +); +export type CreateUsernameNamespaceRequest = RequestOf;