chore (content api): generate types from root schema (#35283)

Ensure that resolvers are properly typed by adding a script to generate
types from the root schema.
This commit is contained in:
Charis authored and GitHub committed 2025-05-02 11:25:35 -04:00
1 parent 02aea98053
commit 5718684991
6 files changed
+1586 -23

No files matched your search

+1
View File
@@ -20,6 +20,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
**/__generated__/**/*
**/*/generated/**/*
!**/*/generated/.gitkeep
!**/*/generated/**/.gitkeep
+13
View File
@@ -0,0 +1,13 @@
import type { CodegenConfig } from '@graphql-codegen/cli'
const config: CodegenConfig = {
overwrite: true,
schema: './__generated__/schema.graphql',
generates: {
'__generated__/graphql.ts': {
plugins: ['typescript', 'typescript-resolvers'],
},
},
}
export default config
+9 -4
View File
@@ -4,11 +4,11 @@
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
"predev": "pnpm run codegen:references && pnpm run codegen:examples",
"predev": "pnpm run codegen:graphql && pnpm run codegen:references && pnpm run codegen:examples",
"dev": "concurrently --kill-others \"next dev --port 3001\" \"pnpm run dev:watch:troubleshooting\"",
"dev:watch:troubleshooting": "node ./scripts/troubleshooting/watch.mjs",
"dev:secrets:pull": "AWS_PROFILE=supabase-dev node ../../scripts/getSecrets.js -n local/docs",
"prebuild": "pnpm run codegen:references && pnpm run codegen:examples",
"prebuild": "pnpm run codegen:graphql && pnpm run codegen:references && pnpm run codegen:examples",
"build": "next build",
"build:analyze": "ANALYZE=true next build",
"build:sitemap": "tsx ./internals/generate-sitemap.ts",
@@ -17,6 +17,7 @@
"start": "next start",
"lint": "next lint",
"lint:mdx": "supa-mdx-lint content --config ../../supa-mdx-lint.config.toml",
"pretypecheck": "pnpm run codegen:graphql",
"typecheck": "tsc --noEmit",
"pretest": "pnpm run codegen:examples",
"test": "vitest --exclude \"**/*.smoke.test.ts\"",
@@ -27,9 +28,10 @@
"last-changed": "tsx scripts/last-changed.ts",
"last-changed:reset": "pnpm run last-changed -- --reset",
"codegen:examples": "cp -r ../../examples ./examples",
"codegen:references": "tsx features/docs/Reference.generated.script.ts",
"codemod:frontmatter": "node ./scripts/codemod/mdx-meta.mjs && prettier --write \"content/**/*.mdx\"",
"clean": "rimraf node_modules features/docs/generated examples"
"codegen:graphql": "tsx ./scripts/graphqlSchema.ts && graphql-codegen --config codegen.ts",
"codegen:references": "tsx features/docs/Reference.generated.script.ts",
"clean": "rimraf node_modules features/docs/generated examples __generated__"
},
"dependencies": {
"@har-sdk/openapi-sampler": "^2.2.0",
@@ -114,6 +116,9 @@
"devDependencies": {
"@aws-sdk/client-secrets-manager": "^3.410.0",
"@graphiql/toolkit": "^0.9.1",
"@graphql-codegen/cli": "5.0.5",
"@graphql-codegen/typescript": "4.1.6",
"@graphql-codegen/typescript-resolvers": "4.5.0",
"@supabase/supa-mdx-lint": "0.2.6-alpha",
"@types/common-tags": "^1.8.4",
"@types/estree": "1.0.5",
+5 -2
View File
@@ -5,10 +5,13 @@ import {
GraphQLString,
printSchema,
} from 'graphql'
import { RootQueryTypeResolvers } from '~/__generated__/graphql'
const GRAPHQL_FIELD_INTROSPECT = 'schema'
const GRAPHQL_FIELD_INTROSPECT = 'schema' as const
async function resolveIntrospect() {
type IntrospectResolver = RootQueryTypeResolvers[typeof GRAPHQL_FIELD_INTROSPECT]
const resolveIntrospect: IntrospectResolver = async () => {
const schema = printSchema(rootGraphQLSchema)
return schema
}
+27
View File
@@ -0,0 +1,27 @@
import { printSchema } from 'graphql'
import fs from 'node:fs'
import path from 'node:path'
import { rootGraphQLSchema } from '../resources/rootSchema'
async function generateGraphQLSchema() {
try {
const schemaString = printSchema(rootGraphQLSchema)
const outputDir = path.resolve(__dirname, '../__generated__')
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true })
}
const outputPath = path.resolve(outputDir, 'schema.graphql')
fs.writeFileSync(outputPath, schemaString)
console.log(`✅ Successfully generated GraphQL schema at ${outputPath}`)
} catch (error) {
console.error('🚨 Error generating GraphQL schema:', error)
process.exit(1)
}
}
if (require.main === module) {
generateGraphQLSchema()
}
+1531 -17
View File
File diff suppressed because it is too large. Load diff