#!/usr/bin/env sh
# Generate TypeScript types from GraphQL schema

# First delete all type files to ensure no old types are left
rm -rf ./app/services/orchard/api/**/generatedTypes.ts

# Generate new type files
graphql-codegen --config graphql.codegen.ts

# Format the generated files
pnpm format

# Replace @generated comment with @ts-ignore in the fragments/**/generatedTypes.ts files
# This is because the file imports shared types without actually using them, causing a TS error
sed -i '' 's/@generated/@ts-ignore/g' ./app/services/orchard/api/fragments/**/generatedTypes.ts
