Skip to content

Commit

Permalink
run codegen in examples
Browse files Browse the repository at this point in the history
run `yarn examples:codegen`
  • Loading branch information
tnyo43 committed Oct 15, 2023
1 parent e8c8b59 commit d79d4da
Show file tree
Hide file tree
Showing 18 changed files with 702 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core';
import { DocumentTypeDecoration } from '@graphql-typed-document-node/core';
import { Incremental, TypedDocumentString } from './graphql';

type Primitive = string | number | boolean | bigint | symbol | null | undefined;
type ExcludePrimitive<T> = Exclude<T, Primitive>;
type ExtractPrimitive<T> = Exclude<T, Exclude<T, Primitive>>;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> =
TDocumentType extends DocumentTypeDecoration<infer TType, any>
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
Expand Down Expand Up @@ -41,8 +46,39 @@ export function useFragment<TType>(
return fragmentType as any;
}

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>(
data: FT,
type UnionToIntersectGroupByTypeName<U, V = U> = [V] extends [{ __typename?: infer TypeName }]
? TypeName extends any
? UnionToIntersection<U extends { __typename?: TypeName } ? U : never>
: never
: never;

type UnionFieldToIntersection<T> = [T] extends [never]
? never
: [T] extends [Array<unknown>]
? Array<UnionFieldToIntersection<ExcludePrimitive<T[number]>> | ExtractPrimitive<T[number]>>
: UnionToIntersectGroupByTypeName<T> extends infer V
? {
[Key in keyof V]: UnionFieldToIntersection<ExcludePrimitive<V[Key]>> | ExtractPrimitive<V[Key]>;
}
: never;

type Flatten<F> = [F] extends [never]
? never
: F extends Array<unknown>
? Array<Flatten<ExcludePrimitive<F[number]>> | ExtractPrimitive<F[number]>>
: {
[Key in keyof Omit<F, ' $fragmentRefs' | ' $fragmentName'>]:
| Flatten<ExcludePrimitive<F[Key]>>
| ExtractPrimitive<F[Key]>;
} & (F extends { ' $fragmentRefs'?: { [K in string]: infer FRefs } }
? FRefs extends any
? Flatten<FRefs>
: never
: {});
export type UnmaskFragment<F> = UnionFieldToIntersection<Flatten<F>>;

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>>(
data: UnmaskFragment<FragmentType<F>>,
_fragment: F
): FragmentType<F> {
return data as FragmentType<F>;
Expand Down
42 changes: 39 additions & 3 deletions examples/persisted-documents/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { FragmentDefinitionNode } from 'graphql';
import { Incremental } from './graphql';

type Primitive = string | number | boolean | bigint | symbol | null | undefined;
type ExcludePrimitive<T> = Exclude<T, Primitive>;
type ExtractPrimitive<T> = Exclude<T, Exclude<T, Primitive>>;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> =
TDocumentType extends DocumentTypeDecoration<infer TType, any>
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
Expand Down Expand Up @@ -42,8 +47,39 @@ export function useFragment<TType>(
return fragmentType as any;
}

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>(
data: FT,
type UnionToIntersectGroupByTypeName<U, V = U> = [V] extends [{ __typename?: infer TypeName }]
? TypeName extends any
? UnionToIntersection<U extends { __typename?: TypeName } ? U : never>
: never
: never;

type UnionFieldToIntersection<T> = [T] extends [never]
? never
: [T] extends [Array<unknown>]
? Array<UnionFieldToIntersection<ExcludePrimitive<T[number]>> | ExtractPrimitive<T[number]>>
: UnionToIntersectGroupByTypeName<T> extends infer V
? {
[Key in keyof V]: UnionFieldToIntersection<ExcludePrimitive<V[Key]>> | ExtractPrimitive<V[Key]>;
}
: never;

type Flatten<F> = [F] extends [never]
? never
: F extends Array<unknown>
? Array<Flatten<ExcludePrimitive<F[number]>> | ExtractPrimitive<F[number]>>
: {
[Key in keyof Omit<F, ' $fragmentRefs' | ' $fragmentName'>]:
| Flatten<ExcludePrimitive<F[Key]>>
| ExtractPrimitive<F[Key]>;
} & (F extends { ' $fragmentRefs'?: { [K in string]: infer FRefs } }
? FRefs extends any
? Flatten<FRefs>
: never
: {});
export type UnmaskFragment<F> = UnionFieldToIntersection<Flatten<F>>;

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>>(
data: UnmaskFragment<FragmentType<F>>,
_fragment: F
): FragmentType<F> {
return data as FragmentType<F>;
Expand Down
42 changes: 39 additions & 3 deletions examples/react/apollo-client-defer/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { FragmentDefinitionNode } from 'graphql';
import { Incremental } from './graphql';

type Primitive = string | number | boolean | bigint | symbol | null | undefined;
type ExcludePrimitive<T> = Exclude<T, Primitive>;
type ExtractPrimitive<T> = Exclude<T, Exclude<T, Primitive>>;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> =
TDocumentType extends DocumentTypeDecoration<infer TType, any>
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
Expand Down Expand Up @@ -42,8 +47,39 @@ export function useFragment<TType>(
return fragmentType as any;
}

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>(
data: FT,
type UnionToIntersectGroupByTypeName<U, V = U> = [V] extends [{ __typename?: infer TypeName }]
? TypeName extends any
? UnionToIntersection<U extends { __typename?: TypeName } ? U : never>
: never
: never;

type UnionFieldToIntersection<T> = [T] extends [never]
? never
: [T] extends [Array<unknown>]
? Array<UnionFieldToIntersection<ExcludePrimitive<T[number]>> | ExtractPrimitive<T[number]>>
: UnionToIntersectGroupByTypeName<T> extends infer V
? {
[Key in keyof V]: UnionFieldToIntersection<ExcludePrimitive<V[Key]>> | ExtractPrimitive<V[Key]>;
}
: never;

type Flatten<F> = [F] extends [never]
? never
: F extends Array<unknown>
? Array<Flatten<ExcludePrimitive<F[number]>> | ExtractPrimitive<F[number]>>
: {
[Key in keyof Omit<F, ' $fragmentRefs' | ' $fragmentName'>]:
| Flatten<ExcludePrimitive<F[Key]>>
| ExtractPrimitive<F[Key]>;
} & (F extends { ' $fragmentRefs'?: { [K in string]: infer FRefs } }
? FRefs extends any
? Flatten<FRefs>
: never
: {});
export type UnmaskFragment<F> = UnionFieldToIntersection<Flatten<F>>;

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>>(
data: UnmaskFragment<FragmentType<F>>,
_fragment: F
): FragmentType<F> {
return data as FragmentType<F>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { FragmentDefinitionNode } from 'graphql';
import { Incremental } from './graphql';

type Primitive = string | number | boolean | bigint | symbol | null | undefined;
type ExcludePrimitive<T> = Exclude<T, Primitive>;
type ExtractPrimitive<T> = Exclude<T, Exclude<T, Primitive>>;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> =
TDocumentType extends DocumentTypeDecoration<infer TType, any>
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
Expand Down Expand Up @@ -42,8 +47,39 @@ export function useFragment<TType>(
return fragmentType as any;
}

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>(
data: FT,
type UnionToIntersectGroupByTypeName<U, V = U> = [V] extends [{ __typename?: infer TypeName }]
? TypeName extends any
? UnionToIntersection<U extends { __typename?: TypeName } ? U : never>
: never
: never;

type UnionFieldToIntersection<T> = [T] extends [never]
? never
: [T] extends [Array<unknown>]
? Array<UnionFieldToIntersection<ExcludePrimitive<T[number]>> | ExtractPrimitive<T[number]>>
: UnionToIntersectGroupByTypeName<T> extends infer V
? {
[Key in keyof V]: UnionFieldToIntersection<ExcludePrimitive<V[Key]>> | ExtractPrimitive<V[Key]>;
}
: never;

type Flatten<F> = [F] extends [never]
? never
: F extends Array<unknown>
? Array<Flatten<ExcludePrimitive<F[number]>> | ExtractPrimitive<F[number]>>
: {
[Key in keyof Omit<F, ' $fragmentRefs' | ' $fragmentName'>]:
| Flatten<ExcludePrimitive<F[Key]>>
| ExtractPrimitive<F[Key]>;
} & (F extends { ' $fragmentRefs'?: { [K in string]: infer FRefs } }
? FRefs extends any
? Flatten<FRefs>
: never
: {});
export type UnmaskFragment<F> = UnionFieldToIntersection<Flatten<F>>;

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>>(
data: UnmaskFragment<FragmentType<F>>,
_fragment: F
): FragmentType<F> {
return data as FragmentType<F>;
Expand Down
42 changes: 39 additions & 3 deletions examples/react/apollo-client/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { FragmentDefinitionNode } from 'graphql';
import { Incremental } from './graphql';

type Primitive = string | number | boolean | bigint | symbol | null | undefined;
type ExcludePrimitive<T> = Exclude<T, Primitive>;
type ExtractPrimitive<T> = Exclude<T, Exclude<T, Primitive>>;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> =
TDocumentType extends DocumentTypeDecoration<infer TType, any>
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
Expand Down Expand Up @@ -42,8 +47,39 @@ export function useFragment<TType>(
return fragmentType as any;
}

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>(
data: FT,
type UnionToIntersectGroupByTypeName<U, V = U> = [V] extends [{ __typename?: infer TypeName }]
? TypeName extends any
? UnionToIntersection<U extends { __typename?: TypeName } ? U : never>
: never
: never;

type UnionFieldToIntersection<T> = [T] extends [never]
? never
: [T] extends [Array<unknown>]
? Array<UnionFieldToIntersection<ExcludePrimitive<T[number]>> | ExtractPrimitive<T[number]>>
: UnionToIntersectGroupByTypeName<T> extends infer V
? {
[Key in keyof V]: UnionFieldToIntersection<ExcludePrimitive<V[Key]>> | ExtractPrimitive<V[Key]>;
}
: never;

type Flatten<F> = [F] extends [never]
? never
: F extends Array<unknown>
? Array<Flatten<ExcludePrimitive<F[number]>> | ExtractPrimitive<F[number]>>
: {
[Key in keyof Omit<F, ' $fragmentRefs' | ' $fragmentName'>]:
| Flatten<ExcludePrimitive<F[Key]>>
| ExtractPrimitive<F[Key]>;
} & (F extends { ' $fragmentRefs'?: { [K in string]: infer FRefs } }
? FRefs extends any
? Flatten<FRefs>
: never
: {});
export type UnmaskFragment<F> = UnionFieldToIntersection<Flatten<F>>;

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>>(
data: UnmaskFragment<FragmentType<F>>,
_fragment: F
): FragmentType<F> {
return data as FragmentType<F>;
Expand Down
42 changes: 39 additions & 3 deletions examples/react/http-executor/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { FragmentDefinitionNode } from 'graphql';
import { Incremental } from './graphql';

type Primitive = string | number | boolean | bigint | symbol | null | undefined;
type ExcludePrimitive<T> = Exclude<T, Primitive>;
type ExtractPrimitive<T> = Exclude<T, Exclude<T, Primitive>>;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> =
TDocumentType extends DocumentTypeDecoration<infer TType, any>
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
Expand Down Expand Up @@ -42,8 +47,39 @@ export function useFragment<TType>(
return fragmentType as any;
}

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>(
data: FT,
type UnionToIntersectGroupByTypeName<U, V = U> = [V] extends [{ __typename?: infer TypeName }]
? TypeName extends any
? UnionToIntersection<U extends { __typename?: TypeName } ? U : never>
: never
: never;

type UnionFieldToIntersection<T> = [T] extends [never]
? never
: [T] extends [Array<unknown>]
? Array<UnionFieldToIntersection<ExcludePrimitive<T[number]>> | ExtractPrimitive<T[number]>>
: UnionToIntersectGroupByTypeName<T> extends infer V
? {
[Key in keyof V]: UnionFieldToIntersection<ExcludePrimitive<V[Key]>> | ExtractPrimitive<V[Key]>;
}
: never;

type Flatten<F> = [F] extends [never]
? never
: F extends Array<unknown>
? Array<Flatten<ExcludePrimitive<F[number]>> | ExtractPrimitive<F[number]>>
: {
[Key in keyof Omit<F, ' $fragmentRefs' | ' $fragmentName'>]:
| Flatten<ExcludePrimitive<F[Key]>>
| ExtractPrimitive<F[Key]>;
} & (F extends { ' $fragmentRefs'?: { [K in string]: infer FRefs } }
? FRefs extends any
? Flatten<FRefs>
: never
: {});
export type UnmaskFragment<F> = UnionFieldToIntersection<Flatten<F>>;

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>>(
data: UnmaskFragment<FragmentType<F>>,
_fragment: F
): FragmentType<F> {
return data as FragmentType<F>;
Expand Down
42 changes: 39 additions & 3 deletions examples/react/nextjs-swr/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
import { FragmentDefinitionNode } from 'graphql';
import { Incremental } from './graphql';

type Primitive = string | number | boolean | bigint | symbol | null | undefined;
type ExcludePrimitive<T> = Exclude<T, Primitive>;
type ExtractPrimitive<T> = Exclude<T, Exclude<T, Primitive>>;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> =
TDocumentType extends DocumentTypeDecoration<infer TType, any>
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
Expand Down Expand Up @@ -42,8 +47,39 @@ export function useFragment<TType>(
return fragmentType as any;
}

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>(
data: FT,
type UnionToIntersectGroupByTypeName<U, V = U> = [V] extends [{ __typename?: infer TypeName }]
? TypeName extends any
? UnionToIntersection<U extends { __typename?: TypeName } ? U : never>
: never
: never;

type UnionFieldToIntersection<T> = [T] extends [never]
? never
: [T] extends [Array<unknown>]
? Array<UnionFieldToIntersection<ExcludePrimitive<T[number]>> | ExtractPrimitive<T[number]>>
: UnionToIntersectGroupByTypeName<T> extends infer V
? {
[Key in keyof V]: UnionFieldToIntersection<ExcludePrimitive<V[Key]>> | ExtractPrimitive<V[Key]>;
}
: never;

type Flatten<F> = [F] extends [never]
? never
: F extends Array<unknown>
? Array<Flatten<ExcludePrimitive<F[number]>> | ExtractPrimitive<F[number]>>
: {
[Key in keyof Omit<F, ' $fragmentRefs' | ' $fragmentName'>]:
| Flatten<ExcludePrimitive<F[Key]>>
| ExtractPrimitive<F[Key]>;
} & (F extends { ' $fragmentRefs'?: { [K in string]: infer FRefs } }
? FRefs extends any
? Flatten<FRefs>
: never
: {});
export type UnmaskFragment<F> = UnionFieldToIntersection<Flatten<F>>;

export function makeFragmentData<F extends DocumentTypeDecoration<any, any>>(
data: UnmaskFragment<FragmentType<F>>,
_fragment: F
): FragmentType<F> {
return data as FragmentType<F>;
Expand Down
Loading

0 comments on commit d79d4da

Please sign in to comment.