Skip to content

Commit

Permalink
feat: introduce generator extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Oct 18, 2024
1 parent 584dbbe commit 1d14594
Show file tree
Hide file tree
Showing 157 changed files with 10,442 additions and 1,225 deletions.
9 changes: 9 additions & 0 deletions graffle/_.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// We import the global module for good measure although it is not clear it is always needed.
// It at least helps with Twoslash wherein without this import here Twoslash will not include the global module.
// In real TypeScript projects it seems the global module is included automatically. But there could be certain tsconfig
// setups where this still indeed does help.
import './modules/Global.js'

export { create } from './modules/Client.js'
export { Select } from './modules/Select.js'
export * as SelectionSets from './modules/SelectionSets.js'
1 change: 1 addition & 0 deletions graffle/__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as Graffle from './_.js'
5 changes: 5 additions & 0 deletions graffle/modules/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createPrefilled } from 'graffle/client'
import { defaultSchemaUrl } from './Data.js'
import { schemaDrivenDataMap } from './SchemaDrivenDataMap.js'

export const create = createPrefilled(`default`, schemaDrivenDataMap, defaultSchemaUrl)
4 changes: 4 additions & 0 deletions graffle/modules/Data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const Name = `default`
export type Name = 'default'

export const defaultSchemaUrl = undefined
24 changes: 24 additions & 0 deletions graffle/modules/Global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type * as Data from './Data.js'
import type * as MethodsDocument from './MethodsDocument.js'
import type * as MethodsRoot from './MethodsRoot.js'
import type * as MethodsSelect from './MethodsSelect.js'
import type { Index } from './SchemaIndex.js'

declare global {
export namespace GraffleGlobal {
export interface Schemas {
default: {
name: Data.Name
index: Index
interfaces: {
MethodsSelect: MethodsSelect.$MethodsSelect
Document: MethodsDocument.BuilderMethodsDocumentFn
Root: MethodsRoot.BuilderMethodsRootFn
}
customScalars: {}

defaultSchemaUrl: null
}
}
}
}
18 changes: 18 additions & 0 deletions graffle/modules/MethodsDocument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type * as Utilities from 'graffle/utilities-for-generated'
import type { Index } from './SchemaIndex.js'
import type * as SelectionSets from './SelectionSets.js'

export interface Document<$Config extends Utilities.Config> {
<$Document>(document: Utilities.ExactNonEmpty<$Document, SelectionSets.$Document>): Utilities.DocumentRunner<
$Config,
Index,
// @ts-expect-error We use Exact instead of constraint on this function. TypeScript does not see that as
// Satisfying the constraint on the DocumentRunner type.
$Document
>
}

export interface BuilderMethodsDocumentFn extends Utilities.TypeFunction.Fn {
// @ts-expect-error parameter is Untyped.
return: Document<this['params']['config']>
}
Loading

0 comments on commit 1d14594

Please sign in to comment.