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 fetchApp #973

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions packages/client/src/actions/app.ts
Original file line number Diff line number Diff line change
@@ -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'),
juangm marked this conversation as resolved.
Show resolved Hide resolved
* });
* ```
*
* @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<App | null, UnexpectedError> {
return client.query(AppQuery, { request });
}
1 change: 1 addition & 0 deletions packages/client/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './account';
export * from './app';
export * from './authentication';
export * from './post';
export * from './posts';
Expand Down
10 changes: 4 additions & 6 deletions packages/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions packages/graphql/src/app.ts
Original file line number Diff line number Diff line change
@@ -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<typeof AppQuery>;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export type Eip1559TransactionRequest = FragmentOf<typeof Eip1559TransactionRequ
export const SelfFundedTransactionRequest = graphql(
`fragment SelfFundedTransactionRequest on SelfFundedTransactionRequest {
__typename
encoded
reason
selfFundedReason
raw {
...Eip1559TransactionRequest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export type Eip712TransactionRequest = FragmentOf<typeof Eip712TransactionReques
export const SponsoredTransactionRequest = graphql(
`fragment SponsoredTransactionRequest on SponsoredTransactionRequest {
__typename
encoded
reason
sponsoredReason
raw {
...Eip712TransactionRequest
}
Expand Down
45 changes: 36 additions & 9 deletions packages/graphql/src/fragments/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
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<typeof AppMetadata>;

export const App = graphql(
`fragment App on App {
address
}`,
`
fragment App on App {
__typename
address
graphAddress
sponsorshipAddress
defaultFeedAddress
namespaceAddress
treasuryAddress
createdAt
metadata {
...AppMetadata
}
}
`,
[AppMetadata],
);
export type App = FragmentOf<typeof App>;

export const Feed = graphql(
`fragment Feed on Feed {
address
}`,
);
export type Feed = FragmentOf<typeof App>;
export const Feed = graphql(`
fragment Feed on Feed {
address
}
`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we attach the beginning and ending of strings with backticks to the strings so to achieve some formatting consistency?

  `fragment AppMetadata on AppMetadata {
      __typename
      description
      developer
      logo
      name
      platforms
      privacyPolicy
      termsOfService
      url
    }`
    
    ...
    
  `fragment App on App {
      __typename
      address
      graphAddress
      sponsorshipAddress
      defaultFeedAddress
      namespaceAddress
      treasuryAddress
      createdAt
      metadata {
        ...AppMetadata
      }
    }`
    
    ...
    
    `fragment Feed on Feed {
      address
    }`

4 changes: 2 additions & 2 deletions packages/graphql/src/graphql-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'; };
Expand All @@ -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; }; }; } }; }; };
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './accounts';
export * from './app';
export * from './authentication';
export * from './enums';
export * from './fragments';
Expand Down