Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed Jan 8, 2025
1 parent 430c082 commit 259d923
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/actions/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,6 @@ export function switchAccount(
*/
export function fetchMeDetails<TAccount extends Account>(
client: SessionClient<Context<TAccount>>,
): ResultAsync<MeResult, UnauthenticatedError | UnexpectedError> {
): ResultAsync<MeResult<TAccount>, UnauthenticatedError | UnexpectedError> {
return client.query(meQuery([client.context.accountFragment]), {});
}
2 changes: 1 addition & 1 deletion packages/graphql/src/accounts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const AccountGraphsStatsQuery = graphql(

export type AccountGraphsStatsRequest = RequestOf<typeof AccountGraphsStatsQuery>;

export const AccountsAvailableQuery = graphql(
export const AccountsAvailableQuery = dynamic(
`query AccountsAvailable($request: AccountsAvailableRequest!) {
value: accountsAvailable(request: $request) {
items{
Expand Down
14 changes: 5 additions & 9 deletions packages/graphql/src/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { FragmentOf } from 'gql.tada';
import {
type Account,
type AccountAvailable,
AccountAvailableFragment,
type FullAccount,
PaginatedResultInfoFragment,
} from './fragments';
import {
Expand Down Expand Up @@ -222,24 +222,20 @@ const MeResultFragment = partial(
window
}
loggedInAs {
...AccountAvailable
${'...AccountAvailable'}
}
}`,
[AccountAvailableFragment],
);
export type MeDetails<TAccount extends Account> = PartialFragmentOf<
export type MeResult<TAccount extends Account> = PartialFragmentOf<
typeof MeResultFragment,
[FragmentDocumentFor<TAccount>]
[FragmentDocumentFor<AccountAvailable<TAccount>>]
>;

type test = MeDetails<FullAccount>;

export type MeResult = FragmentOf<typeof MeResultFragment>;

export const meQuery = dynamic(
`query Me {
value: me {
...MeResult
${'...MeResult'}
}
}`,
[MeResultFragment],
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql/src/fragments/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ const AccountManagedFragment = partial(
`fragment AccountManaged on AccountManaged {
__typename
addedAt
account {
...Account
}
permissions {
...AccountManagerPermissions
}
account {
...Account
}
}`,
[AccountManagerPermissionsFragment],
);
Expand All @@ -146,8 +146,8 @@ const AccountOwnedFragment = partial(
...Account
}
}`,
[],
);

export type AccountOwned<TAccount extends Account> = PartialFragmentOf<
typeof AccountOwnedFragment,
[FragmentDocumentFor<TAccount>]
Expand Down
59 changes: 33 additions & 26 deletions packages/graphql/src/fragments/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,24 +275,6 @@ export const FullPostFieldsFragment = graphql(
*/
export type FullPostFields = FragmentOf<typeof FullPostFieldsFragment>;

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<TPostFields, 'Post', 'PostFields'>, FragmentDocumentFor<TAccount>]
>;

export const PostFragment = partial(
`fragment Post on Post {
${'...PostFields'}
Expand All @@ -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<
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 11 additions & 3 deletions packages/graphql/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,20 @@ export type PartialFragmentOf<
? FragmentOf<FragmentDocumentFrom<In, [...StaticFragments, ...DynamicFragments]>>
: never;

export type DynamicDocument<In extends string, StaticFragments extends FragmentShape[] = []> = <
DynamicFragments extends FragmentShape[],
>(
export type DynamicDocument<
In extends string = string,
StaticFragments extends FragmentShape[] = [],
> = <DynamicFragments extends FragmentShape[]>(
dynamicFragments: DynamicFragments,
) => GetDocumentNode<In, [...StaticFragments, ...DynamicFragments]>;

export type DynamicFragmentOf<
Document extends DynamicDocument,
DynamicFragments extends FragmentShape[],
> = Document extends DynamicDocument<infer In, infer StaticFragments>
? FragmentOf<FragmentDocumentFrom<In, [...StaticFragments, ...DynamicFragments]>>
: never;

/**
* @internal
*/
Expand Down

0 comments on commit 259d923

Please sign in to comment.