Skip to content
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 creation for feed/graph/namespace #1005

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 });
}
3 changes: 3 additions & 0 deletions packages/client/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ export * from './account';
export * from './admins';
export * from './app';
export * from './authentication';
export * from './feed';
export * from './follow';
export * from './graph';
export * from './namespace';
export * from './group';
export * from './post';
export * from './posts';
Expand Down
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 @@ -3,11 +3,14 @@ export * from './admins';
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 './group';
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>;
Loading