Skip to content

Commit 38a2960

Browse files
committed
Stop .gitignoring generated code
1 parent 56c4308 commit 38a2960

File tree

5 files changed

+35756
-1
lines changed

5 files changed

+35756
-1
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
generated
21
node_modules
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* eslint-disable */
2+
import type {
3+
ResultOf,
4+
DocumentTypeDecoration,
5+
} from "@graphql-typed-document-node/core"
6+
import type { Incremental, TypedDocumentString } from "./graphql.ts"
7+
8+
export type FragmentType<
9+
TDocumentType extends DocumentTypeDecoration<any, any>,
10+
> =
11+
TDocumentType extends DocumentTypeDecoration<infer TType, any>
12+
? [TType] extends [{ " $fragmentName"?: infer TKey }]
13+
? TKey extends string
14+
? { " $fragmentRefs"?: { [key in TKey]: TType } }
15+
: never
16+
: never
17+
: never
18+
19+
// return non-nullable if `fragmentType` is non-nullable
20+
export function useFragment<TType>(
21+
_documentNode: DocumentTypeDecoration<TType, any>,
22+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>,
23+
): TType
24+
// return nullable if `fragmentType` is undefined
25+
export function useFragment<TType>(
26+
_documentNode: DocumentTypeDecoration<TType, any>,
27+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined,
28+
): TType | undefined
29+
// return nullable if `fragmentType` is nullable
30+
export function useFragment<TType>(
31+
_documentNode: DocumentTypeDecoration<TType, any>,
32+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null,
33+
): TType | null
34+
// return nullable if `fragmentType` is nullable or undefined
35+
export function useFragment<TType>(
36+
_documentNode: DocumentTypeDecoration<TType, any>,
37+
fragmentType:
38+
| FragmentType<DocumentTypeDecoration<TType, any>>
39+
| null
40+
| undefined,
41+
): TType | null | undefined
42+
// return array of non-nullable if `fragmentType` is array of non-nullable
43+
export function useFragment<TType>(
44+
_documentNode: DocumentTypeDecoration<TType, any>,
45+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>,
46+
): Array<TType>
47+
// return array of nullable if `fragmentType` is array of nullable
48+
export function useFragment<TType>(
49+
_documentNode: DocumentTypeDecoration<TType, any>,
50+
fragmentType:
51+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
52+
| null
53+
| undefined,
54+
): Array<TType> | null | undefined
55+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
56+
export function useFragment<TType>(
57+
_documentNode: DocumentTypeDecoration<TType, any>,
58+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>,
59+
): ReadonlyArray<TType>
60+
// return readonly array of nullable if `fragmentType` is array of nullable
61+
export function useFragment<TType>(
62+
_documentNode: DocumentTypeDecoration<TType, any>,
63+
fragmentType:
64+
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
65+
| null
66+
| undefined,
67+
): ReadonlyArray<TType> | null | undefined
68+
export function useFragment<TType>(
69+
_documentNode: DocumentTypeDecoration<TType, any>,
70+
fragmentType:
71+
| FragmentType<DocumentTypeDecoration<TType, any>>
72+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
73+
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
74+
| null
75+
| undefined,
76+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
77+
return fragmentType as any
78+
}
79+
80+
export function makeFragmentData<
81+
F extends DocumentTypeDecoration<any, any>,
82+
FT extends ResultOf<F>,
83+
>(data: FT, _fragment: F): FragmentType<F> {
84+
return data as FragmentType<F>
85+
}
86+
export function isFragmentReady<TQuery, TFrag>(
87+
queryNode: TypedDocumentString<TQuery, any>,
88+
fragmentNode: TypedDocumentString<TFrag, any>,
89+
data:
90+
| FragmentType<TypedDocumentString<Incremental<TFrag>, any>>
91+
| null
92+
| undefined,
93+
): data is FragmentType<typeof fragmentNode> {
94+
const deferredFields = queryNode.__meta__?.deferredFields as Record<
95+
string,
96+
(keyof TFrag)[]
97+
>
98+
const fragName = fragmentNode.__meta__?.fragmentName as string | undefined
99+
100+
if (!deferredFields || !fragName) return true
101+
102+
const fields = deferredFields[fragName] ?? []
103+
return fields.length > 0 && fields.every(field => data && field in data)
104+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable */
2+
import * as types from "./graphql.ts"
3+
4+
/**
5+
* Map of all GraphQL operations in the project.
6+
*
7+
* This map has several performance disadvantages:
8+
* 1. It is not tree-shakeable, so it will include all operations in the project.
9+
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
10+
* 3. It does not support dead code elimination, so it will add unused operations.
11+
*
12+
* Therefore it is highly recommended to use the babel or swc plugin for production.
13+
* Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size
14+
*/
15+
type Documents = {
16+
"\n query RepoContributors($owner: String!, $name: String!, $after: String) {\n repository(owner: $owner, name: $name) {\n defaultBranchRef {\n target {\n ... on Commit {\n history(first: 100, after: $after) {\n pageInfo {\n hasNextPage\n endCursor\n }\n nodes {\n author {\n user {\n login\n websiteUrl\n }\n }\n }\n }\n }\n }\n }\n }\n }\n": typeof types.RepoContributorsDocument
17+
}
18+
const documents: Documents = {
19+
"\n query RepoContributors($owner: String!, $name: String!, $after: String) {\n repository(owner: $owner, name: $name) {\n defaultBranchRef {\n target {\n ... on Commit {\n history(first: 100, after: $after) {\n pageInfo {\n hasNextPage\n endCursor\n }\n nodes {\n author {\n user {\n login\n websiteUrl\n }\n }\n }\n }\n }\n }\n }\n }\n }\n":
20+
types.RepoContributorsDocument,
21+
}
22+
23+
/**
24+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
25+
*/
26+
export function graphql(
27+
source: "\n query RepoContributors($owner: String!, $name: String!, $after: String) {\n repository(owner: $owner, name: $name) {\n defaultBranchRef {\n target {\n ... on Commit {\n history(first: 100, after: $after) {\n pageInfo {\n hasNextPage\n endCursor\n }\n nodes {\n author {\n user {\n login\n websiteUrl\n }\n }\n }\n }\n }\n }\n }\n }\n }\n",
28+
): typeof import("./graphql.ts").RepoContributorsDocument
29+
30+
export function graphql(source: string) {
31+
return (documents as any)[source] ?? {}
32+
}

0 commit comments

Comments
 (0)