Skip to content

Commit

Permalink
Implement creation for feed/graph/namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
juangm committed Dec 9, 2024
1 parent 9dcd3b3 commit d981066
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/client/src/actions/feed.ts
Original file line number Diff line number Diff line change
@@ -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<CreateFeedResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateFeedMutation, { request });
}
24 changes: 24 additions & 0 deletions packages/client/src/actions/graph.ts
Original file line number Diff line number Diff line change
@@ -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<CreateGraphResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateGraphMutation, { request });
}
5 changes: 4 additions & 1 deletion packages/client/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -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';
30 changes: 30 additions & 0 deletions packages/client/src/actions/namespace.ts
Original file line number Diff line number Diff line change
@@ -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<CreateUsernameNamespaceResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateUsernameNamespaceMutation, { request });
}
37 changes: 37 additions & 0 deletions packages/graphql/src/feed.ts
Original file line number Diff line number Diff line change
@@ -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<typeof CreateFeedResponse>;

const CreateFeedResult = graphql(
`fragment CreateFeedResult on CreateFeedResult {
...on CreateFeedResponse {
...CreateFeedResponse
}
...on SelfFundedTransactionRequest {
...SelfFundedTransactionRequest
}
...on TransactionWillFail {
...TransactionWillFail
}
}`,
[CreateFeedResponse, SelfFundedTransactionRequest, TransactionWillFail],
);
export type CreateFeedResult = FragmentOf<typeof CreateFeedResult>;

export const CreateFeedMutation = graphql(
`mutation CreateFeed($request: CreateFeedRequest!) {
value: createFeed(request: $request) {
...CreateFeedResult
}
}`,
[CreateFeedResult],
);
export type CreateFeedRequest = RequestOf<typeof CreateFeedMutation>;
37 changes: 37 additions & 0 deletions packages/graphql/src/graph.ts
Original file line number Diff line number Diff line change
@@ -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<typeof CreateGraphResponse>;

const CreateGraphResult = graphql(
`fragment CreateGraphResult on CreateGraphResult {
...on CreateGraphResponse {
...CreateGraphResponse
}
...on SelfFundedTransactionRequest {
...SelfFundedTransactionRequest
}
...on TransactionWillFail {
...TransactionWillFail
}
}`,
[CreateGraphResponse, SelfFundedTransactionRequest, TransactionWillFail],
);
export type CreateGraphResult = FragmentOf<typeof CreateGraphResult>;

export const CreateGraphMutation = graphql(
`mutation CreateGraph($request: CreateGraphRequest!) {
value: createGraph(request: $request) {
...CreateGraphResult
}
}`,
[CreateGraphResult],
);
export type CreateGraphRequest = RequestOf<typeof CreateGraphMutation>;
3 changes: 3 additions & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
37 changes: 37 additions & 0 deletions packages/graphql/src/namespace.ts
Original file line number Diff line number Diff line change
@@ -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<typeof CreateNamespaceResponse>;

const CreateUsernameNamespaceResult = graphql(
`fragment CreateUsernameNamespaceResult on CreateUsernameNamespaceResult {
...on CreateNamespaceResponse {
...CreateNamespaceResponse
}
...on SelfFundedTransactionRequest {
...SelfFundedTransactionRequest
}
...on TransactionWillFail {
...TransactionWillFail
}
}`,
[CreateNamespaceResponse, SelfFundedTransactionRequest, TransactionWillFail],
);
export type CreateUsernameNamespaceResult = FragmentOf<typeof CreateUsernameNamespaceResult>;

export const CreateUsernameNamespaceMutation = graphql(
`mutation CreateUsernameNamespace($request: CreateUsernameNamespaceRequest!) {
value: createUsernameNamespace(request: $request) {
...CreateUsernameNamespaceResult
}
}`,
[CreateUsernameNamespaceResult],
);
export type CreateUsernameNamespaceRequest = RequestOf<typeof CreateUsernameNamespaceMutation>;

0 comments on commit d981066

Please sign in to comment.