Skip to content

Commit

Permalink
refactor: preset entrypoints (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Dec 16, 2024
1 parent 40d8961 commit d19d399
Show file tree
Hide file tree
Showing 208 changed files with 5,815 additions and 387 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: pnpm build
- name: Install Examples Dependencies
working-directory: examples
run: pnpm install
- run: pnpm check:lint
publint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -81,6 +85,9 @@ jobs:
with:
node-version: ${{ matrix.node }}
- run: pnpm build
- name: Install Examples Dependencies
working-directory: examples
run: pnpm install
- run: pnpm test:examples -- --environment ${{ matrix.environment }}
test-e2e:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default tsEslint.config({
'src/layers/1_Schema/Hybrid/types/Scalar/Scalar.ts', // There is an ESLint error that goes away when ignored leading to a circular issue of either lint error or unused lint disable.
'**/$/**/*',
'legacy/**/*',
'build/**/*',
'**/build/**/*',
'website/**/*',
],
extends: configPrisma,
Expand Down
10 changes: 10 additions & 0 deletions examples/$/graffle/_.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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 { schemaDrivenDataMap as schemaMap } from './modules/schema-driven-data-map.js'
export { Select } from './modules/select.js'
export * as SelectionSets from './modules/selection-sets.js'
2 changes: 2 additions & 0 deletions examples/$/graffle/__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as Graffle from './_.js'
export { schemaDrivenDataMap as schemaMap } from './modules/schema-driven-data-map.js'
21 changes: 21 additions & 0 deletions examples/$/graffle/modules/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TransportHttp } from 'graffle/extensions/transport-http'
import * as $$Utilities from 'graffle/utilities-for-generated'
import * as $$Data from './data.js'
import * as $$Scalar from './scalar.js'
import * as $$SchemaDrivenDataMap from './schema-driven-data-map.js'

const context = $$Utilities.useReducer(
{
...$$Utilities.Context.States.contextEmpty,
name: $$Data.Name,
schemaMap: $$SchemaDrivenDataMap.schemaDrivenDataMap,
scalars: $$Scalar.$registry,
},
TransportHttp({
url: $$Data.defaultSchemaUrl,
}),
)

export const create = $$Utilities.createConstructorWithContext(
context,
)
4 changes: 4 additions & 0 deletions examples/$/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 = new URL('http://localhost:3000/graphql')
25 changes: 25 additions & 0 deletions examples/$/graffle/modules/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as $$Data from './data.js'
import * as $$MethodsDocument from './methods-document.js'
import * as $$MethodsRoot from './methods-root.js'
import * as $$MethodsSelect from './methods-select.js'
import * as $$Schema from './schema.js'

declare global {
export namespace GraffleGlobal {
export interface Clients {
default: {
name: $$Data.Name
schema: $$Schema.Schema
interfaces: {
MethodsSelect: $$MethodsSelect.$MethodsSelect
Document: $$MethodsDocument.BuilderMethodsDocumentFn
Root: $$MethodsRoot.BuilderMethodsRootFn
}
/**
* http://localhost:3000/graphql
*/
defaultSchemaUrl: string
}
}
}
}
20 changes: 20 additions & 0 deletions examples/$/graffle/modules/methods-document.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type * as $$Utilities from 'graffle/utilities-for-generated'
import * as $$Schema from './schema.js'
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<
$Context,
$$Schema.Schema,
// @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 {
// @ts-expect-error parameter is Untyped.
return: Document<this['params']>
}
167 changes: 167 additions & 0 deletions examples/$/graffle/modules/methods-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import type { InferResult } from 'graffle/schema'
import type * as $$Utilities from 'graffle/utilities-for-generated'
import * as $$Schema from './schema.js'
import * as $$SelectionSets from './selection-sets.js'

export interface QueryMethods<$Context extends $$Utilities.Context> {
$batch: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutput<
$Context,
InferResult.OperationQuery<$$Utilities.AssertExtendsObject<$SelectionSet>, $$Schema.Schema<$Context['scalars']>>
>
>
>
__typename: $$Utilities.ClientTransports.PreflightCheck<
$Context,
() => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
{ __typename: 'Query' },
'__typename'
>
>
>

battles: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.battles<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
InferResult.OperationQuery<{ battles: $SelectionSet }, $$Schema.Schema<$Context['scalars']>>,
'battles'
>
>
>

beings: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.beings<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
InferResult.OperationQuery<{ beings: $SelectionSet }, $$Schema.Schema<$Context['scalars']>>,
'beings'
>
>
>

pokemonByName: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.pokemonByName<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
InferResult.OperationQuery<{ pokemonByName: $SelectionSet }, $$Schema.Schema<$Context['scalars']>>,
'pokemonByName'
>
>
>

pokemons: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.pokemons<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
InferResult.OperationQuery<{ pokemons: $SelectionSet }, $$Schema.Schema<$Context['scalars']>>,
'pokemons'
>
>
>

trainerByName: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.trainerByName<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
InferResult.OperationQuery<{ trainerByName: $SelectionSet }, $$Schema.Schema<$Context['scalars']>>,
'trainerByName'
>
>
>

trainers: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.trainers<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
InferResult.OperationQuery<{ trainers: $SelectionSet }, $$Schema.Schema<$Context['scalars']>>,
'trainers'
>
>
>
}

export interface MutationMethods<$Context extends $$Utilities.Context> {
$batch: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Mutation<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutput<
$Context,
InferResult.OperationMutation<
$$Utilities.AssertExtendsObject<$SelectionSet>,
$$Schema.Schema<$Context['scalars']>
>
>
>
>
__typename: $$Utilities.ClientTransports.PreflightCheck<
$Context,
() => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
{ __typename: 'Mutation' },
'__typename'
>
>
>

addPokemon: $$Utilities.ClientTransports.PreflightCheck<
$Context,
<$SelectionSet>(
selectionSet: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Mutation.addPokemon<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputGraffleRootField<
$Context,
InferResult.OperationMutation<{ addPokemon: $SelectionSet }, $$Schema.Schema<$Context['scalars']>>,
'addPokemon'
>
>
>
}

export interface BuilderMethodsRoot<$Context extends $$Utilities.Context> {
query: QueryMethods<$Context>
mutation: MutationMethods<$Context>
}

export interface BuilderMethodsRootFn extends $$Utilities.TypeFunction {
// @ts-expect-error parameter is Untyped.
return: BuilderMethodsRoot<this['params']>
}
Loading

0 comments on commit d19d399

Please sign in to comment.