Skip to content

Commit

Permalink
refactor: generator layer (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Sep 27, 2024
1 parent 4ce18c6 commit 6503089
Show file tree
Hide file tree
Showing 59 changed files with 843 additions and 1,111 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"homepage": "https://github.com/jasonkuhrt/graffle",
"scripts": {
"serve:pokemon": "tsx tests/_/services/pokemonManual.ts",
"gen:graffle": "tsx tests/_/schemas/generate.ts && pnpm build && cd website && pnpm gen:graffle",
"gen:graffle": "pnpm gen:graffle:tests && pnpm build && cd website && pnpm gen:graffle",
"gen:graffle:tests": "tsx tests/_/schemas/generate.ts",
"graffle": "tsx ./src/cli/generate.ts",
"gen:examples": "tsx scripts/generate-examples-derivatives/generate.ts && pnpm format",
"dev": "rm -rf dist && tsc --watch",
Expand Down
4 changes: 2 additions & 2 deletions src/cli/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Command } from '@molt/command'
import * as Path from 'node:path'
import { z } from 'zod'
import { generateFiles } from '../layers/4_generator/files.js'
import { Generator } from '../layers/4_generator/__.js'
import { urlParseSafe } from '../lib/prelude.js'

const args = Command.create().description(`Generate a type safe GraphQL client.`)
Expand Down Expand Up @@ -89,7 +89,7 @@ const defaultSchemaUrl = typeof args.defaultSchemaUrl === `string`
? new URL(args.defaultSchemaUrl)
: args.defaultSchemaUrl

await generateFiles({
await Generator.generate({
sourceSchema: url
? { type: `url`, url }
: { type: `sdl`, dirPath: Path.dirname(args.schema) },
Expand Down
2 changes: 1 addition & 1 deletion src/entrypoints/generator.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { generateFiles as generate } from '../layers/4_generator/files.js'
export { generate } from '../layers/4_generator/_.js'
2 changes: 2 additions & 0 deletions src/layers/4_generator/_.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './config.js'
export * from './generate.js'
1 change: 1 addition & 0 deletions src/layers/4_generator/__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as Generator from './_.js'
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ import type * as Schema from './SchemaBuildtime.js'
export interface Index {
name: Data.Name
RootTypesPresent: ['Query', 'Mutation']
RootUnion: Schema.Root.Query | Schema.Root.Mutation
RootTypesPresent: ['Mutation', 'Query']
RootUnion: Schema.Root.Mutation | Schema.Root.Query
Root: {
Query: Schema.Root.Query
Mutation: Schema.Root.Mutation
Expand Down Expand Up @@ -270,12 +270,12 @@ export interface Index {
ErrorTwo: { __typename: 'ErrorTwo' }
}
rootResultFields: {
Subscription: {}
Mutation: {}
Query: {
result: 'result'
resultNonNull: 'resultNonNull'
}
Mutation: {}
Subscription: {}
}
}
}
Expand All @@ -284,7 +284,7 @@ export interface Index {
exports[`schema2 7`] = `
"import type * as $ from '../../../../../../src/entrypoints/schema.js'
import type * as $Scalar from './Scalar.ts'
import type * as $Scalar from './Scalar.js'
// ------------------------------------------------------------ //
// Root //
Expand Down Expand Up @@ -898,7 +898,7 @@ export const Query = $.Object$(\`Query\`, {
})
export const $Index: Index = {
name: Data.Name,
RootTypesPresent: ['Query', 'Mutation'] as const,
RootTypesPresent: ['Mutation', 'Query'] as const,
RootUnion: undefined as any, // Type level only.
Root: {
Query,
Expand Down Expand Up @@ -967,12 +967,12 @@ export const $Index: Index = {
ErrorTwo: { __typename: 'ErrorTwo' },
},
rootResultFields: {
Subscription: {},
Mutation: {},
Query: {
result: 'result' as const,
resultNonNull: 'resultNonNull' as const,
},
Mutation: {},
Subscription: {},
},
},
}
Expand Down
Loading

0 comments on commit 6503089

Please sign in to comment.