From 86fb93f66503436c5439f76e9f2b07ad13f16c1e Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Wed, 7 May 2025 19:15:26 +0200 Subject: [PATCH] updated gql ts files --- web/src/gql/fragment-masking.ts | 87 ++++++++++++++++++++++++++ web/src/gql/gql.ts | 48 ++++++++++++++ web/src/gql/graphql.ts | 107 ++++++++++++++++++++++++++++++++ web/src/gql/index.ts | 2 + 4 files changed, 244 insertions(+) create mode 100644 web/src/gql/fragment-masking.ts create mode 100644 web/src/gql/gql.ts create mode 100644 web/src/gql/graphql.ts create mode 100644 web/src/gql/index.ts diff --git a/web/src/gql/fragment-masking.ts b/web/src/gql/fragment-masking.ts new file mode 100644 index 0000000..743a364 --- /dev/null +++ b/web/src/gql/fragment-masking.ts @@ -0,0 +1,87 @@ +/* eslint-disable */ +import type { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; +import type { FragmentDefinitionNode } from 'graphql'; +import type { Incremental } from './graphql'; + + +export type FragmentType> = TDocumentType extends DocumentTypeDecoration< + infer TType, + any +> + ? [TType] extends [{ ' $fragmentName'?: infer TKey }] + ? TKey extends string + ? { ' $fragmentRefs'?: { [key in TKey]: TType } } + : never + : never + : never; + +// return non-nullable if `fragmentType` is non-nullable +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> +): TType; +// return nullable if `fragmentType` is undefined +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | undefined +): TType | undefined; +// return nullable if `fragmentType` is nullable +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null +): TType | null; +// return nullable if `fragmentType` is nullable or undefined +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null | undefined +): TType | null | undefined; +// return array of non-nullable if `fragmentType` is array of non-nullable +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> +): Array; +// return array of nullable if `fragmentType` is array of nullable +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> | null | undefined +): Array | null | undefined; +// return readonly array of non-nullable if `fragmentType` is array of non-nullable +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> +): ReadonlyArray; +// return readonly array of nullable if `fragmentType` is array of nullable +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> | null | undefined +): ReadonlyArray | null | undefined; +export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined +): TType | Array | ReadonlyArray | null | undefined { + return fragmentType as any; +} + + +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf +>(data: FT, _fragment: F): FragmentType { + return data as FragmentType; +} +export function isFragmentReady( + queryNode: DocumentTypeDecoration, + fragmentNode: TypedDocumentNode, + data: FragmentType, any>> | null | undefined +): data is FragmentType { + const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ + ?.deferredFields; + + if (!deferredFields) return true; + + const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; + const fragName = fragDef?.name?.value; + + const fields = (fragName && deferredFields[fragName]) || []; + return fields.length > 0 && fields.every(field => data && field in data); +} diff --git a/web/src/gql/gql.ts b/web/src/gql/gql.ts new file mode 100644 index 0000000..65079e8 --- /dev/null +++ b/web/src/gql/gql.ts @@ -0,0 +1,48 @@ +/* eslint-disable */ +import * as types from './graphql'; +import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + +/** + * Map of all GraphQL operations in the project. + * + * This map has several performance disadvantages: + * 1. It is not tree-shakeable, so it will include all operations in the project. + * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle. + * 3. It does not support dead code elimination, so it will add unused operations. + * + * Therefore it is highly recommended to use the babel or swc plugin for production. + * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size + */ +const documents = { + "\n query getGame($gameID: ID!) {\n game(id: $gameID) {\n added\n overtime\n score\n author {\n ID\n name\n }\n team0player0 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team0player1 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team1player0 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team1player1 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n }\n }\n ": types.GetGameDocument, + "\n query getPlayer($playerID: ID!) {\n player(id: $playerID) {\n ID\n name\n elo\n history {\n delta\n endElo\n game {\n id\n }\n }\n }\n }\n ": types.GetPlayerDocument, +}; + +/** + * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + * + * + * @example + * ```ts + * const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`); + * ``` + * + * The query argument is unknown! + * Please regenerate the types. + */ +export function graphql(source: string): unknown; + +/** + * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + */ +export function graphql(source: "\n query getGame($gameID: ID!) {\n game(id: $gameID) {\n added\n overtime\n score\n author {\n ID\n name\n }\n team0player0 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team0player1 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team1player0 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team1player1 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n }\n }\n "): (typeof documents)["\n query getGame($gameID: ID!) {\n game(id: $gameID) {\n added\n overtime\n score\n author {\n ID\n name\n }\n team0player0 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team0player1 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team1player0 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n team1player1 {\n ID\n name\n history(game: $gameID) {\n startElo\n delta\n }\n }\n }\n }\n "]; +/** + * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + */ +export function graphql(source: "\n query getPlayer($playerID: ID!) {\n player(id: $playerID) {\n ID\n name\n elo\n history {\n delta\n endElo\n game {\n id\n }\n }\n }\n }\n "): (typeof documents)["\n query getPlayer($playerID: ID!) {\n player(id: $playerID) {\n ID\n name\n elo\n history {\n delta\n endElo\n game {\n id\n }\n }\n }\n }\n "]; + +export function graphql(source: string) { + return (documents as any)[source] ?? {}; +} + +export type DocumentType> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never; \ No newline at end of file diff --git a/web/src/gql/graphql.ts b/web/src/gql/graphql.ts new file mode 100644 index 0000000..ba80ae3 --- /dev/null +++ b/web/src/gql/graphql.ts @@ -0,0 +1,107 @@ +/* eslint-disable */ +import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +export type Maybe = T | null; +export type InputMaybe = Maybe; +export type Exact = { [K in keyof T]: T[K] }; +export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; +export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; +export type MakeEmpty = { [_ in K]?: never }; +export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +/** All built-in and custom scalars, mapped to their actual values */ +export type Scalars = { + ID: { input: string; output: string; } + String: { input: string; output: string; } + Boolean: { input: boolean; output: boolean; } + Int: { input: number; output: number; } + Float: { input: number; output: number; } + /** The `DateTime` scalar type represents a DateTime. The DateTime is serialized as an RFC 3339 quoted string */ + DateTime: { input: any; output: any; } +}; + +/** A game played */ +export type Game = { + __typename?: 'Game'; + added: Scalars['DateTime']['output']; + author: Player; + id: Scalars['ID']['output']; + overtime: Scalars['Boolean']['output']; + score: Scalars['Int']['output']; + team0player0: Player; + team0player1: Player; + team1player0: Player; + team1player1: Player; +}; + +/** The ELO change for a player in a game */ +export type GameResult = { + __typename?: 'GameResult'; + delta: Scalars['Int']['output']; + endElo: Scalars['Int']['output']; + game: Game; + id: Scalars['ID']['output']; + player?: Maybe; + startElo: Scalars['Int']['output']; +}; + +/** A player. Can also be authors of games */ +export type Player = { + __typename?: 'Player'; + ID: Scalars['ID']['output']; + elo: Scalars['Int']['output']; + games: Array>; + history: Array>; + name: Scalars['String']['output']; +}; + + +/** A player. Can also be authors of games */ +export type PlayerHistoryArgs = { + game?: InputMaybe; +}; + +export type Query = { + __typename?: 'Query'; + /** Get game by ID */ + game?: Maybe; + /** Result of a game on a players ELO */ + gameResult?: Maybe; + /** Get all games */ + games: Array>; + /** Get player by ID */ + player?: Maybe; + /** Get all players */ + players: Array>; +}; + + +export type QueryGameArgs = { + id: Scalars['ID']['input']; +}; + + +export type QueryGameResultArgs = { + id: Scalars['ID']['input']; +}; + + +export type QueryPlayerArgs = { + id: Scalars['ID']['input']; +}; + +export type GetGameQueryVariables = Exact<{ + gameID: Scalars['ID']['input']; +}>; + + +export type GetGameQuery = { __typename?: 'Query', game?: { __typename?: 'Game', added: any, overtime: boolean, score: number, author: { __typename?: 'Player', ID: string, name: string }, team0player0: { __typename?: 'Player', ID: string, name: string, history: Array<{ __typename?: 'GameResult', startElo: number, delta: number } | null> }, team0player1: { __typename?: 'Player', ID: string, name: string, history: Array<{ __typename?: 'GameResult', startElo: number, delta: number } | null> }, team1player0: { __typename?: 'Player', ID: string, name: string, history: Array<{ __typename?: 'GameResult', startElo: number, delta: number } | null> }, team1player1: { __typename?: 'Player', ID: string, name: string, history: Array<{ __typename?: 'GameResult', startElo: number, delta: number } | null> } } | null }; + +export type GetPlayerQueryVariables = Exact<{ + playerID: Scalars['ID']['input']; +}>; + + +export type GetPlayerQuery = { __typename?: 'Query', player?: { __typename?: 'Player', ID: string, name: string, elo: number, history: Array<{ __typename?: 'GameResult', delta: number, endElo: number, game: { __typename?: 'Game', id: string } } | null> } | null }; + + +export const GetGameDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"getGame"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"gameID"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"game"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"gameID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"added"}},{"kind":"Field","name":{"kind":"Name","value":"overtime"}},{"kind":"Field","name":{"kind":"Name","value":"score"}},{"kind":"Field","name":{"kind":"Name","value":"author"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"team0player0"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"history"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"game"},"value":{"kind":"Variable","name":{"kind":"Name","value":"gameID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"startElo"}},{"kind":"Field","name":{"kind":"Name","value":"delta"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"team0player1"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"history"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"game"},"value":{"kind":"Variable","name":{"kind":"Name","value":"gameID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"startElo"}},{"kind":"Field","name":{"kind":"Name","value":"delta"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"team1player0"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"history"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"game"},"value":{"kind":"Variable","name":{"kind":"Name","value":"gameID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"startElo"}},{"kind":"Field","name":{"kind":"Name","value":"delta"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"team1player1"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"history"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"game"},"value":{"kind":"Variable","name":{"kind":"Name","value":"gameID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"startElo"}},{"kind":"Field","name":{"kind":"Name","value":"delta"}}]}}]}}]}}]}}]} as unknown as DocumentNode; +export const GetPlayerDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"getPlayer"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"playerID"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"player"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"playerID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"elo"}},{"kind":"Field","name":{"kind":"Name","value":"history"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"delta"}},{"kind":"Field","name":{"kind":"Name","value":"endElo"}},{"kind":"Field","name":{"kind":"Name","value":"game"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file diff --git a/web/src/gql/index.ts b/web/src/gql/index.ts new file mode 100644 index 0000000..f515991 --- /dev/null +++ b/web/src/gql/index.ts @@ -0,0 +1,2 @@ +export * from "./fragment-masking"; +export * from "./gql"; \ No newline at end of file