Skip to content

Commit

Permalink
feat: fluent extensions, throws extension, gen static interfaces (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Sep 24, 2024
1 parent e4da3c0 commit a3b1d75
Show file tree
Hide file tree
Showing 228 changed files with 11,164 additions and 3,089 deletions.
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import tsEslint from 'typescript-eslint'

export default tsEslint.config({
ignores: [
'examples/55_generated/generated_document__document.ts',
'eslint.config.js',
'vite.config.ts',
'**/generated/**/*',
Expand Down
1 change: 0 additions & 1 deletion examples/$/generated-clients/atlas/modules/Client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createPrefilled } from '../../../../../src/entrypoints/client.js'

import { $defaultSchemaUrl, $Index } from './SchemaRuntime.js'

export const create = createPrefilled(`Atlas`, $Index, $defaultSchemaUrl)
1 change: 0 additions & 1 deletion examples/$/generated-clients/atlas/modules/Data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const Name = `Atlas`

export type Name = 'Atlas'
3 changes: 0 additions & 3 deletions examples/$/generated-clients/atlas/modules/Error.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
type Include<T, U> = Exclude<T, Exclude<T, U>>

type ObjectWithTypeName = { __typename: string }

const ErrorObjectsTypeNameSelectedEnum = {} as Record<string, ObjectWithTypeName>

const ErrorObjectsTypeNameSelected = Object.values(ErrorObjectsTypeNameSelectedEnum)

type ErrorObjectsTypeNameSelected = (typeof ErrorObjectsTypeNameSelected)[number]

export const isError = <$Value>(value: $Value): value is Include<$Value, ErrorObjectsTypeNameSelected> => {
return typeof value === `object` && value !== null && `__typename` in value
&& ErrorObjectsTypeNameSelected.some(_ => _.__typename === value.__typename)
Expand Down
9 changes: 8 additions & 1 deletion examples/$/generated-clients/atlas/modules/Global.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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 GraffleGlobalTypes {
export interface Schemas {
Atlas: {
interfaces: {
MethodsSelect: MethodsSelect.$MethodsSelect
Document: MethodsDocument.BuilderMethodsDocumentFn
Root: MethodsRoot.BuilderMethodsRootFn
}
name: Data.Name
index: Index
customScalars: {}
Expand Down
22 changes: 22 additions & 0 deletions examples/$/generated-clients/atlas/modules/MethodsDocument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type * as Utilities from '../../../../../src/entrypoints/utilities-for-generated.js'
import type { Index } from './SchemaIndex.js'
import type * as SelectionSets from './SelectionSets.js'

interface DocumentInput {
queries?: Record<string, SelectionSets.Query>
}

export interface Document<$Config extends Utilities.Config> {
<$Document>(document: Utilities.ExactNonEmpty<$Document, DocumentInput>): 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.HKT.Fn {
// @ts-expect-error parameter is Untyped.
return: Document<this['params']['config']>
}
84 changes: 84 additions & 0 deletions examples/$/generated-clients/atlas/modules/MethodsRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import type { ResultSet } from '../../../../../src/entrypoints/schema.js'
import type * as Utils from '../../../../../src/entrypoints/utilities-for-generated.js'
import type { Index } from './SchemaIndex.js'
import type * as SelectionSet from './SelectionSets.js'

export interface QueryMethods<$Config extends Utils.Config> {
// todo Use a static type here?
$batch: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query>) => Promise<
Utils.ResolveOutputReturnRootType<
$Config,
Index,
ResultSet.Query<
Utils.AddTypenameToSelectedRootTypeResultFields<$Config, Index, 'Query', $SelectionSet>,
Index
>
>
>
// todo Use a static type here?
__typename: () => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Index,
'__typename',
'Query'
>
>
continent: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.continent>) => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Index,
'continent',
ResultSet.Field<$SelectionSet, Index['Root']['Query']['fields']['continent'], Index>
>
>
continents: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.continents>) => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Index,
'continents',
ResultSet.Field<$SelectionSet, Index['Root']['Query']['fields']['continents'], Index>
>
>
countries: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.countries>) => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Index,
'countries',
ResultSet.Field<$SelectionSet, Index['Root']['Query']['fields']['countries'], Index>
>
>
country: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.country>) => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Index,
'country',
ResultSet.Field<$SelectionSet, Index['Root']['Query']['fields']['country'], Index>
>
>
language: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.language>) => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Index,
'language',
ResultSet.Field<$SelectionSet, Index['Root']['Query']['fields']['language'], Index>
>
>
languages: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.languages>) => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Index,
'languages',
ResultSet.Field<$SelectionSet, Index['Root']['Query']['fields']['languages'], Index>
>
>
}

export interface BuilderMethodsRoot<$Config extends Utils.Config> {
query: QueryMethods<$Config>
}

export interface BuilderMethodsRootFn extends Utils.HKT.Fn {
// @ts-expect-error parameter is Untyped.
return: BuilderMethodsRoot<this['params']['config']>
}
83 changes: 83 additions & 0 deletions examples/$/generated-clients/atlas/modules/MethodsSelect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type * as $Utilities from '../../../../../src/entrypoints/utilities-for-generated.js'
import type * as $SelectionSets from './SelectionSets.js'

//
//
//
//
//
//
// ==================================================================================================
// Select Methods Interface
// ==================================================================================================
//
//
//
//
//
//

export interface $MethodsSelect {
Query: Query
Continent: Continent
Country: Country
Language: Language
State: State
Subdivision: Subdivision
}

//
//
//
//
//
//
// ==================================================================================================
// Root
// ==================================================================================================
//
//
//
//
//
//

export interface Query {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Query>): $SelectionSet
}

