From 8817c09109f719192824c2ce9a2f4934708d6e5a Mon Sep 17 00:00:00 2001 From: Juan Garcia Date: Wed, 27 Nov 2024 18:49:47 +0100 Subject: [PATCH] Implement fetchApp (#973) * Implement fetchApp Co-authored-by: Cesare Naldi --- packages/client/src/actions/app.ts | 29 +++++++++++++++++++ packages/client/src/actions/index.ts | 1 + packages/graphql/schema.graphql | 10 +++---- packages/graphql/src/app.ts | 12 ++++++++ .../fragments/SelfFundedTransactionRequest.ts | 3 +- .../fragments/SponsoredTransactionRequest.ts | 3 +- packages/graphql/src/fragments/account.ts | 2 +- packages/graphql/src/fragments/primitives.ts | 29 +++++++++++++++++-- packages/graphql/src/graphql-env.d.ts | 4 +-- packages/graphql/src/index.ts | 1 + 10 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 packages/client/src/actions/app.ts create mode 100644 packages/graphql/src/app.ts diff --git a/packages/client/src/actions/app.ts b/packages/client/src/actions/app.ts new file mode 100644 index 000000000..7603024b6 --- /dev/null +++ b/packages/client/src/actions/app.ts @@ -0,0 +1,29 @@ +import type { App } from '@lens-protocol/graphql'; +import { AppQuery } from '@lens-protocol/graphql'; +import type { ResultAsync } from '@lens-protocol/types'; + +import type { AppRequest } from '@lens-protocol/graphql'; +import type { AnyClient, SessionClient } from '../clients'; +import type { UnexpectedError } from '../errors'; + +/** + * Fetch an App. + * + * Using a {@link SessionClient} will yield {@link App#operations} + * + * ```ts + * const result = await fetchApp(anyClient, { + * address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'), + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The App query request. + * @returns The App or `null` if it does not exist. + */ +export function fetchApp( + client: AnyClient, + request: AppRequest, +): ResultAsync { + return client.query(AppQuery, { request }); +} diff --git a/packages/client/src/actions/index.ts b/packages/client/src/actions/index.ts index c5118d9ee..e906d9a83 100644 --- a/packages/client/src/actions/index.ts +++ b/packages/client/src/actions/index.ts @@ -1,4 +1,5 @@ export * from './account'; +export * from './app'; export * from './authentication'; export * from './post'; export * from './posts'; diff --git a/packages/graphql/schema.graphql b/packages/graphql/schema.graphql index 0e1b2774d..b2bab82b5 100644 --- a/packages/graphql/schema.graphql +++ b/packages/graphql/schema.graphql @@ -3914,9 +3914,8 @@ type SelfFundedTransactionRequest { Use this object if your library does not have a parser for the encoded transaction data. """ raw: Eip1559TransactionRequest! - - """The reason for the fallback.""" - reason: SelfFundedFallbackReason + reason: String! + selfFundedReason: SelfFundedFallbackReason } input SetAccountMetadataRequest { @@ -4012,9 +4011,8 @@ type SponsoredTransactionRequest { Use this object if your library does not have a parser for the encoded transaction data. """ raw: Eip712TransactionRequest! - - """The reason for the fallback.""" - reason: SponsoredFallbackReason + reason: String! + sponsoredReason: SponsoredFallbackReason } type SponsorshipAllowance { diff --git a/packages/graphql/src/app.ts b/packages/graphql/src/app.ts new file mode 100644 index 000000000..65600fdf4 --- /dev/null +++ b/packages/graphql/src/app.ts @@ -0,0 +1,12 @@ +import { App } from './fragments'; +import { type RequestOf, graphql } from './graphql'; + +export const AppQuery = graphql( + `query App($request: AppRequest!) { + value: app(request: $request) { + ...App + } + }`, + [App], +); +export type AppRequest = RequestOf; diff --git a/packages/graphql/src/fragments/SelfFundedTransactionRequest.ts b/packages/graphql/src/fragments/SelfFundedTransactionRequest.ts index 680f62aef..2f8401986 100644 --- a/packages/graphql/src/fragments/SelfFundedTransactionRequest.ts +++ b/packages/graphql/src/fragments/SelfFundedTransactionRequest.ts @@ -21,7 +21,8 @@ export type Eip1559TransactionRequest = FragmentOf; diff --git a/packages/graphql/src/fragments/primitives.ts b/packages/graphql/src/fragments/primitives.ts index 8f93c2bb0..756d28a69 100644 --- a/packages/graphql/src/fragments/primitives.ts +++ b/packages/graphql/src/fragments/primitives.ts @@ -1,16 +1,41 @@ import type { FragmentOf } from 'gql.tada'; import { graphql } from '../graphql'; +export const AppMetadata = graphql( + `fragment AppMetadata on AppMetadata { + __typename + description + developer + logo + name + platforms + privacyPolicy + termsOfService + url + }`, +); +export type AppMetadata = FragmentOf; + export const App = graphql( `fragment App on App { + __typename address + graphAddress + sponsorshipAddress + defaultFeedAddress + namespaceAddress + treasuryAddress + createdAt + metadata { + ...AppMetadata + } }`, + [AppMetadata], ); export type App = FragmentOf; export const Feed = graphql( `fragment Feed on Feed { - address + address }`, ); -export type Feed = FragmentOf; diff --git a/packages/graphql/src/graphql-env.d.ts b/packages/graphql/src/graphql-env.d.ts index df5cd0286..c2d7435a2 100644 --- a/packages/graphql/src/graphql-env.d.ts +++ b/packages/graphql/src/graphql-env.d.ts @@ -321,7 +321,7 @@ export type introspection_types = { 'SearchPostsFilter': { kind: 'INPUT_OBJECT'; name: 'SearchPostsFilter'; isOneOf: false; inputFields: [{ name: 'postTypes'; type: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'PostType'; ofType: null; }; }; }; defaultValue: null }, { name: 'metadata'; type: { kind: 'INPUT_OBJECT'; name: 'PostMetadataFilter'; ofType: null; }; defaultValue: null }]; }; 'SearchPostsRequest': { kind: 'INPUT_OBJECT'; name: 'SearchPostsRequest'; isOneOf: false; inputFields: [{ name: 'query'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; }; defaultValue: null }, { name: 'forFeeds'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'EvmAddress'; ofType: null; }; }; }; }; defaultValue: "[\"0x83C8D9e96Da13aaD12E068F48C639C7671D2a5C7\"]" }, { name: 'filter'; type: { kind: 'INPUT_OBJECT'; name: 'SearchPostsFilter'; ofType: null; }; defaultValue: null }, { name: 'pageSize'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'PageSize'; ofType: null; }; }; defaultValue: "FIFTY" }, { name: 'cursor'; type: { kind: 'SCALAR'; name: 'Cursor'; ofType: null; }; defaultValue: null }]; }; 'SelfFundedFallbackReason': { name: 'SelfFundedFallbackReason'; enumValues: 'NOT_SPONSORED' | 'CANNOT_SPONSOR'; }; - 'SelfFundedTransactionRequest': { kind: 'OBJECT'; name: 'SelfFundedTransactionRequest'; fields: { 'raw': { name: 'raw'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'Eip1559TransactionRequest'; ofType: null; }; } }; 'reason': { name: 'reason'; type: { kind: 'ENUM'; name: 'SelfFundedFallbackReason'; ofType: null; } }; }; }; + 'SelfFundedTransactionRequest': { kind: 'OBJECT'; name: 'SelfFundedTransactionRequest'; fields: { 'raw': { name: 'raw'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'Eip1559TransactionRequest'; ofType: null; }; } }; 'reason': { name: 'reason'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'selfFundedReason': { name: 'selfFundedReason'; type: { kind: 'ENUM'; name: 'SelfFundedFallbackReason'; ofType: null; } }; }; }; 'SetAccountMetadataRequest': { kind: 'INPUT_OBJECT'; name: 'SetAccountMetadataRequest'; isOneOf: false; inputFields: [{ name: 'metadataUri'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'URI'; ofType: null; }; }; defaultValue: null }]; }; 'SetAccountMetadataResponse': { kind: 'OBJECT'; name: 'SetAccountMetadataResponse'; fields: { 'hash': { name: 'hash'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'TxHash'; ofType: null; }; } }; }; }; 'SetAccountMetadataResult': { kind: 'UNION'; name: 'SetAccountMetadataResult'; fields: {}; possibleTypes: 'SelfFundedTransactionRequest' | 'SetAccountMetadataResponse' | 'SponsoredTransactionRequest' | 'TransactionWillFail'; }; @@ -332,7 +332,7 @@ export type introspection_types = { 'SpaceMetadata': { kind: 'OBJECT'; name: 'SpaceMetadata'; fields: { 'attachments': { name: 'attachments'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'UNION'; name: 'AnyMedia'; ofType: null; }; }; }; } }; 'attributes': { name: 'attributes'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'MetadataAttribute'; ofType: null; }; }; }; } }; 'content': { name: 'content'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; }; } }; 'contentWarning': { name: 'contentWarning'; type: { kind: 'ENUM'; name: 'ContentWarning'; ofType: null; } }; 'encryptedWith': { name: 'encryptedWith'; type: { kind: 'UNION'; name: 'EncryptionStrategy'; ofType: null; } }; 'id': { name: 'id'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'MetadataId'; ofType: null; }; } }; 'link': { name: 'link'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; }; } }; 'locale': { name: 'locale'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Locale'; ofType: null; }; } }; 'mainContentFocus': { name: 'mainContentFocus'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'MainContentFocus'; ofType: null; }; } }; 'startsAt': { name: 'startsAt'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; }; } }; 'tags': { name: 'tags'; type: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Tag'; ofType: null; }; }; } }; 'title': { name: 'title'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; }; }; 'SponsorLimitType': { name: 'SponsorLimitType'; enumValues: 'HOUR' | 'DAY' | 'WEEK' | 'MONTH'; }; 'SponsoredFallbackReason': { name: 'SponsoredFallbackReason'; enumValues: 'SIGNLESS_DISABLED' | 'SIGNLESS_FAILED'; }; - 'SponsoredTransactionRequest': { kind: 'OBJECT'; name: 'SponsoredTransactionRequest'; fields: { 'raw': { name: 'raw'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'Eip712TransactionRequest'; ofType: null; }; } }; 'reason': { name: 'reason'; type: { kind: 'ENUM'; name: 'SponsoredFallbackReason'; ofType: null; } }; }; }; + 'SponsoredTransactionRequest': { kind: 'OBJECT'; name: 'SponsoredTransactionRequest'; fields: { 'raw': { name: 'raw'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'Eip712TransactionRequest'; ofType: null; }; } }; 'reason': { name: 'reason'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'sponsoredReason': { name: 'sponsoredReason'; type: { kind: 'ENUM'; name: 'SponsoredFallbackReason'; ofType: null; } }; }; }; 'SponsorshipAllowance': { kind: 'OBJECT'; name: 'SponsorshipAllowance'; fields: { 'allowance': { name: 'allowance'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; } }; 'allowanceLeft': { name: 'allowanceLeft'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; } }; 'allowanceUsed': { name: 'allowanceUsed'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; } }; 'window': { name: 'window'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'SponsorLimitType'; ofType: null; }; } }; }; }; 'StatsReactionRequest': { kind: 'INPUT_OBJECT'; name: 'StatsReactionRequest'; isOneOf: false; inputFields: [{ name: 'type'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'PostReactionType'; ofType: null; }; }; defaultValue: null }]; }; 'StoryMetadata': { kind: 'OBJECT'; name: 'StoryMetadata'; fields: { 'asset': { name: 'asset'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'UNION'; name: 'AnyMedia'; ofType: null; }; } }; 'attributes': { name: 'attributes'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'MetadataAttribute'; ofType: null; }; }; }; } }; 'content': { name: 'content'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; }; } }; 'contentWarning': { name: 'contentWarning'; type: { kind: 'ENUM'; name: 'ContentWarning'; ofType: null; } }; 'encryptedWith': { name: 'encryptedWith'; type: { kind: 'UNION'; name: 'EncryptionStrategy'; ofType: null; } }; 'id': { name: 'id'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'MetadataId'; ofType: null; }; } }; 'locale': { name: 'locale'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Locale'; ofType: null; }; } }; 'mainContentFocus': { name: 'mainContentFocus'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'MainContentFocus'; ofType: null; }; } }; 'tags': { name: 'tags'; type: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Tag'; ofType: null; }; }; } }; }; }; diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index 95ed6ddd6..b288afeee 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -1,4 +1,5 @@ export * from './accounts'; +export * from './app'; export * from './authentication'; export * from './enums'; export * from './fragments';