Skip to content

Commit

Permalink
refactor: document-builder namespace (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Dec 27, 2024
1 parent 05a9717 commit 62553b5
Show file tree
Hide file tree
Showing 32 changed files with 1,350 additions and 718 deletions.
2 changes: 1 addition & 1 deletion examples/$/graffle/modules/methods-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as $$SelectionSets from './selection-sets.js'
export interface Document<$Context extends $$Utilities.Context> {
<$Document>(
document: $$Utilities.ExactNonEmpty<$Document, $$SelectionSets.$Document<$Context['scalars']>>,
): $$Utilities.DocumentRunner<
): $$Utilities.DocumentBuilder.DocumentRunner<
$Context,
$$Schema.Schema,
// @ts-expect-error We use Exact instead of constraint on this function. TypeScript does not see that as
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@
},
"homepage": "https://github.com/graffle-js/graffle",
"scripts": {
"graffle": "tsx ./src/generator/cli/generate.ts",
"serve:pokemon": "tsx tests/_/services/pokemonManual.ts",
"gen:graffle": "pnpm gen:graffle:tests && pnpm build && cd website && pnpm gen:graffle",
"gen:graffle": "pnpm gen:graffle:tests && pnpm build && pnpm website:gen:graffle",
"gen:graffle:tests": "tsx tests/_/schemas/generate.ts && pnpm graffle --project src/extensions/SchemaErrors/tests/fixture",
"examples:gen:graffle": "pnpm build && cd examples && pnpm i && pnpm gen:graffle",
"examples:link-mode": "cd examples && pnpm add ..",
"graffle": "tsx ./src/generator/cli/generate.ts",
"website:gen:graffle": "cd website && pnpm i && pnpm gen:graffle",
"gen:examples": "tsx scripts/generate-examples-derivatives/generate.ts && pnpm format",
"gen:examples:outputs": "tsx scripts/generate-examples-derivatives/generate.ts --outputs",
"dev": "rm -rf dist && tsc --watch",
Expand Down
1 change: 0 additions & 1 deletion src/documentBuilder/_.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/documentBuilder/_.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './InferResult/__.js'
export * from './requestMethods/document.js'
export * from './requestMethods/requestMethods.js'
export * from './Select/__.js'
export * from './SelectGraphQLMapper/__.js'
3 changes: 1 addition & 2 deletions src/entrypoints/utilities-for-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ export type { Simplify } from 'type-fest'
export { createConstructorWithContext } from '../client/client.js'
export type { ConfigGetOutputError, HandleOutput, HandleOutputGraffleRootField } from '../client/handleOutput.js'
export { useReducer } from '../client/properties/use.js'
export { type DocumentRunner } from '../documentBuilder/requestMethods/document.js'
export * from '../documentBuilder/Select/__.js'
export * from '../documentBuilder/__.js'
export { type AssertExtendsObject, type Exact, type ExactNonEmpty, type UnionExpanded } from '../lib/prelude.js'
export { TypeFunction } from '../lib/type-function/__.js'
export type { ClientTransports } from '../types/context.js'
Expand Down
4 changes: 2 additions & 2 deletions src/extension/TypeHooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GraffleExecutionResultEnvelope } from '../client/handleOutput.js'
import type { Select } from '../entrypoints/utilities-for-generated.js'
import type { DocumentBuilder } from '../documentBuilder/__.js'
import type { AssertExtends } from '../lib/prelude.js'
import type { TypeFunction } from '../lib/type-function/__.js'
import type { Context } from '../types/context.js'
Expand Down Expand Up @@ -79,7 +79,7 @@ export interface TypeHooksBuilder<$TypeHooks extends TypeHooks = TypeHooksEmpty>
export interface OnRequestDocumentRootType extends TypeFunction {}
export namespace OnRequestDocumentRootType {
export interface Params {
selectionRootType: Select.SelectionSet.RootType
selectionRootType: DocumentBuilder.Select.SelectionSet.RootType
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { expect, test } from 'vitest'
import { graffleMappedResultToRequest } from '../../documentBuilder/requestMethods/requestMethods.js'
import { normalizeOrThrow } from '../../documentBuilder/Select/document.js'
import { SelectionSetGraphqlMapper } from '../../documentBuilder/SelectGraphQLMapper/__.js'
import { DocumentBuilder } from '../../documentBuilder/__.js'
import { injectTypenameOnRootResultFields } from './injectTypenameOnRootResultFields.js'
import { GraffleSchemaErrors } from './tests/fixture/graffle/__.js'

Expand Down Expand Up @@ -35,14 +33,14 @@ test.each<CasesQuery>([
{ resultNonNull: [`x`, {}] },
{ resultNonNull: [`x`, { __typename: true }] }],
])(`Query %s`, (_, queryWithoutTypenameInput, queryWithTypenameInput) => {
const docWithout = SelectionSetGraphqlMapper.toGraphQL(
normalizeOrThrow({ query: { x: queryWithoutTypenameInput as any } }),
const docWithout = DocumentBuilder.SelectionSetGraphqlMapper.toGraphQL(
DocumentBuilder.Select.Document.normalizeOrThrow({ query: { x: queryWithoutTypenameInput as any } }),
)
const docWith = SelectionSetGraphqlMapper.toGraphQL(
normalizeOrThrow({ query: { x: queryWithTypenameInput as any } }),
const docWith = DocumentBuilder.SelectionSetGraphqlMapper.toGraphQL(
DocumentBuilder.Select.Document.normalizeOrThrow({ query: { x: queryWithTypenameInput as any } }),
)
injectTypenameOnRootResultFields({
request: graffleMappedResultToRequest(docWithout),
request: DocumentBuilder.graffleMappedResultToRequest(docWithout),
sddm: GraffleSchemaErrors.schemaMap,
})
expect(docWithout.document).toMatchObject(docWith.document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as $$SelectionSets from './selection-sets.js'
export interface Document<$Context extends $$Utilities.Context> {
<$Document>(
document: $$Utilities.ExactNonEmpty<$Document, $$SelectionSets.$Document<$Context['scalars']>>,
): $$Utilities.DocumentRunner<
): $$Utilities.DocumentBuilder.DocumentRunner<
$Context,
$$Schema.Schema,
// @ts-expect-error We use Exact instead of constraint on this function. TypeScript does not see that as
Expand Down
Loading

0 comments on commit 62553b5

Please sign in to comment.