diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fff7c5f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true diff --git a/.env.local.template b/.env.local.template index a82dd7d..79ef232 100644 --- a/.env.local.template +++ b/.env.local.template @@ -4,5 +4,5 @@ AUTH0_ISSUER_BASE_URL='' AUTH0_CLIENT_ID='' AUTH0_CLIENT_SECRET='' -HASURA_GRAPHQL_URL='' +NEXT_PUBLIC_HASURA_GRAPHQL_URL='' HASURA_GRAPHQL_ADMIN_SECRET='' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fb4814..f3116ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,6 @@ jobs: uses: oven-sh/setup-bun@v1 - name: Install dependencies run: bun install - - name: Run Typecheck - run: bun run typecheck - name: Run Check run: bun run check - name: Run Test diff --git a/app/api/access-token/route.ts b/app/api/access-token/route.ts new file mode 100644 index 0000000..c6ca93f --- /dev/null +++ b/app/api/access-token/route.ts @@ -0,0 +1 @@ +export { GET } from '@/_shared/api/access-token'; diff --git a/lefthook.yml b/lefthook.yml index d84ae3b..482bdd9 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -8,4 +8,4 @@ pre-push: commands: check: glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}" - run: bun typecheck && bun test && bunx biome check --no-errors-on-unmatched --files-ignore-unknown=true {pushed_files} + run: bun type:check && bun test && bunx biome check --no-errors-on-unmatched --files-ignore-unknown=true {pushed_files} diff --git a/package.json b/package.json index d1fd2c2..1657329 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,17 @@ "test:watch": "vitest watch", "coverage": "vitest run --coverage", "fix": "run-s *:fix", - "lint:fix": "biome lint --apply-unsafe ./", "format:fix": "biome format ./ --write", - "check": "biome check ./", - "typecheck": "tsc --noEmit", + "analyzer:fix": "biome check --apply ./", + "lint:fix": "biome lint --apply-unsafe ./", + "check": "run-s *:check", + "format:check": "biome format ./", + "analyzer:check": "biome check ./", + "lint:check": "biome lint ./", + "type:check": "tsc --noEmit", "lefthook:sync": "lefthook install", "add:component": "bunx shadcn-ui@latest add", - "gql:codegen": "graphql-codegen --config ./src/_shared/lib/gql-codegen/api/config.ts && bun format:fix && bun lint:fix" + "gql:codegen": "graphql-codegen --config ./src/_shared/lib/gql-codegen/api/config.ts" }, "dependencies": { "@auth0/nextjs-auth0": "^3.5.0", diff --git a/src/_entities/darts-position/api/get-darts-positions.graphql b/src/_entities/darts-position/api/get-darts-positions.graphql deleted file mode 100644 index f540cf2..0000000 --- a/src/_entities/darts-position/api/get-darts-positions.graphql +++ /dev/null @@ -1,9 +0,0 @@ -query GetDartsPositions { - darts_positions { - id - multiplier - score - position_code - sector - } -} diff --git a/src/_entities/game/api/insert-game-session-with-throws.graphql b/src/_entities/game/api/insert-game-session-with-throws.graphql new file mode 100644 index 0000000..b79b3ef --- /dev/null +++ b/src/_entities/game/api/insert-game-session-with-throws.graphql @@ -0,0 +1,13 @@ +mutation InsertGameSessionWithThrows($gameSession: game_sessions_insert_input!) { + insert_game_sessions_one(object: $gameSession) { + game_type_id + rate_80 + rate_100 + score_summary + user_id + throws { + id + position_id + } + } +} diff --git a/src/_entities/game/api/insert-game-session-with-throws.ts b/src/_entities/game/api/insert-game-session-with-throws.ts new file mode 100644 index 0000000..236d28b --- /dev/null +++ b/src/_entities/game/api/insert-game-session-with-throws.ts @@ -0,0 +1,24 @@ +import type { DartsHitHistory } from '@/_entities/score/model/types'; +import { graphqlSdk } from '@/_shared/lib/gql-codegen'; + +type InsertGameSessionWithThrowsArgs = { + gameTypeId: number; + throws: (DartsHitHistory | undefined)[]; +}; + +export const insertGameSessionWithThrows = async ({ + gameTypeId, + throws, +}: InsertGameSessionWithThrowsArgs) => { + return graphqlSdk.InsertGameSessionWithThrows({ + gameSession: { + game_type_id: gameTypeId, + rate_80: 1, + rate_100: 1, + score_summary: '{}', + throws: { + data: throws.map(t => ({ position_id: t?.id ?? null })), + }, + }, + }); +}; diff --git a/src/_entities/score/model/types.ts b/src/_entities/score/model/types.ts index 484727d..89348d0 100644 --- a/src/_entities/score/model/types.ts +++ b/src/_entities/score/model/types.ts @@ -1,6 +1,7 @@ -import type { Darts_Positions } from '@/_shared/lib/gql-codegen/api/generated/graphql'; +import type { Darts_Positions_Max_Fields } from '@/_shared/lib/gql-codegen/api/generated/graphql'; -export type DartsPosition = Darts_Positions; +// MEMO: リレーションを取り除いた型定義を使用している +export type DartsPosition = Darts_Positions_Max_Fields; export type DartsHitHistory = DartsPosition | null; export type DartsRound = [DartsHitHistory?, DartsHitHistory?, DartsHitHistory?]; export type DartsRoundsHistory = Array; diff --git a/src/_pages/game-play/ui/screen/screen.tsx b/src/_pages/game-play/ui/screen/screen.tsx index 6d7e23f..f1dcb34 100644 --- a/src/_pages/game-play/ui/screen/screen.tsx +++ b/src/_pages/game-play/ui/screen/screen.tsx @@ -1,5 +1,6 @@ 'use client'; +import { insertGameSessionWithThrows } from '@/_entities/game/api/insert-game-session-with-throws'; import { useConnectDartsliveHome } from '@/_features/connect-dartsboard'; import { pagesPath } from '@/_shared/lib/pathpida'; import { Button } from '@/_shared/ui/button'; @@ -68,9 +69,22 @@ export default function Game() { useEffect(() => { if (Number(difficulty) <= currentSBullCount + currentDBullCount * 2) { - router.push(pagesPath.game.result.$url().pathname); + (async () => { + const response = await insertGameSessionWithThrows({ + gameTypeId: 10, + throws: dartsRoundsHistory.flat(), + }); + if (response.insert_game_sessions_one) + router.push(pagesPath.game.result.$url().pathname); + })(); } - }, [currentSBullCount, currentDBullCount, difficulty, router]); + }, [ + currentSBullCount, + currentDBullCount, + difficulty, + router, + dartsRoundsHistory, + ]); return (
diff --git a/src/_pages/home/ui/screen/screen.tsx b/src/_pages/home/ui/screen/screen.tsx index 5f1d30d..af0c094 100644 --- a/src/_pages/home/ui/screen/screen.tsx +++ b/src/_pages/home/ui/screen/screen.tsx @@ -18,6 +18,9 @@ export default function Home() { + diff --git a/src/_shared/api/access-token/api-route.ts b/src/_shared/api/access-token/api-route.ts new file mode 100644 index 0000000..04e89cd --- /dev/null +++ b/src/_shared/api/access-token/api-route.ts @@ -0,0 +1,15 @@ +import { getAccessToken } from '@auth0/nextjs-auth0'; +import { NextResponse } from 'next/server'; + +export const GET = async () => { + const { accessToken } = await getAccessToken(); + + if (accessToken === undefined) { + return NextResponse.json( + { error: 'Access token not found' }, + { status: 401 }, + ); + } + + return NextResponse.json({ accessToken }, { status: 200 }); +}; diff --git a/src/_shared/api/access-token/get-access-token.ts b/src/_shared/api/access-token/get-access-token.ts new file mode 100644 index 0000000..4de0aeb --- /dev/null +++ b/src/_shared/api/access-token/get-access-token.ts @@ -0,0 +1,24 @@ +import type { + AccessTokenResponse, + ErrorResponse, +} from '@/_shared/api/access-token/type'; + +export const getAccessToken = async (): Promise< + AccessTokenResponse | ErrorResponse +> => { + const response = await fetch('/api/access-token', { + next: { + revalidate: 60 * 60, + }, + }); + + if (response.status === 200) { + return response.json() as Promise; + } + + if (response.status === 401) { + return response.json() as Promise; + } + + return { error: 'Internal Server Error' }; +}; diff --git a/src/_shared/api/access-token/index.ts b/src/_shared/api/access-token/index.ts new file mode 100644 index 0000000..6e3031b --- /dev/null +++ b/src/_shared/api/access-token/index.ts @@ -0,0 +1,2 @@ +export { GET } from './api-route'; +export { getAccessToken } from './get-access-token'; diff --git a/src/_shared/api/access-token/type.ts b/src/_shared/api/access-token/type.ts new file mode 100644 index 0000000..0229604 --- /dev/null +++ b/src/_shared/api/access-token/type.ts @@ -0,0 +1,7 @@ +export type AccessTokenResponse = { + accessToken: string; +}; + +export type ErrorResponse = { + error: string; +}; diff --git a/src/_shared/lib/gql-codegen/api/config.ts b/src/_shared/lib/gql-codegen/api/config.ts index f5d744a..1b61a1c 100644 --- a/src/_shared/lib/gql-codegen/api/config.ts +++ b/src/_shared/lib/gql-codegen/api/config.ts @@ -2,9 +2,16 @@ import type { CodegenConfig } from '@graphql-codegen/cli'; const config: CodegenConfig = { overwrite: true, + hooks: { + afterOneFileWrite: [ + 'bun run format:fix', + 'bun run analyzer:fix', + 'bun run lint:fix', + ], + }, schema: [ { - [process.env.HASURA_GRAPHQL_URL ?? '']: { + [process.env.NEXT_PUBLIC_HASURA_GRAPHQL_URL ?? '']: { headers: { 'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET ?? '', @@ -14,7 +21,7 @@ const config: CodegenConfig = { ], documents: ['src/**/*.tsx', 'src/**/*.ts', 'src/**/*.graphql'], generates: { - 'src/shared/lib/gql-codegen/api/generated/': { + 'src/_shared/lib/gql-codegen/api/generated/': { preset: 'client', config: { gqlTagName: 'graphql', @@ -30,9 +37,15 @@ const config: CodegenConfig = { defaultScalarType: 'unknown', enumsAsTypes: true, useTypeImports: true, + scalars: { + float8: 'number', + json: 'string', + timestamptz: 'string', + uuid: 'string', + }, }, }, - 'src/shared/lib/gql-codegen/api/generated/sdk.ts': { + 'src/_shared/lib/gql-codegen/api/generated/sdk.ts': { plugins: [ { add: { diff --git a/src/_shared/lib/gql-codegen/api/generated/gql.ts b/src/_shared/lib/gql-codegen/api/generated/gql.ts index 6de70e2..a8934db 100644 --- a/src/_shared/lib/gql-codegen/api/generated/gql.ts +++ b/src/_shared/lib/gql-codegen/api/generated/gql.ts @@ -13,8 +13,8 @@ import * as types from './graphql'; * Therefore it is highly recommended to use the babel or swc plugin for production. */ const documents = { - 'query GetDartsPositions {\n darts_positions {\n id\n multiplier\n score\n position_code\n sector\n }\n}': - types.GetDartsPositionsDocument, + 'mutation InsertGameSessionWithThrows($gameSession: game_sessions_insert_input!) {\n insert_game_sessions_one(object: $gameSession) {\n game_type_id\n rate_80\n rate_100\n score_summary\n user_id\n throws {\n id\n position_id\n }\n }\n}': + types.InsertGameSessionWithThrowsDocument, }; /** @@ -35,8 +35,8 @@ 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: 'query GetDartsPositions {\n darts_positions {\n id\n multiplier\n score\n position_code\n sector\n }\n}', -): (typeof documents)['query GetDartsPositions {\n darts_positions {\n id\n multiplier\n score\n position_code\n sector\n }\n}']; + source: 'mutation InsertGameSessionWithThrows($gameSession: game_sessions_insert_input!) {\n insert_game_sessions_one(object: $gameSession) {\n game_type_id\n rate_80\n rate_100\n score_summary\n user_id\n throws {\n id\n position_id\n }\n }\n}', +): (typeof documents)['mutation InsertGameSessionWithThrows($gameSession: game_sessions_insert_input!) {\n insert_game_sessions_one(object: $gameSession) {\n game_type_id\n rate_80\n rate_100\n score_summary\n user_id\n throws {\n id\n position_id\n }\n }\n}']; export function graphql(source: string) { return (documents as any)[source] ?? {}; diff --git a/src/_shared/lib/gql-codegen/api/generated/graphql.ts b/src/_shared/lib/gql-codegen/api/generated/graphql.ts index 7422b2c..44c2a56 100644 --- a/src/_shared/lib/gql-codegen/api/generated/graphql.ts +++ b/src/_shared/lib/gql-codegen/api/generated/graphql.ts @@ -27,10 +27,9 @@ export type Scalars = { Boolean: { input: boolean; output: boolean }; Int: { input: number; output: number }; Float: { input: number; output: number }; - float8: { input: unknown; output: unknown }; - json: { input: unknown; output: unknown }; - timestamptz: { input: unknown; output: unknown }; - uuid: { input: unknown; output: unknown }; + float8: { input: number; output: number }; + json: { input: string; output: string }; + timestamptz: { input: string; output: string }; }; /** Boolean expression to compare columns of type "Int". All fields are combined with logical 'AND'. */ @@ -93,6 +92,28 @@ export type Darts_Positions = { position_code: Scalars['String']['output']; score: Scalars['Int']['output']; sector: Maybe; + /** An array relationship */ + throws: Array; + /** An aggregate relationship */ + throws_aggregate: Throws_Aggregate; +}; + +/** columns and relationships of "darts_positions" */ +export type Darts_PositionsThrowsArgs = { + distinct_on: InputMaybe>; + limit: InputMaybe; + offset: InputMaybe; + order_by: InputMaybe>; + where: InputMaybe; +}; + +/** columns and relationships of "darts_positions" */ +export type Darts_PositionsThrows_AggregateArgs = { + distinct_on: InputMaybe>; + limit: InputMaybe; + offset: InputMaybe; + order_by: InputMaybe>; + where: InputMaybe; }; /** aggregated selection of "darts_positions" */ @@ -139,6 +160,8 @@ export type Darts_Positions_Bool_Exp = { position_code?: InputMaybe; score?: InputMaybe; sector?: InputMaybe; + throws?: InputMaybe; + throws_aggregate?: InputMaybe; }; /** unique or primary key constraints on table "darts_positions" */ @@ -160,6 +183,7 @@ export type Darts_Positions_Insert_Input = { position_code?: InputMaybe; score?: InputMaybe; sector?: InputMaybe; + throws?: InputMaybe; }; /** aggregate max on columns */ @@ -188,6 +212,13 @@ export type Darts_Positions_Mutation_Response = { returning: Array; }; +/** input type for inserting object relation for remote table "darts_positions" */ +export type Darts_Positions_Obj_Rel_Insert_Input = { + data: Darts_Positions_Insert_Input; + /** upsert condition */ + on_conflict?: InputMaybe; +}; + /** on_conflict condition type for table "darts_positions" */ export type Darts_Positions_On_Conflict = { constraint: Darts_Positions_Constraint; @@ -202,6 +233,7 @@ export type Darts_Positions_Order_By = { position_code?: InputMaybe; score?: InputMaybe; sector?: InputMaybe; + throws_aggregate?: InputMaybe; }; /** primary key columns input for table: darts_positions */ @@ -341,8 +373,14 @@ export type Game_Sessions = { rate_80: Scalars['float8']['output']; rate_100: Scalars['float8']['output']; score_summary: Scalars['json']['output']; + /** An array relationship */ + throws: Array; + /** An aggregate relationship */ + throws_aggregate: Throws_Aggregate; updated_at: Scalars['timestamptz']['output']; - user_id: Scalars['uuid']['output']; + /** An object relationship */ + user: Users; + user_id: Scalars['String']['output']; }; /** columns and relationships of "game_sessions" */ @@ -350,12 +388,115 @@ export type Game_SessionsScore_SummaryArgs = { path: InputMaybe; }; +/** columns and relationships of "game_sessions" */ +export type Game_SessionsThrowsArgs = { + distinct_on: InputMaybe>; + limit: InputMaybe; + offset: InputMaybe; + order_by: InputMaybe>; + where: InputMaybe; +}; + +/** columns and relationships of "game_sessions" */ +export type Game_SessionsThrows_AggregateArgs = { + distinct_on: InputMaybe>; + limit: InputMaybe; + offset: InputMaybe; + order_by: InputMaybe>; + where: InputMaybe; +}; + /** aggregated selection of "game_sessions" */ export type Game_Sessions_Aggregate = { aggregate: Maybe; nodes: Array; }; +export type Game_Sessions_Aggregate_Bool_Exp = { + avg?: InputMaybe; + corr?: InputMaybe; + count?: InputMaybe; + covar_samp?: InputMaybe; + max?: InputMaybe; + min?: InputMaybe; + stddev_samp?: InputMaybe; + sum?: InputMaybe; + var_samp?: InputMaybe; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Avg = { + arguments: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Avg_Arguments_Columns; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Float8_Comparison_Exp; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Corr = { + arguments: Game_Sessions_Aggregate_Bool_Exp_Corr_Arguments; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Float8_Comparison_Exp; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Corr_Arguments = { + X: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Corr_Arguments_Columns; + Y: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Corr_Arguments_Columns; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Count = { + arguments?: InputMaybe>; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Int_Comparison_Exp; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Covar_Samp = { + arguments: Game_Sessions_Aggregate_Bool_Exp_Covar_Samp_Arguments; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Float8_Comparison_Exp; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Covar_Samp_Arguments = { + X: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Covar_Samp_Arguments_Columns; + Y: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Covar_Samp_Arguments_Columns; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Max = { + arguments: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Max_Arguments_Columns; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Float8_Comparison_Exp; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Min = { + arguments: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Min_Arguments_Columns; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Float8_Comparison_Exp; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Stddev_Samp = { + arguments: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Stddev_Samp_Arguments_Columns; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Float8_Comparison_Exp; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Sum = { + arguments: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Sum_Arguments_Columns; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Float8_Comparison_Exp; +}; + +export type Game_Sessions_Aggregate_Bool_Exp_Var_Samp = { + arguments: Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Var_Samp_Arguments_Columns; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Float8_Comparison_Exp; +}; + /** aggregate fields of "game_sessions" */ export type Game_Sessions_Aggregate_Fields = { avg: Maybe; @@ -377,6 +518,28 @@ export type Game_Sessions_Aggregate_FieldsCountArgs = { distinct: InputMaybe; }; +/** order by aggregate values of table "game_sessions" */ +export type Game_Sessions_Aggregate_Order_By = { + avg?: InputMaybe; + count?: InputMaybe; + max?: InputMaybe; + min?: InputMaybe; + stddev?: InputMaybe; + stddev_pop?: InputMaybe; + stddev_samp?: InputMaybe; + sum?: InputMaybe; + var_pop?: InputMaybe; + var_samp?: InputMaybe; + variance?: InputMaybe; +}; + +/** input type for inserting array relation for remote table "game_sessions" */ +export type Game_Sessions_Arr_Rel_Insert_Input = { + data: Array; + /** upsert condition */ + on_conflict?: InputMaybe; +}; + /** aggregate avg on columns */ export type Game_Sessions_Avg_Fields = { game_type_id: Maybe; @@ -385,6 +548,14 @@ export type Game_Sessions_Avg_Fields = { rate_100: Maybe; }; +/** order by avg() on columns of table "game_sessions" */ +export type Game_Sessions_Avg_Order_By = { + game_type_id?: InputMaybe; + id?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; +}; + /** Boolean expression to filter rows from the table "game_sessions". All fields are combined with a logical 'AND'. */ export type Game_Sessions_Bool_Exp = { _and?: InputMaybe>; @@ -397,16 +568,17 @@ export type Game_Sessions_Bool_Exp = { rate_80?: InputMaybe; rate_100?: InputMaybe; score_summary?: InputMaybe; + throws?: InputMaybe; + throws_aggregate?: InputMaybe; updated_at?: InputMaybe; - user_id?: InputMaybe; + user?: InputMaybe; + user_id?: InputMaybe; }; /** unique or primary key constraints on table "game_sessions" */ export type Game_Sessions_Constraint = - /** unique or primary key constraint on columns "game_type_id" */ - | 'game_sessions_game_type_id_key' /** unique or primary key constraint on columns "id" */ - | 'game_sessions_pkey'; + 'game_sessions_pkey'; /** input type for incrementing numeric columns in table "game_sessions" */ export type Game_Sessions_Inc_Input = { @@ -425,8 +597,10 @@ export type Game_Sessions_Insert_Input = { rate_80?: InputMaybe; rate_100?: InputMaybe; score_summary?: InputMaybe; + throws?: InputMaybe; updated_at?: InputMaybe; - user_id?: InputMaybe; + user?: InputMaybe; + user_id?: InputMaybe; }; /** aggregate max on columns */ @@ -438,7 +612,19 @@ export type Game_Sessions_Max_Fields = { rate_80: Maybe; rate_100: Maybe; updated_at: Maybe; - user_id: Maybe; + user_id: Maybe; +}; + +/** order by max() on columns of table "game_sessions" */ +export type Game_Sessions_Max_Order_By = { + created_at?: InputMaybe; + game_type_id?: InputMaybe; + id?: InputMaybe; + played_at?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; + updated_at?: InputMaybe; + user_id?: InputMaybe; }; /** aggregate min on columns */ @@ -450,7 +636,19 @@ export type Game_Sessions_Min_Fields = { rate_80: Maybe; rate_100: Maybe; updated_at: Maybe; - user_id: Maybe; + user_id: Maybe; +}; + +/** order by min() on columns of table "game_sessions" */ +export type Game_Sessions_Min_Order_By = { + created_at?: InputMaybe; + game_type_id?: InputMaybe; + id?: InputMaybe; + played_at?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; + updated_at?: InputMaybe; + user_id?: InputMaybe; }; /** response of any mutation on the table "game_sessions" */ @@ -461,6 +659,13 @@ export type Game_Sessions_Mutation_Response = { returning: Array; }; +/** input type for inserting object relation for remote table "game_sessions" */ +export type Game_Sessions_Obj_Rel_Insert_Input = { + data: Game_Sessions_Insert_Input; + /** upsert condition */ + on_conflict?: InputMaybe; +}; + /** on_conflict condition type for table "game_sessions" */ export type Game_Sessions_On_Conflict = { constraint: Game_Sessions_Constraint; @@ -477,7 +682,9 @@ export type Game_Sessions_Order_By = { rate_80?: InputMaybe; rate_100?: InputMaybe; score_summary?: InputMaybe; + throws_aggregate?: InputMaybe; updated_at?: InputMaybe; + user?: InputMaybe; user_id?: InputMaybe; }; @@ -507,6 +714,62 @@ export type Game_Sessions_Select_Column = /** column name */ | 'user_id'; +/** select "game_sessions_aggregate_bool_exp_avg_arguments_columns" columns of table "game_sessions" */ +export type Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Avg_Arguments_Columns = + /** column name */ + | 'rate_80' + /** column name */ + | 'rate_100'; + +/** select "game_sessions_aggregate_bool_exp_corr_arguments_columns" columns of table "game_sessions" */ +export type Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Corr_Arguments_Columns = + /** column name */ + | 'rate_80' + /** column name */ + | 'rate_100'; + +/** select "game_sessions_aggregate_bool_exp_covar_samp_arguments_columns" columns of table "game_sessions" */ +export type Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Covar_Samp_Arguments_Columns = + /** column name */ + | 'rate_80' + /** column name */ + | 'rate_100'; + +/** select "game_sessions_aggregate_bool_exp_max_arguments_columns" columns of table "game_sessions" */ +export type Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Max_Arguments_Columns = + /** column name */ + | 'rate_80' + /** column name */ + | 'rate_100'; + +/** select "game_sessions_aggregate_bool_exp_min_arguments_columns" columns of table "game_sessions" */ +export type Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Min_Arguments_Columns = + /** column name */ + | 'rate_80' + /** column name */ + | 'rate_100'; + +/** select "game_sessions_aggregate_bool_exp_stddev_samp_arguments_columns" columns of table "game_sessions" */ +export type Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Stddev_Samp_Arguments_Columns = + /** column name */ + | 'rate_80' + /** column name */ + | 'rate_100'; + +/** select "game_sessions_aggregate_bool_exp_sum_arguments_columns" columns of table "game_sessions" */ +export type Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Sum_Arguments_Columns = + /** column name */ + | 'rate_80' + /** column name */ + | 'rate_100'; + +/** select "game_sessions_aggregate_bool_exp_var_samp_arguments_columns" columns of table "game_sessions" */ +export type Game_Sessions_Select_Column_Game_Sessions_Aggregate_Bool_Exp_Var_Samp_Arguments_Columns = + /** column name */ + | 'rate_80' + /** column name */ + | 'rate_100'; + /** input type for updating data in table "game_sessions" */ export type Game_Sessions_Set_Input = { created_at?: InputMaybe; @@ -517,7 +780,7 @@ export type Game_Sessions_Set_Input = { rate_100?: InputMaybe; score_summary?: InputMaybe; updated_at?: InputMaybe; - user_id?: InputMaybe; + user_id?: InputMaybe; }; /** aggregate stddev on columns */ @@ -528,6 +791,14 @@ export type Game_Sessions_Stddev_Fields = { rate_100: Maybe; }; +/** order by stddev() on columns of table "game_sessions" */ +export type Game_Sessions_Stddev_Order_By = { + game_type_id?: InputMaybe; + id?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; +}; + /** aggregate stddev_pop on columns */ export type Game_Sessions_Stddev_Pop_Fields = { game_type_id: Maybe; @@ -536,6 +807,14 @@ export type Game_Sessions_Stddev_Pop_Fields = { rate_100: Maybe; }; +/** order by stddev_pop() on columns of table "game_sessions" */ +export type Game_Sessions_Stddev_Pop_Order_By = { + game_type_id?: InputMaybe; + id?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; +}; + /** aggregate stddev_samp on columns */ export type Game_Sessions_Stddev_Samp_Fields = { game_type_id: Maybe; @@ -544,6 +823,14 @@ export type Game_Sessions_Stddev_Samp_Fields = { rate_100: Maybe; }; +/** order by stddev_samp() on columns of table "game_sessions" */ +export type Game_Sessions_Stddev_Samp_Order_By = { + game_type_id?: InputMaybe; + id?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; +}; + /** Streaming cursor of the table "game_sessions" */ export type Game_Sessions_Stream_Cursor_Input = { /** Stream column input with initial value */ @@ -562,7 +849,7 @@ export type Game_Sessions_Stream_Cursor_Value_Input = { rate_100?: InputMaybe; score_summary?: InputMaybe; updated_at?: InputMaybe; - user_id?: InputMaybe; + user_id?: InputMaybe; }; /** aggregate sum on columns */ @@ -573,6 +860,14 @@ export type Game_Sessions_Sum_Fields = { rate_100: Maybe; }; +/** order by sum() on columns of table "game_sessions" */ +export type Game_Sessions_Sum_Order_By = { + game_type_id?: InputMaybe; + id?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; +}; + /** update columns of table "game_sessions" */ export type Game_Sessions_Update_Column = /** column name */ @@ -611,6 +906,14 @@ export type Game_Sessions_Var_Pop_Fields = { rate_100: Maybe; }; +/** order by var_pop() on columns of table "game_sessions" */ +export type Game_Sessions_Var_Pop_Order_By = { + game_type_id?: InputMaybe; + id?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; +}; + /** aggregate var_samp on columns */ export type Game_Sessions_Var_Samp_Fields = { game_type_id: Maybe; @@ -619,6 +922,14 @@ export type Game_Sessions_Var_Samp_Fields = { rate_100: Maybe; }; +/** order by var_samp() on columns of table "game_sessions" */ +export type Game_Sessions_Var_Samp_Order_By = { + game_type_id?: InputMaybe; + id?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; +}; + /** aggregate variance on columns */ export type Game_Sessions_Variance_Fields = { game_type_id: Maybe; @@ -627,6 +938,14 @@ export type Game_Sessions_Variance_Fields = { rate_100: Maybe; }; +/** order by variance() on columns of table "game_sessions" */ +export type Game_Sessions_Variance_Order_By = { + game_type_id?: InputMaybe; + id?: InputMaybe; + rate_80?: InputMaybe; + rate_100?: InputMaybe; +}; + /** columns and relationships of "game_types" */ export type Game_Types = { created_at: Scalars['timestamptz']['output']; @@ -958,7 +1277,7 @@ export type Mutation_RootDelete_UsersArgs = { /** mutation root */ export type Mutation_RootDelete_Users_By_PkArgs = { - id: Scalars['uuid']['input']; + id: Scalars['String']['input']; }; /** mutation root */ @@ -1136,9 +1455,9 @@ export type Query_Root = { darts_positions_aggregate: Darts_Positions_Aggregate; /** fetch data from the table: "darts_positions" using primary key columns */ darts_positions_by_pk: Maybe; - /** fetch data from the table: "game_sessions" */ + /** An array relationship */ game_sessions: Array; - /** fetch aggregated fields from the table: "game_sessions" */ + /** An aggregate relationship */ game_sessions_aggregate: Game_Sessions_Aggregate; /** fetch data from the table: "game_sessions" using primary key columns */ game_sessions_by_pk: Maybe; @@ -1148,9 +1467,9 @@ export type Query_Root = { game_types_aggregate: Game_Types_Aggregate; /** fetch data from the table: "game_types" using primary key columns */ game_types_by_pk: Maybe; - /** fetch data from the table: "throws" */ + /** An array relationship */ throws: Array; - /** fetch aggregated fields from the table: "throws" */ + /** An aggregate relationship */ throws_aggregate: Throws_Aggregate; /** fetch data from the table: "throws" using primary key columns */ throws_by_pk: Maybe; @@ -1259,7 +1578,7 @@ export type Query_RootUsers_AggregateArgs = { }; export type Query_RootUsers_By_PkArgs = { - id: Scalars['uuid']['input']; + id: Scalars['String']['input']; }; export type Subscription_Root = { @@ -1271,9 +1590,9 @@ export type Subscription_Root = { darts_positions_by_pk: Maybe; /** fetch data from the table in a streaming manner: "darts_positions" */ darts_positions_stream: Array; - /** fetch data from the table: "game_sessions" */ + /** An array relationship */ game_sessions: Array; - /** fetch aggregated fields from the table: "game_sessions" */ + /** An aggregate relationship */ game_sessions_aggregate: Game_Sessions_Aggregate; /** fetch data from the table: "game_sessions" using primary key columns */ game_sessions_by_pk: Maybe; @@ -1287,9 +1606,9 @@ export type Subscription_Root = { game_types_by_pk: Maybe; /** fetch data from the table in a streaming manner: "game_types" */ game_types_stream: Array; - /** fetch data from the table: "throws" */ + /** An array relationship */ throws: Array; - /** fetch aggregated fields from the table: "throws" */ + /** An aggregate relationship */ throws_aggregate: Throws_Aggregate; /** fetch data from the table: "throws" using primary key columns */ throws_by_pk: Maybe; @@ -1426,7 +1745,7 @@ export type Subscription_RootUsers_AggregateArgs = { }; export type Subscription_RootUsers_By_PkArgs = { - id: Scalars['uuid']['input']; + id: Scalars['String']['input']; }; export type Subscription_RootUsers_StreamArgs = { @@ -1438,8 +1757,12 @@ export type Subscription_RootUsers_StreamArgs = { /** columns and relationships of "throws" */ export type Throws = { created_at: Scalars['timestamptz']['output']; + /** An object relationship */ + darts_position: Maybe; + /** An object relationship */ + game_session: Game_Sessions; id: Scalars['Int']['output']; - position_id: Scalars['Int']['output']; + position_id: Maybe; session_id: Scalars['Int']['output']; updated_at: Scalars['timestamptz']['output']; }; @@ -1450,6 +1773,17 @@ export type Throws_Aggregate = { nodes: Array; }; +export type Throws_Aggregate_Bool_Exp = { + count?: InputMaybe; +}; + +export type Throws_Aggregate_Bool_Exp_Count = { + arguments?: InputMaybe>; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Int_Comparison_Exp; +}; + /** aggregate fields of "throws" */ export type Throws_Aggregate_Fields = { avg: Maybe; @@ -1471,6 +1805,28 @@ export type Throws_Aggregate_FieldsCountArgs = { distinct: InputMaybe; }; +/** order by aggregate values of table "throws" */ +export type Throws_Aggregate_Order_By = { + avg?: InputMaybe; + count?: InputMaybe; + max?: InputMaybe; + min?: InputMaybe; + stddev?: InputMaybe; + stddev_pop?: InputMaybe; + stddev_samp?: InputMaybe; + sum?: InputMaybe; + var_pop?: InputMaybe; + var_samp?: InputMaybe; + variance?: InputMaybe; +}; + +/** input type for inserting array relation for remote table "throws" */ +export type Throws_Arr_Rel_Insert_Input = { + data: Array; + /** upsert condition */ + on_conflict?: InputMaybe; +}; + /** aggregate avg on columns */ export type Throws_Avg_Fields = { id: Maybe; @@ -1478,12 +1834,21 @@ export type Throws_Avg_Fields = { session_id: Maybe; }; +/** order by avg() on columns of table "throws" */ +export type Throws_Avg_Order_By = { + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; +}; + /** Boolean expression to filter rows from the table "throws". All fields are combined with a logical 'AND'. */ export type Throws_Bool_Exp = { _and?: InputMaybe>; _not?: InputMaybe; _or?: InputMaybe>; created_at?: InputMaybe; + darts_position?: InputMaybe; + game_session?: InputMaybe; id?: InputMaybe; position_id?: InputMaybe; session_id?: InputMaybe; @@ -1505,6 +1870,8 @@ export type Throws_Inc_Input = { /** input type for inserting data into table "throws" */ export type Throws_Insert_Input = { created_at?: InputMaybe; + darts_position?: InputMaybe; + game_session?: InputMaybe; id?: InputMaybe; position_id?: InputMaybe; session_id?: InputMaybe; @@ -1520,6 +1887,15 @@ export type Throws_Max_Fields = { updated_at: Maybe; }; +/** order by max() on columns of table "throws" */ +export type Throws_Max_Order_By = { + created_at?: InputMaybe; + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; + updated_at?: InputMaybe; +}; + /** aggregate min on columns */ export type Throws_Min_Fields = { created_at: Maybe; @@ -1529,6 +1905,15 @@ export type Throws_Min_Fields = { updated_at: Maybe; }; +/** order by min() on columns of table "throws" */ +export type Throws_Min_Order_By = { + created_at?: InputMaybe; + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; + updated_at?: InputMaybe; +}; + /** response of any mutation on the table "throws" */ export type Throws_Mutation_Response = { /** number of rows affected by the mutation */ @@ -1547,6 +1932,8 @@ export type Throws_On_Conflict = { /** Ordering options when selecting data from "throws". */ export type Throws_Order_By = { created_at?: InputMaybe; + darts_position?: InputMaybe; + game_session?: InputMaybe; id?: InputMaybe; position_id?: InputMaybe; session_id?: InputMaybe; @@ -1587,6 +1974,13 @@ export type Throws_Stddev_Fields = { session_id: Maybe; }; +/** order by stddev() on columns of table "throws" */ +export type Throws_Stddev_Order_By = { + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; +}; + /** aggregate stddev_pop on columns */ export type Throws_Stddev_Pop_Fields = { id: Maybe; @@ -1594,6 +1988,13 @@ export type Throws_Stddev_Pop_Fields = { session_id: Maybe; }; +/** order by stddev_pop() on columns of table "throws" */ +export type Throws_Stddev_Pop_Order_By = { + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; +}; + /** aggregate stddev_samp on columns */ export type Throws_Stddev_Samp_Fields = { id: Maybe; @@ -1601,6 +2002,13 @@ export type Throws_Stddev_Samp_Fields = { session_id: Maybe; }; +/** order by stddev_samp() on columns of table "throws" */ +export type Throws_Stddev_Samp_Order_By = { + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; +}; + /** Streaming cursor of the table "throws" */ export type Throws_Stream_Cursor_Input = { /** Stream column input with initial value */ @@ -1625,6 +2033,13 @@ export type Throws_Sum_Fields = { session_id: Maybe; }; +/** order by sum() on columns of table "throws" */ +export type Throws_Sum_Order_By = { + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; +}; + /** update columns of table "throws" */ export type Throws_Update_Column = /** column name */ @@ -1654,6 +2069,13 @@ export type Throws_Var_Pop_Fields = { session_id: Maybe; }; +/** order by var_pop() on columns of table "throws" */ +export type Throws_Var_Pop_Order_By = { + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; +}; + /** aggregate var_samp on columns */ export type Throws_Var_Samp_Fields = { id: Maybe; @@ -1661,6 +2083,13 @@ export type Throws_Var_Samp_Fields = { session_id: Maybe; }; +/** order by var_samp() on columns of table "throws" */ +export type Throws_Var_Samp_Order_By = { + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; +}; + /** aggregate variance on columns */ export type Throws_Variance_Fields = { id: Maybe; @@ -1668,6 +2097,13 @@ export type Throws_Variance_Fields = { session_id: Maybe; }; +/** order by variance() on columns of table "throws" */ +export type Throws_Variance_Order_By = { + id?: InputMaybe; + position_id?: InputMaybe; + session_id?: InputMaybe; +}; + /** Boolean expression to compare columns of type "timestamptz". All fields are combined with logical 'AND'. */ export type Timestamptz_Comparison_Exp = { _eq?: InputMaybe; @@ -1685,12 +2121,34 @@ export type Timestamptz_Comparison_Exp = { export type Users = { created_at: Scalars['timestamptz']['output']; email: Scalars['String']['output']; - id: Scalars['uuid']['output']; + /** An array relationship */ + game_sessions: Array; + /** An aggregate relationship */ + game_sessions_aggregate: Game_Sessions_Aggregate; + id: Scalars['String']['output']; picture: Scalars['String']['output']; updated_at: Scalars['timestamptz']['output']; user_name: Scalars['String']['output']; }; +/** columns and relationships of "users" */ +export type UsersGame_SessionsArgs = { + distinct_on: InputMaybe>; + limit: InputMaybe; + offset: InputMaybe; + order_by: InputMaybe>; + where: InputMaybe; +}; + +/** columns and relationships of "users" */ +export type UsersGame_Sessions_AggregateArgs = { + distinct_on: InputMaybe>; + limit: InputMaybe; + offset: InputMaybe; + order_by: InputMaybe>; + where: InputMaybe; +}; + /** aggregated selection of "users" */ export type Users_Aggregate = { aggregate: Maybe; @@ -1717,7 +2175,9 @@ export type Users_Bool_Exp = { _or?: InputMaybe>; created_at?: InputMaybe; email?: InputMaybe; - id?: InputMaybe; + game_sessions?: InputMaybe; + game_sessions_aggregate?: InputMaybe; + id?: InputMaybe; picture?: InputMaybe; updated_at?: InputMaybe; user_name?: InputMaybe; @@ -1734,7 +2194,8 @@ export type Users_Constraint = export type Users_Insert_Input = { created_at?: InputMaybe; email?: InputMaybe; - id?: InputMaybe; + game_sessions?: InputMaybe; + id?: InputMaybe; picture?: InputMaybe; updated_at?: InputMaybe; user_name?: InputMaybe; @@ -1744,7 +2205,7 @@ export type Users_Insert_Input = { export type Users_Max_Fields = { created_at: Maybe; email: Maybe; - id: Maybe; + id: Maybe; picture: Maybe; updated_at: Maybe; user_name: Maybe; @@ -1754,7 +2215,7 @@ export type Users_Max_Fields = { export type Users_Min_Fields = { created_at: Maybe; email: Maybe; - id: Maybe; + id: Maybe; picture: Maybe; updated_at: Maybe; user_name: Maybe; @@ -1768,6 +2229,13 @@ export type Users_Mutation_Response = { returning: Array; }; +/** input type for inserting object relation for remote table "users" */ +export type Users_Obj_Rel_Insert_Input = { + data: Users_Insert_Input; + /** upsert condition */ + on_conflict?: InputMaybe; +}; + /** on_conflict condition type for table "users" */ export type Users_On_Conflict = { constraint: Users_Constraint; @@ -1779,6 +2247,7 @@ export type Users_On_Conflict = { export type Users_Order_By = { created_at?: InputMaybe; email?: InputMaybe; + game_sessions_aggregate?: InputMaybe; id?: InputMaybe; picture?: InputMaybe; updated_at?: InputMaybe; @@ -1787,7 +2256,7 @@ export type Users_Order_By = { /** primary key columns input for table: users */ export type Users_Pk_Columns_Input = { - id: Scalars['uuid']['input']; + id: Scalars['String']['input']; }; /** select columns of table "users" */ @@ -1809,7 +2278,7 @@ export type Users_Select_Column = export type Users_Set_Input = { created_at?: InputMaybe; email?: InputMaybe; - id?: InputMaybe; + id?: InputMaybe; picture?: InputMaybe; updated_at?: InputMaybe; user_name?: InputMaybe; @@ -1827,7 +2296,7 @@ export type Users_Stream_Cursor_Input = { export type Users_Stream_Cursor_Value_Input = { created_at?: InputMaybe; email?: InputMaybe; - id?: InputMaybe; + id?: InputMaybe; picture?: InputMaybe; updated_at?: InputMaybe; user_name?: InputMaybe; @@ -1855,55 +2324,88 @@ export type Users_Updates = { where: Users_Bool_Exp; }; -/** Boolean expression to compare columns of type "uuid". All fields are combined with logical 'AND'. */ -export type Uuid_Comparison_Exp = { - _eq?: InputMaybe; - _gt?: InputMaybe; - _gte?: InputMaybe; - _in?: InputMaybe>; - _is_null?: InputMaybe; - _lt?: InputMaybe; - _lte?: InputMaybe; - _neq?: InputMaybe; - _nin?: InputMaybe>; -}; - -export type GetDartsPositionsQueryVariables = Exact<{ [key: string]: never }>; +export type InsertGameSessionWithThrowsMutationVariables = Exact<{ + gameSession: Game_Sessions_Insert_Input; +}>; -export type GetDartsPositionsQuery = { - darts_positions: Array<{ - id: number; - multiplier: number; - score: number; - position_code: string; - sector: string | null; - }>; +export type InsertGameSessionWithThrowsMutation = { + insert_game_sessions_one: { + game_type_id: number; + rate_80: number; + rate_100: number; + score_summary: string; + user_id: string; + throws: Array<{ id: number; position_id: number | null }>; + } | null; }; -export const GetDartsPositionsDocument = { +export const InsertGameSessionWithThrowsDocument = { kind: 'Document', definitions: [ { kind: 'OperationDefinition', - operation: 'query', - name: { kind: 'Name', value: 'GetDartsPositions' }, + operation: 'mutation', + name: { kind: 'Name', value: 'InsertGameSessionWithThrows' }, + variableDefinitions: [ + { + kind: 'VariableDefinition', + variable: { + kind: 'Variable', + name: { kind: 'Name', value: 'gameSession' }, + }, + type: { + kind: 'NonNullType', + type: { + kind: 'NamedType', + name: { kind: 'Name', value: 'game_sessions_insert_input' }, + }, + }, + }, + ], selectionSet: { kind: 'SelectionSet', selections: [ { kind: 'Field', - name: { kind: 'Name', value: 'darts_positions' }, + name: { kind: 'Name', value: 'insert_game_sessions_one' }, + arguments: [ + { + kind: 'Argument', + name: { kind: 'Name', value: 'object' }, + value: { + kind: 'Variable', + name: { kind: 'Name', value: 'gameSession' }, + }, + }, + ], selectionSet: { kind: 'SelectionSet', selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'multiplier' } }, - { kind: 'Field', name: { kind: 'Name', value: 'score' } }, { kind: 'Field', - name: { kind: 'Name', value: 'position_code' }, + name: { kind: 'Name', value: 'game_type_id' }, + }, + { kind: 'Field', name: { kind: 'Name', value: 'rate_80' } }, + { kind: 'Field', name: { kind: 'Name', value: 'rate_100' } }, + { + kind: 'Field', + name: { kind: 'Name', value: 'score_summary' }, + }, + { kind: 'Field', name: { kind: 'Name', value: 'user_id' } }, + { + kind: 'Field', + name: { kind: 'Name', value: 'throws' }, + selectionSet: { + kind: 'SelectionSet', + selections: [ + { kind: 'Field', name: { kind: 'Name', value: 'id' } }, + { + kind: 'Field', + name: { kind: 'Name', value: 'position_id' }, + }, + ], + }, }, - { kind: 'Field', name: { kind: 'Name', value: 'sector' } }, ], }, }, @@ -1912,6 +2414,6 @@ export const GetDartsPositionsDocument = { }, ], } as unknown as DocumentNode< - GetDartsPositionsQuery, - GetDartsPositionsQueryVariables + InsertGameSessionWithThrowsMutation, + InsertGameSessionWithThrowsMutationVariables >; diff --git a/src/_shared/lib/gql-codegen/api/generated/sdk.ts b/src/_shared/lib/gql-codegen/api/generated/sdk.ts index 0f2f5cb..6051bc5 100644 --- a/src/_shared/lib/gql-codegen/api/generated/sdk.ts +++ b/src/_shared/lib/gql-codegen/api/generated/sdk.ts @@ -1,6 +1,6 @@ import type { DocumentNode } from 'graphql'; import * as Operations from './graphql'; -import type * as Type from './graphql'; +import type * as Type from './graphql.ts'; export type Requester = ( doc: DocumentNode, @@ -9,18 +9,18 @@ export type Requester = ( ) => Promise | AsyncIterable; export function getSdk(requester: Requester) { return { - GetDartsPositions( - variables?: Type.GetDartsPositionsQueryVariables, + InsertGameSessionWithThrows( + variables: Type.InsertGameSessionWithThrowsMutationVariables, options?: C, - ): Promise { + ): Promise { return requester< - Type.GetDartsPositionsQuery, - Type.GetDartsPositionsQueryVariables + Type.InsertGameSessionWithThrowsMutation, + Type.InsertGameSessionWithThrowsMutationVariables >( - Operations.GetDartsPositionsDocument, + Operations.InsertGameSessionWithThrowsDocument, variables, options, - ) as Promise; + ) as Promise; }, }; } diff --git a/src/_shared/lib/gql-codegen/api/graphql-sdk.ts b/src/_shared/lib/gql-codegen/api/graphql-sdk.ts index b41fa1a..898ccd6 100644 --- a/src/_shared/lib/gql-codegen/api/graphql-sdk.ts +++ b/src/_shared/lib/gql-codegen/api/graphql-sdk.ts @@ -1,3 +1,4 @@ +import { getAccessToken } from '@/_shared/api/access-token'; import { print } from 'graphql'; import { type Requester, getSdk } from './generated/sdk'; @@ -7,24 +8,25 @@ type RequestOptions = { tags?: string[]; }; -const endpoint = process.env.HASURA_GRAPHQL_URL; -const token = process.env.HASURA_GRAPHQL_ADMIN_SECRET; +const endpoint = process.env.NEXT_PUBLIC_HASURA_GRAPHQL_URL; const apiClient: Requester = async ( doc, variables, options?, ) => { - if (!(endpoint && token)) { - throw new Error( - 'Missing HASURA_GRAPHQL_URL or HASURA_GRAPHQL_ADMIN_SECRET', - ); + if (endpoint === undefined) { + throw new Error('HASURA_GRAPHQL_URL is not defined'); + } + + const accessTokenResponse = await getAccessToken(); + if ('error' in accessTokenResponse) { + throw new Error('Access token is not defined'); } const headers = { 'Content-Type': 'application/json', - // TODO: x-hasura-admin-secret の代わりに Authorization ヘッダを使う - 'x-hasura-admin-secret': token, + Authorization: `Bearer ${accessTokenResponse.accessToken}`, ...options?.headers, }; const revalidate = options?.revalidate ?? 0; @@ -43,15 +45,22 @@ const apiClient: Requester = async ( }, }); - if (!response.ok) { + if (response.status !== 200) { + // MEMO: GraphQL は常に200を返すので、エラーの場合はサーバー側でエラーが発生している + throw new Error(`GraphQL request failed: ${JSON.stringify(response)}`); + } + + const result = await response.json(); + + if ('errors' in result) { throw new Error( - `GraphQL Error: ${response.status} ${response.statusText}`, + result.errors.map((error: Error) => error.message).join('\n'), ); } - const data = (await response.json()).data; - return data; + + return result.data; } catch (error) { - console.error('Error in GraphQL request:', error); + console.error(error); } };