//
//
//
//
//
//
// ==================================================================================================
// Object
// ==================================================================================================
//
//
//
//
//
//

export interface Continent {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Continent>): $SelectionSet
}

export interface Country {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Country>): $SelectionSet
}

export interface Language {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Language>): $SelectionSet
}

export interface State {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.State>): $SelectionSet
}

export interface Subdivision {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Subdivision>): $SelectionSet
}
11 changes: 0 additions & 11 deletions examples/$/generated-clients/atlas/modules/SchemaBuildtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type * as $Scalar from './Scalar.ts'
// ------------------------------------------------------------ //
// Root //
// ------------------------------------------------------------ //

export namespace Root {
export type Query = $.Output.ObjectQuery<{
continent: $.Field<
Expand Down Expand Up @@ -45,19 +44,15 @@ export namespace Root {
>
}>
}

// ------------------------------------------------------------ //
// Enum //
// ------------------------------------------------------------ //

export namespace Enum {
// -- no types --
}

// ------------------------------------------------------------ //
// InputObject //
// ------------------------------------------------------------ //

export namespace InputObject {
export type ContinentFilterInput = $.InputObject<'ContinentFilterInput', {
code: $.Input.Field<$.Input.Nullable<InputObject.StringQueryOperatorInput>>
Expand All @@ -82,19 +77,15 @@ export namespace InputObject {
regex: $.Input.Field<$.Input.Nullable<$Scalar.String>>
}, true>
}

// ------------------------------------------------------------ //
// Interface //
// ------------------------------------------------------------ //

export namespace Interface {
// -- no types --
}

// ------------------------------------------------------------ //
// Object //
// ------------------------------------------------------------ //

export namespace Object {
export type Continent = $.Object$2<'Continent', {
code: $.Field<$Scalar.ID, null>
Expand Down Expand Up @@ -144,11 +135,9 @@ export namespace Object {
name: $.Field<$Scalar.String, null>
}>
}

// ------------------------------------------------------------ //
// Union //
// ------------------------------------------------------------ //

export namespace Union {
// -- no types --
}
11 changes: 9 additions & 2 deletions examples/$/generated-clients/atlas/modules/SchemaIndex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable */

import type * as Data from './Data.js'

import type * as MethodsRoot from './MethodsRoot.js'
import type * as Schema from './SchemaBuildtime.js'

export interface Index {
Expand All @@ -13,6 +12,14 @@ export interface Index {
Mutation: null
Subscription: null
}
allTypes: {
Query: Schema.Root.Query
Continent: Schema.Object.Continent
Country: Schema.Object.Country
Language: Schema.Object.Language
State: Schema.Object.State
Subdivision: Schema.Object.Subdivision
}
objects: {
Continent: Schema.Object.Continent
Country: Schema.Object.Country
Expand Down
12 changes: 8 additions & 4 deletions examples/$/generated-clients/atlas/modules/SchemaRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable */

import * as $ from '../../../../../src/entrypoints/schema.js'
import * as Data from './Data.js'
import * as $Scalar from './Scalar.js'
import type { Index } from './SchemaIndex.js'

export const $defaultSchemaUrl = new URL('https://countries.trevorblades.com/graphql')

export const ContinentFilterInput = $.InputObject(`ContinentFilterInput`, {
Expand All @@ -29,7 +27,6 @@ export const StringQueryOperatorInput = $.InputObject(`StringQueryOperatorInput`
nin: $.Input.Field($.Input.Nullable($.Input.List($Scalar.String))),
regex: $.Input.Field($.Input.Nullable($Scalar.String)),
}, true)

// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
export const Continent = $.Object$(`Continent`, {
code: $.field($Scalar.ID),
Expand Down Expand Up @@ -108,7 +105,6 @@ export const Query = $.Object$(`Query`, {
$.Args({ filter: $.Input.Field($.Input.Nullable(LanguageFilterInput)) }, true),
),
})

export const $Index: Index = {
name: Data.Name,
RootTypesPresent: ['Query'] as const,
Expand All @@ -118,6 +114,14 @@ export const $Index: Index = {
Mutation: null,
Subscription: null,
},
allTypes: {
Query,
Continent,
Country,
Language,
State,
Subdivision,
},
objects: {
Continent,
Country,
Expand Down
Loading

0 comments on commit a3b1d75

Please sign in to comment.