diff --git a/packages/client/src/actions/authentication.ts b/packages/client/src/actions/authentication.ts index 08fc62ea9..7cfba3d08 100644 --- a/packages/client/src/actions/authentication.ts +++ b/packages/client/src/actions/authentication.ts @@ -155,6 +155,6 @@ export function switchAccount( */ export function fetchMeDetails( client: SessionClient>, -): ResultAsync { +): ResultAsync, UnauthenticatedError | UnexpectedError> { return client.query(meQuery([client.context.accountFragment]), {}); } diff --git a/packages/graphql/src/accounts/account.ts b/packages/graphql/src/accounts/account.ts index d09faa95c..7caa73e58 100644 --- a/packages/graphql/src/accounts/account.ts +++ b/packages/graphql/src/accounts/account.ts @@ -222,7 +222,7 @@ export const AccountGraphsStatsQuery = graphql( export type AccountGraphsStatsRequest = RequestOf; -export const AccountsAvailableQuery = graphql( +export const AccountsAvailableQuery = dynamic( `query AccountsAvailable($request: AccountsAvailableRequest!) { value: accountsAvailable(request: $request) { items{ diff --git a/packages/graphql/src/authentication.ts b/packages/graphql/src/authentication.ts index 7ea7be5e0..6dc6e2f08 100644 --- a/packages/graphql/src/authentication.ts +++ b/packages/graphql/src/authentication.ts @@ -1,8 +1,8 @@ import type { FragmentOf } from 'gql.tada'; import { type Account, + type AccountAvailable, AccountAvailableFragment, - type FullAccount, PaginatedResultInfoFragment, } from './fragments'; import { @@ -222,24 +222,20 @@ const MeResultFragment = partial( window } loggedInAs { - ...AccountAvailable + ${'...AccountAvailable'} } }`, [AccountAvailableFragment], ); -export type MeDetails = PartialFragmentOf< +export type MeResult = PartialFragmentOf< typeof MeResultFragment, - [FragmentDocumentFor] + [FragmentDocumentFor>] >; -type test = MeDetails; - -export type MeResult = FragmentOf; - export const meQuery = dynamic( `query Me { value: me { - ...MeResult + ${'...MeResult'} } }`, [MeResultFragment], diff --git a/packages/graphql/src/fragments/account.ts b/packages/graphql/src/fragments/account.ts index 1bc188b5c..2c2074962 100644 --- a/packages/graphql/src/fragments/account.ts +++ b/packages/graphql/src/fragments/account.ts @@ -124,12 +124,12 @@ const AccountManagedFragment = partial( `fragment AccountManaged on AccountManaged { __typename addedAt - account { - ...Account - } permissions { ...AccountManagerPermissions } + account { + ...Account + } }`, [AccountManagerPermissionsFragment], ); @@ -146,8 +146,8 @@ const AccountOwnedFragment = partial( ...Account } }`, - [], ); + export type AccountOwned = PartialFragmentOf< typeof AccountOwnedFragment, [FragmentDocumentFor] diff --git a/packages/graphql/src/fragments/post.ts b/packages/graphql/src/fragments/post.ts index 958e96ac3..1a38badac 100644 --- a/packages/graphql/src/fragments/post.ts +++ b/packages/graphql/src/fragments/post.ts @@ -275,24 +275,6 @@ export const FullPostFieldsFragment = graphql( */ export type FullPostFields = FragmentOf; -export const ReferencedPostFragment = partial( - `fragment ReferencedPost on Post { - ${'...PostFields'} - - author { - ...Account - } - }`, -); - -export type ReferencedPost< - TPostFields extends PostFields = PostFields, - TAccount extends Account = Account, -> = PartialFragmentOf< - typeof ReferencedPostFragment, - [FragmentDocumentFor, FragmentDocumentFor] ->; - export const PostFragment = partial( `fragment Post on Post { ${'...PostFields'} @@ -301,16 +283,27 @@ export const PostFragment = partial( ...Account } root { - ${'...ReferencedPost'} + ${'...PostFields'} + + author { + ...Account + } } quoteOf { - ${'...ReferencedPost'} + ${'...PostFields'} + + author { + ...Account + } } commentOn { - ${'...ReferencedPost'} + ${'...PostFields'} + + author { + ...Account + } } }`, - [ReferencedPostFragment], ); export type Post< @@ -339,19 +332,33 @@ export const RepostFragment = partial( author { ...Account } + root { - ${'...ReferencedPost'} + ${'...PostFields'} + + author { + ...Account + } } quoteOf { - ${'...ReferencedPost'} + ${'...PostFields'} + + author { + ...Account + } } commentOn { - ${'...ReferencedPost'} + ${'...PostFields'} + + author { + ...Account + } } } }`, - [AppFragment, PostFragment], + [AppFragment], ); + export type Repost< TPostFields extends PostFields = PostFields, TAccount extends Account = Account, diff --git a/packages/graphql/src/graphql.ts b/packages/graphql/src/graphql.ts index f7b237be5..0ee9cd7fe 100644 --- a/packages/graphql/src/graphql.ts +++ b/packages/graphql/src/graphql.ts @@ -273,12 +273,20 @@ export type PartialFragmentOf< ? FragmentOf> : never; -export type DynamicDocument = < - DynamicFragments extends FragmentShape[], ->( +export type DynamicDocument< + In extends string = string, + StaticFragments extends FragmentShape[] = [], +> = ( dynamicFragments: DynamicFragments, ) => GetDocumentNode; +export type DynamicFragmentOf< + Document extends DynamicDocument, + DynamicFragments extends FragmentShape[], +> = Document extends DynamicDocument + ? FragmentOf> + : never; + /** * @internal */