diff --git a/apps/api/src/features/auth/authApp.test.ts b/apps/api/src/features/auth/authApp.test.ts index e83ddce..0256bd2 100644 --- a/apps/api/src/features/auth/authApp.test.ts +++ b/apps/api/src/features/auth/authApp.test.ts @@ -1,6 +1,5 @@ // @vitest-environment node import { describe, expect, it, vi } from 'vitest'; -import { print, parse } from 'graphql'; import { createApp } from '../../app.js'; import { createAuthService } from './authService.js'; import type { AuthRepository } from './authRepository.js'; @@ -44,7 +43,8 @@ function setup(secure = false) { secure, ); async function request( - document: Parameters[0], + // A generated operation (typed query string) or raw query text. + document: { toString(): string }, variables: Record = {}, sentCookie = cookie, csrf = true, @@ -56,7 +56,7 @@ function setup(secure = false) { ...(csrf ? { 'X-Requested-With': 'recipe-platform' } : {}), ...(sentCookie ? { Cookie: sentCookie } : {}), }, - body: JSON.stringify({ query: print(document), variables }), + body: JSON.stringify({ query: document.toString(), variables }), }); const setCookie = response.headers.get('set-cookie'); if (setCookie) cookie = setCookie.split(';')[0]!; @@ -171,18 +171,13 @@ describe('cookie GraphQL authentication', () => { it('rejects the old token-bearing GraphQL contract', async () => { const { request } = setup(); expect( - ( - await request( - parse('query { currentUser(sessionToken: "old") { id } }'), - ) - ).errors, + (await request('query { currentUser(sessionToken: "old") { id } }')) + .errors, ).toBeDefined(); expect( ( await request( - parse( - 'mutation { login(email:"a@example.com",password:"x") { sessionToken } }', - ), + 'mutation { login(email:"a@example.com",password:"x") { sessionToken } }', ) ).errors, ).toBeDefined(); diff --git a/apps/web/index.html b/apps/web/index.html index ca7696e..f679f2c 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -3,6 +3,15 @@ + + Recipe Platform diff --git a/apps/web/package.json b/apps/web/package.json index d2cb06f..1c9618b 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -9,7 +9,6 @@ }, "dependencies": { "@t31/validation": "*", - "graphql": "16.12.0", "react": "19.2.0", "react-dom": "19.2.0", "react-easy-crop": "6.2.4", diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index f69bb52..e8041a7 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -1,18 +1,30 @@ -import { useEffect } from 'react'; +import { lazy, useEffect } from 'react'; import { useAppStore } from './store'; import { Route, Routes } from 'react-router-dom'; import AppShell from './components/shell/AppShell/AppShell'; -import LoginPage from './features/auth/LoginPage'; -import RegisterPage from './features/auth/RegisterPage'; import RequireAuth from './features/auth/RequireAuth'; import ExplorePage from './features/explore/ExplorePage'; -import CookbookPage from './features/cookbook/CookbookPage'; -import RecipeCreatePage from './features/recipes/RecipeCreatePage'; -import RecipeDetailPage from './features/recipe-detail/RecipeDetailPage'; + +/* + * Explore is the landing page and loads with the app. Other pages are split + * into their own chunks and fetched on first visit (AppShell shows a loading + * state meanwhile), so a visitor who only browses never downloads, for + * example, the image cropper used by Add Recipe. + */ +const LoginPage = lazy(() => import('./features/auth/LoginPage')); +const RegisterPage = lazy(() => import('./features/auth/RegisterPage')); +const CookbookPage = lazy(() => import('./features/cookbook/CookbookPage')); +const RecipeCreatePage = lazy( + () => import('./features/recipes/RecipeCreatePage'), +); +const RecipeDetailPage = lazy( + () => import('./features/recipe-detail/RecipeDetailPage'), +); + import NotFoundPage from './features/not-found/NotFoundPage'; import { devPagesElement } from './dev/devPagesRoute'; diff --git a/apps/web/src/components/shell/AppShell/AppShell.tsx b/apps/web/src/components/shell/AppShell/AppShell.tsx index 195600a..d5d7c9b 100644 --- a/apps/web/src/components/shell/AppShell/AppShell.tsx +++ b/apps/web/src/components/shell/AppShell/AppShell.tsx @@ -1,5 +1,7 @@ +import { Suspense } from 'react'; import { Outlet } from 'react-router-dom'; +import LoadingIndicator from '../../ui/LoadingIndicator/LoadingIndicator'; import SiteHeader from '../SiteHeader/SiteHeader'; import './AppShell.css'; @@ -8,7 +10,10 @@ function AppShell() {
- + {/* Lazily loaded pages (App.tsx) suspend here; the header stays. */} + }> + +
); diff --git a/apps/web/src/features/auth/RequireAuth.test.tsx b/apps/web/src/features/auth/RequireAuth.test.tsx index a1d760b..f2687cd 100644 --- a/apps/web/src/features/auth/RequireAuth.test.tsx +++ b/apps/web/src/features/auth/RequireAuth.test.tsx @@ -126,6 +126,8 @@ describe('protected routes with session restoration', () => { if (register) { const links = screen.getAllByRole('link', { name: 'Register' }); await interaction.click(links[links.length - 1]!); + // Register is lazy-loaded (code splitting): wait for the page itself. + await screen.findByRole('heading', { name: 'Register' }); await interaction.type(screen.getByLabelText(/^Name/), 'Hasan'); await interaction.type( screen.getByLabelText(/^Confirm password/), diff --git a/apps/web/src/features/auth/authApi.ts b/apps/web/src/features/auth/authApi.ts index 16f4e2e..a36f7d5 100644 --- a/apps/web/src/features/auth/authApi.ts +++ b/apps/web/src/features/auth/authApi.ts @@ -1,5 +1,8 @@ -import { ApiError, graphqlRequest as request } from '../../lib/graphqlClient'; -import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; +import { + ApiError, + graphqlRequest as request, + type GraphqlDocument, +} from '../../lib/graphqlClient'; import { RegisterDocument, LoginDocument, @@ -16,7 +19,7 @@ const errorMessages: Record = { RATE_LIMITED: 'Too many attempts. Please try again in a minute.', }; async function graphqlRequest( - document: TypedDocumentNode, + document: GraphqlDocument, variables: V, ): Promise { try { diff --git a/apps/web/src/features/recipes/recipeApi.ts b/apps/web/src/features/recipes/recipeApi.ts index 1e4c58b..dad8b9d 100644 --- a/apps/web/src/features/recipes/recipeApi.ts +++ b/apps/web/src/features/recipes/recipeApi.ts @@ -1,5 +1,11 @@ import { create } from 'zustand'; -import { z } from 'zod'; +/* + * Same pattern as Zod's z.uuid(), which the API uses for recipe ids. + * Checked here with a plain regex so Explore does not load Zod (~40 KB + * gzipped) just to reject malformed ids before calling the API. + */ +const UUID_PATTERN = + /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/; import { RecipesDocument, CookbookDocument, @@ -54,7 +60,7 @@ export async function listRecipes( } export async function getRecipe(id: string, signal?: AbortSignal) { - if (!z.uuid().safeParse(id).success) return null; + if (!UUID_PATTERN.test(id)) return null; const { recipe } = await graphqlRequest(RecipeDocument, { id }, signal); return recipe ? toRecipe(recipe) : null; } diff --git a/apps/web/src/lib/graphqlClient.ts b/apps/web/src/lib/graphqlClient.ts index 4583a23..b28a7ed 100644 --- a/apps/web/src/lib/graphqlClient.ts +++ b/apps/web/src/lib/graphqlClient.ts @@ -1,5 +1,13 @@ -import { print } from 'graphql'; -import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; +import type { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; + +/** + * A generated operation from contracts/generated.ts: the query text as a + * string, typed with its result (T) and variables (V). Sending the text + * directly keeps graphql-js out of the browser bundle. + */ +export type GraphqlDocument = DocumentTypeDecoration & { + toString(): string; +}; const GRAPHQL_URL = import.meta.env.DEV ? '/graphql' : '/project2/api/graphql'; @@ -13,7 +21,7 @@ export class ApiError extends Error { } export async function graphqlRequest( - document: TypedDocumentNode, + document: GraphqlDocument, variables: V, signal?: AbortSignal, ): Promise { @@ -26,7 +34,7 @@ export async function graphqlRequest( 'X-Requested-With': 'recipe-platform', }, credentials: 'same-origin', - body: JSON.stringify({ query: print(document), variables }), + body: JSON.stringify({ query: document.toString(), variables }), signal, }); } catch (error) { diff --git a/contracts/generated.ts b/contracts/generated.ts index c803e5c..e16b73a 100644 --- a/contracts/generated.ts +++ b/contracts/generated.ts @@ -7,7 +7,7 @@ export type Incremental = | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never; }; -import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import type { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; export type RecipeDifficulty = 'easy' | 'medium' | 'hard'; export type RecipeVisibility = 'public' | 'private'; @@ -400,1431 +400,464 @@ export type RemoveRecipeRatingMutationVariables = Exact<{ export type RemoveRecipeRatingMutation = { removeRecipeRating: boolean }; -export const RecipeFieldsFragmentDoc = { - kind: 'Document', - definitions: [ - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'Recipe' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'category' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cuisine' } }, - { kind: 'Field', name: { kind: 'Name', value: 'difficulty' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'sourceRecipeId' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'createdAt' } }, - { kind: 'Field', name: { kind: 'Name', value: 'updatedAt' } }, - { - 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: 'ingredients' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'amount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'unit' } }, - { kind: 'Field', name: { kind: 'Name', value: 'note' } }, - ], - }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'instructions' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'step' } }, - { kind: 'Field', name: { kind: 'Name', value: 'text' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'userRating' } }, - { kind: 'Field', name: { kind: 'Name', value: 'saveCount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const RecipeSummaryFieldsFragmentDoc = { - kind: 'Document', - definitions: [ - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeSummaryFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'RecipeSummary' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const HealthDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'query', - name: { kind: 'Name', value: 'Health' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'health' } }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const SignOutDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'SignOut' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'signOut' } }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const RegisterDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'Register' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { kind: 'Variable', name: { kind: 'Name', value: 'name' } }, - type: { - kind: 'NonNullType', - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'String' }, - }, - }, - }, - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'email' }, - }, - type: { - kind: 'NonNullType', - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'String' }, - }, - }, - }, - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'password' }, - }, - type: { - kind: 'NonNullType', - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'String' }, - }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'register' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'name' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'name' }, - }, - }, - { - kind: 'Argument', - name: { kind: 'Name', value: 'email' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'email' }, - }, - }, - { - kind: 'Argument', - name: { kind: 'Name', value: 'password' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'password' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'user' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'email' } }, - ], - }, - }, - ], - }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const LoginDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'Login' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'email' }, - }, - type: { - kind: 'NonNullType', - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'String' }, - }, - }, - }, - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'password' }, - }, - type: { - kind: 'NonNullType', - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'String' }, - }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'login' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'email' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'email' }, - }, - }, - { - kind: 'Argument', - name: { kind: 'Name', value: 'password' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'password' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'user' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'email' } }, - ], - }, - }, - ], - }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const CurrentUserDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'query', - name: { kind: 'Name', value: 'CurrentUser' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'currentUser' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'email' } }, - ], - }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const RecipesDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'query', - name: { kind: 'Name', value: 'Recipes' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'input' }, - }, - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'RecipeListInput' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'recipes' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'input' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'input' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'items' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'FragmentSpread', - name: { kind: 'Name', value: 'RecipeSummaryFields' }, - }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'totalCount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'totalPages' } }, - { kind: 'Field', name: { kind: 'Name', value: 'page' } }, - { kind: 'Field', name: { kind: 'Name', value: 'pageSize' } }, - ], - }, - }, - ], - }, - }, - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeSummaryFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'RecipeSummary' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const RecipeDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'query', - name: { kind: 'Name', value: 'Recipe' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { kind: 'Variable', name: { kind: 'Name', value: 'id' } }, - type: { - kind: 'NonNullType', - type: { kind: 'NamedType', name: { kind: 'Name', value: 'ID' } }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'recipe' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'id' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'id' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'FragmentSpread', - name: { kind: 'Name', value: 'RecipeFields' }, - }, - ], - }, - }, - ], - }, - }, - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'Recipe' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'category' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cuisine' } }, - { kind: 'Field', name: { kind: 'Name', value: 'difficulty' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'sourceRecipeId' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'createdAt' } }, - { kind: 'Field', name: { kind: 'Name', value: 'updatedAt' } }, - { - 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: 'ingredients' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'amount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'unit' } }, - { kind: 'Field', name: { kind: 'Name', value: 'note' } }, - ], - }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'instructions' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'step' } }, - { kind: 'Field', name: { kind: 'Name', value: 'text' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'userRating' } }, - { kind: 'Field', name: { kind: 'Name', value: 'saveCount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const CookbookDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'query', - name: { kind: 'Name', value: 'Cookbook' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'input' }, - }, - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'RecipeListInput' }, - }, - }, - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'scope' }, - }, - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'CookbookScope' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'cookbook' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'input' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'input' }, - }, - }, - { - kind: 'Argument', - name: { kind: 'Name', value: 'scope' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'scope' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'items' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'FragmentSpread', - name: { kind: 'Name', value: 'RecipeSummaryFields' }, - }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'totalCount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'totalPages' } }, - { kind: 'Field', name: { kind: 'Name', value: 'page' } }, - { kind: 'Field', name: { kind: 'Name', value: 'pageSize' } }, - ], - }, - }, - ], - }, - }, - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeSummaryFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'RecipeSummary' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const CreateRecipeDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'CreateRecipe' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'input' }, - }, - type: { - kind: 'NonNullType', - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'RecipeInput' }, - }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'createRecipe' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'input' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'input' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'FragmentSpread', - name: { kind: 'Name', value: 'RecipeFields' }, - }, - ], - }, - }, - ], - }, - }, - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'Recipe' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'category' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cuisine' } }, - { kind: 'Field', name: { kind: 'Name', value: 'difficulty' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'sourceRecipeId' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'createdAt' } }, - { kind: 'Field', name: { kind: 'Name', value: 'updatedAt' } }, - { - 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: 'ingredients' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'amount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'unit' } }, - { kind: 'Field', name: { kind: 'Name', value: 'note' } }, - ], - }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'instructions' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'step' } }, - { kind: 'Field', name: { kind: 'Name', value: 'text' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'userRating' } }, - { kind: 'Field', name: { kind: 'Name', value: 'saveCount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode< +export class TypedDocumentString + extends String + implements DocumentTypeDecoration +{ + __apiType?: NonNullable< + DocumentTypeDecoration['__apiType'] + >; + private value: string; + public __meta__?: Record | undefined; + + constructor(value: string, __meta__?: Record | undefined) { + super(value); + this.value = value; + this.__meta__ = __meta__; + } + + override toString(): string & DocumentTypeDecoration { + return this.value; + } +} +export const RecipeFieldsFragmentDoc = new TypedDocumentString( + ` + fragment RecipeFields on Recipe { + id + title + description + category + cuisine + difficulty + visibility + imageUrl + sourceRecipeId + prepMinutes + cookMinutes + servings + createdAt + updatedAt + author { + id + name + } + ingredients { + id + name + amount + unit + note + } + instructions { + step + text + } + tags + rating { + average + count + } + userRating + saveCount + isSaved + isCreatedByCurrentUser +} + `, + { fragmentName: 'RecipeFields' }, +) as unknown as TypedDocumentString; +export const RecipeSummaryFieldsFragmentDoc = new TypedDocumentString( + ` + fragment RecipeSummaryFields on RecipeSummary { + id + title + description + visibility + imageUrl + prepMinutes + cookMinutes + servings + tags + rating { + average + count + } + isSaved + isCreatedByCurrentUser +} + `, + { fragmentName: 'RecipeSummaryFields' }, +) as unknown as TypedDocumentString; +export const HealthDocument = new TypedDocumentString(` + query Health { + health +} + `) as unknown as TypedDocumentString; +export const SignOutDocument = new TypedDocumentString(` + mutation SignOut { + signOut +} + `) as unknown as TypedDocumentString< + SignOutMutation, + SignOutMutationVariables +>; +export const RegisterDocument = new TypedDocumentString(` + mutation Register($name: String!, $email: String!, $password: String!) { + register(name: $name, email: $email, password: $password) { + user { + id + name + email + } + } +} + `) as unknown as TypedDocumentString< + RegisterMutation, + RegisterMutationVariables +>; +export const LoginDocument = new TypedDocumentString(` + mutation Login($email: String!, $password: String!) { + login(email: $email, password: $password) { + user { + id + name + email + } + } +} + `) as unknown as TypedDocumentString; +export const CurrentUserDocument = new TypedDocumentString(` + query CurrentUser { + currentUser { + id + name + email + } +} + `) as unknown as TypedDocumentString< + CurrentUserQuery, + CurrentUserQueryVariables +>; +export const RecipesDocument = new TypedDocumentString(` + query Recipes($input: RecipeListInput) { + recipes(input: $input) { + items { + ...RecipeSummaryFields + } + totalCount + totalPages + page + pageSize + } +} + fragment RecipeSummaryFields on RecipeSummary { + id + title + description + visibility + imageUrl + prepMinutes + cookMinutes + servings + tags + rating { + average + count + } + isSaved + isCreatedByCurrentUser +}`) as unknown as TypedDocumentString; +export const RecipeDocument = new TypedDocumentString(` + query Recipe($id: ID!) { + recipe(id: $id) { + ...RecipeFields + } +} + fragment RecipeFields on Recipe { + id + title + description + category + cuisine + difficulty + visibility + imageUrl + sourceRecipeId + prepMinutes + cookMinutes + servings + createdAt + updatedAt + author { + id + name + } + ingredients { + id + name + amount + unit + note + } + instructions { + step + text + } + tags + rating { + average + count + } + userRating + saveCount + isSaved + isCreatedByCurrentUser +}`) as unknown as TypedDocumentString; +export const CookbookDocument = new TypedDocumentString(` + query Cookbook($input: RecipeListInput, $scope: CookbookScope) { + cookbook(input: $input, scope: $scope) { + items { + ...RecipeSummaryFields + } + totalCount + totalPages + page + pageSize + } +} + fragment RecipeSummaryFields on RecipeSummary { + id + title + description + visibility + imageUrl + prepMinutes + cookMinutes + servings + tags + rating { + average + count + } + isSaved + isCreatedByCurrentUser +}`) as unknown as TypedDocumentString; +export const CreateRecipeDocument = new TypedDocumentString(` + mutation CreateRecipe($input: RecipeInput!) { + createRecipe(input: $input) { + ...RecipeFields + } +} + fragment RecipeFields on Recipe { + id + title + description + category + cuisine + difficulty + visibility + imageUrl + sourceRecipeId + prepMinutes + cookMinutes + servings + createdAt + updatedAt + author { + id + name + } + ingredients { + id + name + amount + unit + note + } + instructions { + step + text + } + tags + rating { + average + count + } + userRating + saveCount + isSaved + isCreatedByCurrentUser +}`) as unknown as TypedDocumentString< CreateRecipeMutation, CreateRecipeMutationVariables >; -export const UpdateRecipeDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'UpdateRecipe' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { kind: 'Variable', name: { kind: 'Name', value: 'id' } }, - type: { - kind: 'NonNullType', - type: { kind: 'NamedType', name: { kind: 'Name', value: 'ID' } }, - }, - }, - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'input' }, - }, - type: { - kind: 'NonNullType', - type: { - kind: 'NamedType', - name: { kind: 'Name', value: 'RecipeInput' }, - }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'updateRecipe' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'id' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'id' }, - }, - }, - { - kind: 'Argument', - name: { kind: 'Name', value: 'input' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'input' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'FragmentSpread', - name: { kind: 'Name', value: 'RecipeFields' }, - }, - ], - }, - }, - ], - }, - }, - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'Recipe' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'category' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cuisine' } }, - { kind: 'Field', name: { kind: 'Name', value: 'difficulty' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'sourceRecipeId' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'createdAt' } }, - { kind: 'Field', name: { kind: 'Name', value: 'updatedAt' } }, - { - 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: 'ingredients' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'amount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'unit' } }, - { kind: 'Field', name: { kind: 'Name', value: 'note' } }, - ], - }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'instructions' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'step' } }, - { kind: 'Field', name: { kind: 'Name', value: 'text' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'userRating' } }, - { kind: 'Field', name: { kind: 'Name', value: 'saveCount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode< +export const UpdateRecipeDocument = new TypedDocumentString(` + mutation UpdateRecipe($id: ID!, $input: RecipeInput!) { + updateRecipe(id: $id, input: $input) { + ...RecipeFields + } +} + fragment RecipeFields on Recipe { + id + title + description + category + cuisine + difficulty + visibility + imageUrl + sourceRecipeId + prepMinutes + cookMinutes + servings + createdAt + updatedAt + author { + id + name + } + ingredients { + id + name + amount + unit + note + } + instructions { + step + text + } + tags + rating { + average + count + } + userRating + saveCount + isSaved + isCreatedByCurrentUser +}`) as unknown as TypedDocumentString< UpdateRecipeMutation, UpdateRecipeMutationVariables >; -export const DeleteRecipeDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'DeleteRecipe' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { kind: 'Variable', name: { kind: 'Name', value: 'id' } }, - type: { - kind: 'NonNullType', - type: { kind: 'NamedType', name: { kind: 'Name', value: 'ID' } }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'deleteRecipe' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'id' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'id' }, - }, - }, - ], - }, - ], - }, - }, - ], -} as unknown as DocumentNode< +export const DeleteRecipeDocument = new TypedDocumentString(` + mutation DeleteRecipe($id: ID!) { + deleteRecipe(id: $id) +} + `) as unknown as TypedDocumentString< DeleteRecipeMutation, DeleteRecipeMutationVariables >; -export const SaveRecipeDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'SaveRecipe' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { kind: 'Variable', name: { kind: 'Name', value: 'id' } }, - type: { - kind: 'NonNullType', - type: { kind: 'NamedType', name: { kind: 'Name', value: 'ID' } }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'saveRecipe' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'id' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'id' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'FragmentSpread', - name: { kind: 'Name', value: 'RecipeFields' }, - }, - ], - }, - }, - ], - }, - }, - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'Recipe' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'category' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cuisine' } }, - { kind: 'Field', name: { kind: 'Name', value: 'difficulty' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'sourceRecipeId' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'createdAt' } }, - { kind: 'Field', name: { kind: 'Name', value: 'updatedAt' } }, - { - 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: 'ingredients' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'amount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'unit' } }, - { kind: 'Field', name: { kind: 'Name', value: 'note' } }, - ], - }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'instructions' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'step' } }, - { kind: 'Field', name: { kind: 'Name', value: 'text' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'userRating' } }, - { kind: 'Field', name: { kind: 'Name', value: 'saveCount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const UnsaveRecipeDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'UnsaveRecipe' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { kind: 'Variable', name: { kind: 'Name', value: 'id' } }, - type: { - kind: 'NonNullType', - type: { kind: 'NamedType', name: { kind: 'Name', value: 'ID' } }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'unsaveRecipe' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'id' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'id' }, - }, - }, - ], - }, - ], - }, - }, - ], -} as unknown as DocumentNode< +export const SaveRecipeDocument = new TypedDocumentString(` + mutation SaveRecipe($id: ID!) { + saveRecipe(id: $id) { + ...RecipeFields + } +} + fragment RecipeFields on Recipe { + id + title + description + category + cuisine + difficulty + visibility + imageUrl + sourceRecipeId + prepMinutes + cookMinutes + servings + createdAt + updatedAt + author { + id + name + } + ingredients { + id + name + amount + unit + note + } + instructions { + step + text + } + tags + rating { + average + count + } + userRating + saveCount + isSaved + isCreatedByCurrentUser +}`) as unknown as TypedDocumentString< + SaveRecipeMutation, + SaveRecipeMutationVariables +>; +export const UnsaveRecipeDocument = new TypedDocumentString(` + mutation UnsaveRecipe($id: ID!) { + unsaveRecipe(id: $id) +} + `) as unknown as TypedDocumentString< UnsaveRecipeMutation, UnsaveRecipeMutationVariables >; -export const RateRecipeDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'RateRecipe' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { kind: 'Variable', name: { kind: 'Name', value: 'id' } }, - type: { - kind: 'NonNullType', - type: { kind: 'NamedType', name: { kind: 'Name', value: 'ID' } }, - }, - }, - { - kind: 'VariableDefinition', - variable: { - kind: 'Variable', - name: { kind: 'Name', value: 'score' }, - }, - type: { - kind: 'NonNullType', - type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'rateRecipe' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'id' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'id' }, - }, - }, - { - kind: 'Argument', - name: { kind: 'Name', value: 'score' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'score' }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'FragmentSpread', - name: { kind: 'Name', value: 'RecipeFields' }, - }, - ], - }, - }, - ], - }, - }, - { - kind: 'FragmentDefinition', - name: { kind: 'Name', value: 'RecipeFields' }, - typeCondition: { - kind: 'NamedType', - name: { kind: 'Name', value: 'Recipe' }, - }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'title' } }, - { kind: 'Field', name: { kind: 'Name', value: 'description' } }, - { kind: 'Field', name: { kind: 'Name', value: 'category' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cuisine' } }, - { kind: 'Field', name: { kind: 'Name', value: 'difficulty' } }, - { kind: 'Field', name: { kind: 'Name', value: 'visibility' } }, - { kind: 'Field', name: { kind: 'Name', value: 'imageUrl' } }, - { kind: 'Field', name: { kind: 'Name', value: 'sourceRecipeId' } }, - { kind: 'Field', name: { kind: 'Name', value: 'prepMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'cookMinutes' } }, - { kind: 'Field', name: { kind: 'Name', value: 'servings' } }, - { kind: 'Field', name: { kind: 'Name', value: 'createdAt' } }, - { kind: 'Field', name: { kind: 'Name', value: 'updatedAt' } }, - { - 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: 'ingredients' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'id' } }, - { kind: 'Field', name: { kind: 'Name', value: 'name' } }, - { kind: 'Field', name: { kind: 'Name', value: 'amount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'unit' } }, - { kind: 'Field', name: { kind: 'Name', value: 'note' } }, - ], - }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'instructions' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'step' } }, - { kind: 'Field', name: { kind: 'Name', value: 'text' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'tags' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rating' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { kind: 'Field', name: { kind: 'Name', value: 'average' } }, - { kind: 'Field', name: { kind: 'Name', value: 'count' } }, - ], - }, - }, - { kind: 'Field', name: { kind: 'Name', value: 'userRating' } }, - { kind: 'Field', name: { kind: 'Name', value: 'saveCount' } }, - { kind: 'Field', name: { kind: 'Name', value: 'isSaved' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'isCreatedByCurrentUser' }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode; -export const RemoveRecipeRatingDocument = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'mutation', - name: { kind: 'Name', value: 'RemoveRecipeRating' }, - variableDefinitions: [ - { - kind: 'VariableDefinition', - variable: { kind: 'Variable', name: { kind: 'Name', value: 'id' } }, - type: { - kind: 'NonNullType', - type: { kind: 'NamedType', name: { kind: 'Name', value: 'ID' } }, - }, - }, - ], - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'removeRecipeRating' }, - arguments: [ - { - kind: 'Argument', - name: { kind: 'Name', value: 'id' }, - value: { - kind: 'Variable', - name: { kind: 'Name', value: 'id' }, - }, - }, - ], - }, - ], - }, - }, - ], -} as unknown as DocumentNode< +export const RateRecipeDocument = new TypedDocumentString(` + mutation RateRecipe($id: ID!, $score: Int!) { + rateRecipe(id: $id, score: $score) { + ...RecipeFields + } +} + fragment RecipeFields on Recipe { + id + title + description + category + cuisine + difficulty + visibility + imageUrl + sourceRecipeId + prepMinutes + cookMinutes + servings + createdAt + updatedAt + author { + id + name + } + ingredients { + id + name + amount + unit + note + } + instructions { + step + text + } + tags + rating { + average + count + } + userRating + saveCount + isSaved + isCreatedByCurrentUser +}`) as unknown as TypedDocumentString< + RateRecipeMutation, + RateRecipeMutationVariables +>; +export const RemoveRecipeRatingDocument = new TypedDocumentString(` + mutation RemoveRecipeRating($id: ID!) { + removeRecipeRating(id: $id) +} + `) as unknown as TypedDocumentString< RemoveRecipeRatingMutation, RemoveRecipeRatingMutationVariables >; diff --git a/docs/performance-and-images.md b/docs/performance-and-images.md index 61d2f55..7c813cc 100644 --- a/docs/performance-and-images.md +++ b/docs/performance-and-images.md @@ -55,6 +55,24 @@ bildet på nytt. Asset-reglene står i `deploy/apache.conf` og krever `mod_headers` (`sudo a2enmod headers`). Filen må legges inn i Apache på VM-en manuelt. +## JavaScript-pakker + +Explore er landingssiden og lastes sammen med appen. Øvrige sider (innlogging, +registrering, kokebok, detaljside og oppskriftsskjema) deles i egne filer med +`React.lazy` og hentes først når de besøkes. GraphQL-operasjonene genereres som +ferdige spørrestrenger (`documentMode: 'string'`), slik at nettleseren ikke +trenger graphql-js for å sende dem. Zod lastes bare på sidene som validerer +skjemaer. + +| Måling (produksjonsbygg, gzip) | Før | Etter | +| -------------------------------- | -------- | ------- | +| JavaScript før Explore vises | 131,8 kB | 90,1 kB | +| Oppskriftsskjema (egen fil) | – | 13,0 kB | +| Innlogging/registrering (felles) | – | 23,1 kB | + +Tallene er fra `npm run build`. De måler overført filstørrelse, ikke lastetid +eller energibruk. + ## Bilder og bærekraft - **Serverside behandling:** API-et behandler alle opplastede bilder med diff --git a/docs/recipe-api.md b/docs/recipe-api.md index cb939bb..613a879 100644 --- a/docs/recipe-api.md +++ b/docs/recipe-api.md @@ -37,7 +37,6 @@ klienten `apps/web/src/lib/graphqlClient.ts`. Eksempelet under viser transporten Samme URL, headere og cookie-innstilling brukes for de øvrige operasjonene. ```ts -import { print } from 'graphql'; import { CreateRecipeDocument, type CreateRecipeMutation, @@ -56,7 +55,11 @@ export async function createRecipe( 'Content-Type': 'application/json', 'X-Requested-With': 'recipe-platform', }, - body: JSON.stringify({ query: print(CreateRecipeDocument), variables }), + // Dokumentene er strenger (TypedDocumentString), ikke AST-er. + body: JSON.stringify({ + query: CreateRecipeDocument.toString(), + variables, + }), }); if (!response.ok) throw new Error('Kunne ikke kontakte API-et.'); diff --git a/e2e/smoke.spec.ts b/e2e/smoke.spec.ts index ca150f9..7ea6b98 100644 --- a/e2e/smoke.spec.ts +++ b/e2e/smoke.spec.ts @@ -256,6 +256,20 @@ test('icons stay within their controls on desktop and mobile', async ({ } }); +test('keeps component styles above the CSS reset on code-split pages', async ({ + page, +}) => { + // Login loads as its own chunk. If its CSS were linked before the main + // stylesheet without the layer order in index.html, the reset's + // `button { color: inherit }` would win and primary buttons lose their + // white text. + await page.goto('login'); + await expect(page.getByRole('heading', { name: 'Log in' })).toBeVisible(); + await expect( + page.locator('form').getByRole('button', { name: 'Log in' }), + ).toHaveCSS('color', 'rgb(255, 255, 255)'); +}); + test('clicking anywhere on a recipe card, including its image, opens the recipe', async ({ page, }) => { diff --git a/package-lock.json b/package-lock.json index e550695..524be12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -69,7 +69,6 @@ "name": "@t31/web", "dependencies": { "@t31/validation": "*", - "graphql": "16.12.0", "react": "19.2.0", "react-dom": "19.2.0", "react-easy-crop": "6.2.4", diff --git a/scripts/generate-api.ts b/scripts/generate-api.ts index 0084dc0..3e2b4c7 100644 --- a/scripts/generate-api.ts +++ b/scripts/generate-api.ts @@ -21,7 +21,13 @@ const targets = [ filename: 'contracts/generated.ts', // typescript-operations v6 also emits the used input types. plugins: [{ operations: {} }, { typedDocument: {} }], - config: { useTypeImports: true, enumsAsTypes: true }, + // String documents carry the query text, so the browser can send them + // without graphql-js's print() and its ~40 KB of parser/printer code. + config: { + useTypeImports: true, + enumsAsTypes: true, + documentMode: 'string', + }, }, ]; diff --git a/scripts/test-recipe-api.ts b/scripts/test-recipe-api.ts index eb4c05d..ecb053c 100644 --- a/scripts/test-recipe-api.ts +++ b/scripts/test-recipe-api.ts @@ -16,9 +16,8 @@ import { } from '../apps/api/src/features/recipes/imageStore.js'; import { test } from 'node:test'; import { Pool } from 'pg'; +import type { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; import sharp from 'sharp'; -import { print } from 'graphql'; -import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; import { createApp } from '../apps/api/src/app.js'; import { createAuthRepository } from '../apps/api/src/features/auth/authRepository.js'; import { createAuthService } from '../apps/api/src/features/auth/authService.js'; @@ -43,6 +42,11 @@ import { import { seedRecipes } from '../apps/api/src/db/seedRecipes.js'; +// Generated operations are typed query strings (contracts/generated.ts). +type TypedDocumentNode = DocumentTypeDecoration & { + toString(): string; +}; + await test('recipe GraphQL API against PostgreSQL', async (t) => { assert.ok(process.env.DATABASE_URL, 'Set DATABASE_URL in .env.'); const pool = new Pool({ @@ -87,7 +91,7 @@ await test('recipe GraphQL API against PostgreSQL', async (t) => { 'X-Requested-With': 'recipe-platform', ...(cookie ? { Cookie: cookie } : {}), }, - body: JSON.stringify({ query: print(document), variables }), + body: JSON.stringify({ query: document.toString(), variables }), }); const sessionCookie = response.headers.get('set-cookie')?.split(';')[0] ?? '';