From a554328350db293459a79b226d3e0fd55606a1f8 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Sat, 20 Apr 2024 21:34:28 +0200 Subject: [PATCH] tests(ts-client): refactor to one default schema (#790) --- src/client/ResultSet/ResultSet.test-d.ts | 14 +- .../SelectionSet/SelectionSet.test-d.ts | 20 +- .../toGraphQLDocumentString.test.ts.snap | 12 +- .../toGraphQLDocumentString.test.ts | 10 +- src/client/client.customScalar.test.ts | 6 +- src/client/client.returnMode.test-d.ts | 2 +- src/client/client.test.ts | 9 +- .../__snapshots__/files.test.ts.snap | 993 ++++++------------ src/generator/files.test.ts | 21 - tests/_/db.ts | 67 +- tests/_/schema/generated/Index.ts | 8 + tests/_/schema/generated/SchemaBuildtime.ts | 174 ++- tests/_/schema/generated/SchemaRuntime.ts | 114 ++ tests/_/schema/generated/Select.ts | 27 + tests/_/schema/schema.graphql | 94 +- tests/_/schema/schema.ts | 290 ++++- tests/_/schemaGenerate.ts | 13 - .../_/schemaMutationOnly/generated/Global.ts | 2 - tests/_/schemaQueryOnly/generated/Global.ts | 2 - tests/ts/_/schema/generated/Error.ts | 14 - tests/ts/_/schema/generated/Global.ts | 14 - tests/ts/_/schema/generated/Index.ts | 36 - tests/ts/_/schema/generated/Scalar.ts | 2 - .../ts/_/schema/generated/SchemaBuildtime.ts | 292 ----- tests/ts/_/schema/generated/SchemaRuntime.ts | 218 ---- tests/ts/_/schema/generated/Select.ts | 82 -- tests/ts/_/schema/schema.graphql | 166 --- 27 files changed, 1094 insertions(+), 1608 deletions(-) delete mode 100644 tests/ts/_/schema/generated/Error.ts delete mode 100644 tests/ts/_/schema/generated/Global.ts delete mode 100644 tests/ts/_/schema/generated/Index.ts delete mode 100644 tests/ts/_/schema/generated/Scalar.ts delete mode 100644 tests/ts/_/schema/generated/SchemaBuildtime.ts delete mode 100644 tests/ts/_/schema/generated/SchemaRuntime.ts delete mode 100644 tests/ts/_/schema/generated/Select.ts delete mode 100644 tests/ts/_/schema/schema.graphql diff --git a/src/client/ResultSet/ResultSet.test-d.ts b/src/client/ResultSet/ResultSet.test-d.ts index 11c2ee5ee..5a09140ae 100644 --- a/src/client/ResultSet/ResultSet.test-d.ts +++ b/src/client/ResultSet/ResultSet.test-d.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/ban-types */ import { expectTypeOf, test } from 'vitest' -import type { Index } from '../../../tests/ts/_/schema/generated/Index.js' -import type * as Schema from '../../../tests/ts/_/schema/generated/SchemaBuildtime.js' +import type { Index } from '../../../tests/_/schema/generated/Index.js' +import type * as Schema from '../../../tests/_/schema/generated/SchemaBuildtime.js' import type { SelectionSet } from '../SelectionSet/__.js' import type { ResultSet } from './__.js' @@ -51,10 +51,10 @@ test(`general`, () => { expectTypeOf>().toEqualTypeOf<{ objectNonNull: { __typename: "Object1" } }>() // Union - expectTypeOf>().toEqualTypeOf<{ fooBarUnion: null | { __typename: "Foo" } | { __typename: "Bar" } }>() - expectTypeOf>().toEqualTypeOf<{ fooBarUnion: null | {} | { __typename: "Foo" } }>() - expectTypeOf>().toEqualTypeOf<{ fooBarUnion: null | {} | { id: null|string } }>() - expectTypeOf>().toEqualTypeOf<{ fooBarUnion: null | { __typename: "Bar" } | { __typename: "Foo"; id: null|string } }>() + expectTypeOf>().toEqualTypeOf<{ unionFooBar: null | { __typename: "Foo" } | { __typename: "Bar" } }>() + expectTypeOf>().toEqualTypeOf<{ unionFooBar: null | {} | { __typename: "Foo" } }>() + expectTypeOf>().toEqualTypeOf<{ unionFooBar: null | {} | { id: null|string } }>() + expectTypeOf>().toEqualTypeOf<{ unionFooBar: null | { __typename: "Bar" } | { __typename: "Foo"; id: null|string } }>() // with Args expectTypeOf>().toEqualTypeOf<{ unionFooBarWithArgs: null | {} | { id: null|string } }>() @@ -82,7 +82,7 @@ test(`general`, () => { expectTypeOf>().toEqualTypeOf<{ id_as: ResultSet.Errors.UnknownFieldName<'id_as', Schema.Root.Query> }>() expectTypeOf>().toEqualTypeOf<{ id_as_$: ResultSet.Errors.UnknownFieldName<'id_as_$', Schema.Root.Query> }>() // union fragment - expectTypeOf>().toEqualTypeOf<{ fooBarUnion: null | {} | { id2: null|string } }>() + expectTypeOf>().toEqualTypeOf<{ unionFooBar: null | {} | { id2: null|string } }>() // Directive @include // On scalar non-nullable diff --git a/src/client/SelectionSet/SelectionSet.test-d.ts b/src/client/SelectionSet/SelectionSet.test-d.ts index fd5972ada..dd670977d 100644 --- a/src/client/SelectionSet/SelectionSet.test-d.ts +++ b/src/client/SelectionSet/SelectionSet.test-d.ts @@ -1,5 +1,5 @@ import { assertType, expectTypeOf, test } from 'vitest' -import type { Index } from '../../../tests/ts/_/schema/generated/Index.js' +import type { Index } from '../../../tests/_/schema/generated/Index.js' import type { SelectionSet } from './__.js' type Q = SelectionSet.Query @@ -52,15 +52,15 @@ test(`Query`, () => { assertType({ object: { a2: true } }) // Union - assertType({ fooBarUnion: { __typename: true } }) - assertType({ fooBarUnion: { onFoo: { __typename: true } } }) - assertType({ fooBarUnion: { onFoo: { id: true } } }) + assertType({ unionFooBar: { __typename: true } }) + assertType({ unionFooBar: { onFoo: { __typename: true } } }) + assertType({ unionFooBar: { onFoo: { id: true } } }) // @ts-expect-error no b - assertType({ fooBarUnion: { onFoo: { id2: true } } }) - assertType({ fooBarUnion: { onBar: { __typename: true } } }) - assertType({ fooBarUnion: { onBar: { int: true } } }) + assertType({ unionFooBar: { onFoo: { id2: true } } }) + assertType({ unionFooBar: { onBar: { __typename: true } } }) + assertType({ unionFooBar: { onBar: { int: true } } }) // @ts-expect-error no a - assertType({ fooBarUnion: { onBar: { int2: true } } }) + assertType({ unionFooBar: { onBar: { int2: true } } }) // Union fragments Case assertType({ lowerCaseUnion: { onLowerCaseObject: { id: true }, onLowerCaseObject2: { int: true } } }) @@ -112,7 +112,7 @@ test(`Query`, () => { assertType({ object: { $skip: true, string: true } }) // assertType({ scalars: skip().select({ a: true }) }) // on fragment - assertType({ fooBarUnion: { onBar: { $skip: true, int: true } } }) + assertType({ unionFooBar: { onBar: { $skip: true, int: true } } }) // @include assertType({ string: { $include: true } }) assertType({ string: { $include: false } }) @@ -224,7 +224,7 @@ test(`Query`, () => { // @ts-expect-error no directives on scalars field assertType({ scalars: { $scalars: { $skip: true } } }) // union fragment - assertType({ fooBarUnion: { onBar: { $scalars: true } } }) + assertType({ unionFooBar: { onBar: { $scalars: true } } }) assertType({ unionFooBarWithArgs: { $: { id: `abc` }, onBar: { $scalars: true } } }) // assertType({ scalars: select() }) diff --git a/src/client/SelectionSet/__snapshots__/toGraphQLDocumentString.test.ts.snap b/src/client/SelectionSet/__snapshots__/toGraphQLDocumentString.test.ts.snap index 617b33960..3e0876ce3 100644 --- a/src/client/SelectionSet/__snapshots__/toGraphQLDocumentString.test.ts.snap +++ b/src/client/SelectionSet/__snapshots__/toGraphQLDocumentString.test.ts.snap @@ -811,13 +811,13 @@ exports[`other > Query 9`] = ` exports[`union > Query 1`] = ` " { - "fooBarUnion": { + "unionFooBar": { "__typename": true } } -------------- { - fooBarUnion { + unionFooBar { __typename } } @@ -827,7 +827,7 @@ exports[`union > Query 1`] = ` exports[`union > Query 2`] = ` " { - "fooBarUnion": { + "unionFooBar": { "onBar": { "int": true } @@ -835,7 +835,7 @@ exports[`union > Query 2`] = ` } -------------- { - fooBarUnion { + unionFooBar { ... on Bar { int } @@ -847,7 +847,7 @@ exports[`union > Query 2`] = ` exports[`union > Query 3`] = ` " { - "fooBarUnion": { + "unionFooBar": { "onBar": { "$skip": true, "int": true @@ -856,7 +856,7 @@ exports[`union > Query 3`] = ` } -------------- { - fooBarUnion { + unionFooBar { ... on Bar @skip(if: true) { int } diff --git a/src/client/SelectionSet/toGraphQLDocumentString.test.ts b/src/client/SelectionSet/toGraphQLDocumentString.test.ts index 41d554936..ee2e77fa4 100644 --- a/src/client/SelectionSet/toGraphQLDocumentString.test.ts +++ b/src/client/SelectionSet/toGraphQLDocumentString.test.ts @@ -1,6 +1,6 @@ import { parse, print } from 'graphql' import { describe, expect, test } from 'vitest' -import type { Index } from '../../../tests/ts/_/schema/generated/Index.js' +import type { Index } from '../../../tests/_/schema/generated/Index.js' import type { SelectionSet } from './__.js' import { toGraphQLDocumentSelectionSet } from './toGraphQLDocumentString.js' @@ -23,10 +23,10 @@ const prepareResult = (ss: Q) => { describe(`union`, () => { test.each([ - s({ fooBarUnion: { __typename: true } }), - s({ fooBarUnion: { onBar: { int: true } } }), - s({ fooBarUnion: { onBar: { $skip: true, int: true } } }), - // s({ fooBarUnion: { onBar: {} } }), // todo should be static type error + s({ unionFooBar: { __typename: true } }), + s({ unionFooBar: { onBar: { int: true } } }), + s({ unionFooBar: { onBar: { $skip: true, int: true } } }), + // s({ unionFooBar: { onBar: {} } }), // todo should be static type error ])(`Query`, (ss) => { expect(prepareResult(ss)).toMatchSnapshot() }) diff --git a/src/client/client.customScalar.test.ts b/src/client/client.customScalar.test.ts index f9ee42858..b19ddcd61 100644 --- a/src/client/client.customScalar.test.ts +++ b/src/client/client.customScalar.test.ts @@ -1,16 +1,15 @@ /* eslint-disable */ import { beforeEach, describe, expect, test } from 'vitest' import { db } from '../../tests/_/db.js' +import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js' import { setupMockServer } from '../../tests/raw/__helpers.js' -// import type { Index } from '../../tests/ts/_/schema/generated/Index.js' -import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js' import { create } from './client.js' const ctx = setupMockServer() const date0Encoded = db.date0.toISOString() const date1Encoded = db.date1.toISOString() -const client = () => create({ name: 'MigrateMe', schema: ctx.url, schemaIndex }) +const client = () => create({ schema: ctx.url, schemaIndex }) describe(`output`, () => { test(`query field`, async () => { @@ -80,7 +79,6 @@ describe(`input`, () => { }) const clientExpected = (expectedDocument: (document: any) => void) => { const client = create({ - name: 'MigrateMe', schema: ctx.url, schemaIndex, hooks: { diff --git a/src/client/client.returnMode.test-d.ts b/src/client/client.returnMode.test-d.ts index 60dcdccfc..37aa8b0cb 100644 --- a/src/client/client.returnMode.test-d.ts +++ b/src/client/client.returnMode.test-d.ts @@ -3,8 +3,8 @@ import { ExecutionResult } from 'graphql' import { ObjMap } from 'graphql/jsutils/ObjMap.js' import { describe } from 'node:test' import { expectTypeOf, test } from 'vitest' +import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js' import { schema } from '../../tests/_/schema/schema.js' -import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js' import { create } from './client.js' // dprint-ignore diff --git a/src/client/client.test.ts b/src/client/client.test.ts index 9c3f128be..aec3922a7 100644 --- a/src/client/client.test.ts +++ b/src/client/client.test.ts @@ -1,15 +1,14 @@ -/* eslint-disable */ import { expect, test } from 'vitest' +import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js' import { setupMockServer } from '../../tests/raw/__helpers.js' -import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js' import { create } from './client.js' const ctx = setupMockServer() -const data = { fooBarUnion: { int: 1 } } +const data = { unionFooBar: { int: 1 } } -const client = () => create({ name: 'MigrateMe', schema: ctx.url, schemaIndex }) +const client = () => create({ schema: ctx.url, schemaIndex }) test.todo(`query`, async () => { const mockRes = ctx.res({ body: { data } }).spec.body! - expect(await client().query.$batch({ fooBarUnion: { onBar: { int: true } } })).toEqual(mockRes.data) + expect(await client().query.$batch({ unionFooBar: { onBar: { int: true } } })).toEqual(mockRes.data) }) diff --git a/src/generator/__snapshots__/files.test.ts.snap b/src/generator/__snapshots__/files.test.ts.snap index 2eac0f2e7..f1e466b7d 100644 --- a/src/generator/__snapshots__/files.test.ts.snap +++ b/src/generator/__snapshots__/files.test.ts.snap @@ -1,673 +1,5 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`generates types from GraphQL SDL file 1`] = ` -"type Include = Exclude> - -type ObjectWithTypeName = { __typename: string } - -const ErrorObjectsTypeNameSelectedEnum = {} as Record - -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) -} -" -`; - -exports[`generates types from GraphQL SDL file 2`] = ` -"import { ResultSet, SelectionSet } from '../../../../../src/entrypoints/alpha/schema.js' -import { Index } from './Index.js' - -// Root Types -// ---------- - -export type Query<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< - $SelectionSet, - Index, - 'Query' -> - -// Object Types -// ------------ - -export type DateObject1<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index> - -export type DateObject2<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index> - -export type ObjectUnion<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index> - -export type Foo<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Foo'], - Index -> - -export type Bar<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Bar'], - Index -> - -export type ObjectNested<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index> - -export type lowerCaseObject<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index> - -export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index> - -export type Object1<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Object1'], - Index -> - -export type Object1ImplementingInterface< - $SelectionSet extends SelectionSet.Object, -> = ResultSet.Object$<$SelectionSet, Index['objects']['Object1ImplementingInterface'], Index> - -export type Object2ImplementingInterface< - $SelectionSet extends SelectionSet.Object, -> = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index> - -// Union Types -// ----------- - -export type DateUnion<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< - $SelectionSet, - Index['unions']['DateUnion'], - Index -> - -export type FooBarUnion<$SelectionSet extends SelectionSet.Union> = - ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index> - -export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union> = - ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index> - -// Interface Types -// --------------- - -export type DateInterface1<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index> - -export type Interface<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['Interface'], Index> -" -`; - -exports[`generates types from GraphQL SDL file 3`] = ` -"/* eslint-disable */ - -import type * as Schema from './SchemaBuildtime.js' - -export interface Index { - Root: { - Query: Schema.Root.Query - Mutation: null - Subscription: null - } - objects: { - DateObject1: Schema.Object.DateObject1 - DateObject2: Schema.Object.DateObject2 - ObjectUnion: Schema.Object.ObjectUnion - Foo: Schema.Object.Foo - Bar: Schema.Object.Bar - ObjectNested: Schema.Object.ObjectNested - lowerCaseObject: Schema.Object.lowerCaseObject - lowerCaseObject2: Schema.Object.lowerCaseObject2 - Object1: Schema.Object.Object1 - Object1ImplementingInterface: Schema.Object.Object1ImplementingInterface - Object2ImplementingInterface: Schema.Object.Object2ImplementingInterface - } - unions: { - DateUnion: Schema.Union.DateUnion - FooBarUnion: Schema.Union.FooBarUnion - lowerCaseUnion: Schema.Union.lowerCaseUnion - } - interfaces: { - DateInterface1: Schema.Interface.DateInterface1 - Interface: Schema.Interface.Interface - } - error: { - objects: {} - } -} -" -`; - -exports[`generates types from GraphQL SDL file 4`] = ` -"import type * as $ from '../../../../../src/entrypoints/alpha/schema.js' -import type * as $Scalar from './Scalar.ts' - -// ------------------------------------------------------------ // -// Root // -// ------------------------------------------------------------ // - -export namespace Root { - export type Query = $.Object$2<'Query', { - date: $.Field<$.Output.Nullable<$Scalar.Date>, null> - dateNonNull: $.Field<$Scalar.Date, null> - dateList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Date>>>, null> - dateObject1: $.Field<$.Output.Nullable, null> - dateUnion: $.Field<$.Output.Nullable, null> - dateInterface1: $.Field<$.Output.Nullable, null> - dateListNonNull: $.Field<$.Output.List<$Scalar.Date>, null> - dateArg: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $.Input.Nullable<$Scalar.Date> - }> - > - dateArgNonNull: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $Scalar.Date - }> - > - dateArgList: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $.Input.Nullable<$.Input.List<$.Input.Nullable<$Scalar.Date>>> - }> - > - dateArgNonNullList: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $.Input.List<$.Input.Nullable<$Scalar.Date>> - }> - > - dateArgNonNullListNonNull: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $.Input.List<$Scalar.Date> - }> - > - dateArgInputObject: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - input: $.Input.Nullable - }> - > - InputObjectNested: $.Field< - $.Output.Nullable<$Scalar.ID>, - $.Args<{ - input: $.Input.Nullable - }> - > - InputObjectNestedNonNull: $.Field< - $.Output.Nullable<$Scalar.ID>, - $.Args<{ - input: InputObject.InputObjectNested - }> - > - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - idNonNull: $.Field<$Scalar.ID, null> - string: $.Field<$.Output.Nullable<$Scalar.String>, null> - stringWithRequiredArg: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - string: $Scalar.String - }> - > - stringWithArgs: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - string: $.Input.Nullable<$Scalar.String> - int: $.Input.Nullable<$Scalar.Int> - float: $.Input.Nullable<$Scalar.Float> - boolean: $.Input.Nullable<$Scalar.Boolean> - id: $.Input.Nullable<$Scalar.ID> - }> - > - stringWithArgEnum: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - ABCEnum: $.Input.Nullable - }> - > - stringWithListArg: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - ints: $.Input.Nullable<$.Input.List<$.Input.Nullable<$Scalar.Int>>> - }> - > - stringWithListArgRequired: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - ints: $.Input.List<$.Input.Nullable<$Scalar.Int>> - }> - > - stringWithArgInputObject: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - input: $.Input.Nullable - }> - > - stringWithArgInputObjectRequired: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - input: InputObject.InputObject - }> - > - listListIntNonNull: $.Field<$.Output.List<$.Output.List<$Scalar.Int>>, null> - listListInt: $.Field< - $.Output.Nullable<$.Output.List<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>>>, - null - > - listInt: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>, null> - listIntNonNull: $.Field<$.Output.List<$Scalar.Int>, null> - object: $.Field<$.Output.Nullable, null> - objectNonNull: $.Field - objectNested: $.Field<$.Output.Nullable, null> - objectWithArgs: $.Field< - $.Output.Nullable, - $.Args<{ - string: $.Input.Nullable<$Scalar.String> - int: $.Input.Nullable<$Scalar.Int> - float: $.Input.Nullable<$Scalar.Float> - boolean: $.Input.Nullable<$Scalar.Boolean> - id: $.Input.Nullable<$Scalar.ID> - }> - > - fooBarUnion: $.Field<$.Output.Nullable, null> - objectList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable>>, null> - objectListNonNull: $.Field<$.Output.List, null> - /** - * Query enum field documentation. - */ - abcEnum: $.Field<$.Output.Nullable, null> - lowerCaseUnion: $.Field<$.Output.Nullable, null> - interface: $.Field<$.Output.Nullable, null> - interfaceWithArgs: $.Field< - $.Output.Nullable, - $.Args<{ - id: $Scalar.ID - }> - > - interfaceNonNull: $.Field - unionFooBar: $.Field<$.Output.Nullable, null> - unionFooBarWithArgs: $.Field< - $.Output.Nullable, - $.Args<{ - id: $.Input.Nullable<$Scalar.ID> - }> - > - unionObject: $.Field<$.Output.Nullable, null> - unionFooBarNonNull: $.Field - unionObjectNonNull: $.Field - }> -} - -// ------------------------------------------------------------ // -// Enum // -// ------------------------------------------------------------ // - -export namespace Enum { - /** - * Enum documentation. - * - * Members - * "A" - (DEPRECATED: Enum value A is deprecated.) - * "B" - Enum B member documentation. - * "C" - Enum C member documentation. (DEPRECATED: Enum value C is deprecated.) - */ - export type ABCEnum = $.Enum<'ABCEnum', ['A', 'B', 'C']> -} - -// ------------------------------------------------------------ // -// InputObject // -// ------------------------------------------------------------ // - -export namespace InputObject { - export type InputObjectNested = $.InputObject<'InputObjectNested', { - InputObject: $.Input.Nullable - }> - - export type InputObjectNestedNonNull = $.InputObject<'InputObjectNestedNonNull', { - InputObject: InputObject.InputObject - }> - - export type InputObject = $.InputObject<'InputObject', { - id: $.Input.Nullable<$Scalar.ID> - idRequired: $Scalar.ID - date: $.Input.Nullable<$Scalar.Date> - dateRequired: $Scalar.Date - }> -} - -// ------------------------------------------------------------ // -// Interface // -// ------------------------------------------------------------ // - -export namespace Interface { - export type DateInterface1 = $.Interface<'DateInterface1', { - date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> - }, [Object.DateObject1]> - - export type Interface = $.Interface<'Interface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - }, [Object.Object1ImplementingInterface, Object.Object2ImplementingInterface]> -} - -// ------------------------------------------------------------ // -// Object // -// ------------------------------------------------------------ // - -export namespace Object { - export type DateObject1 = $.Object$2<'DateObject1', { - date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> - }> - - export type DateObject2 = $.Object$2<'DateObject2', { - date2: $.Field<$.Output.Nullable<$Scalar.Date>, null> - }> - - export type ObjectUnion = $.Object$2<'ObjectUnion', { - fooBarUnion: $.Field<$.Output.Nullable, null> - }> - - /** - * Object documentation. - */ - export type Foo = $.Object$2<'Foo', { - /** - * Field documentation. - * - * @deprecated Field a is deprecated. - */ - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - }> - - export type Bar = $.Object$2<'Bar', { - int: $.Field<$.Output.Nullable<$Scalar.Int>, null> - }> - - export type ObjectNested = $.Object$2<'ObjectNested', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - object: $.Field<$.Output.Nullable, null> - }> - - export type lowerCaseObject = $.Object$2<'lowerCaseObject', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - }> - - export type lowerCaseObject2 = $.Object$2<'lowerCaseObject2', { - int: $.Field<$.Output.Nullable<$Scalar.Int>, null> - }> - - export type Object1 = $.Object$2<'Object1', { - string: $.Field<$.Output.Nullable<$Scalar.String>, null> - int: $.Field<$.Output.Nullable<$Scalar.Int>, null> - float: $.Field<$.Output.Nullable<$Scalar.Float>, null> - boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - }> - - export type Object1ImplementingInterface = $.Object$2<'Object1ImplementingInterface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - int: $.Field<$.Output.Nullable<$Scalar.Int>, null> - }> - - export type Object2ImplementingInterface = $.Object$2<'Object2ImplementingInterface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> - }> -} - -// ------------------------------------------------------------ // -// Union // -// ------------------------------------------------------------ // - -export namespace Union { - export type DateUnion = $.Union<'DateUnion', [Object.DateObject1, Object.DateObject2]> - - /** - * Union documentation. - */ - export type FooBarUnion = $.Union<'FooBarUnion', [Object.Foo, Object.Bar]> - - export type lowerCaseUnion = $.Union<'lowerCaseUnion', [Object.lowerCaseObject, Object.lowerCaseObject2]> -} -" -`; - -exports[`generates types from GraphQL SDL file 5`] = ` -"export * from '../../../../../src/Schema/Hybrid/types/Scalar/Scalar.js' -export * from '../../../../_/customScalarCodecs.js' -" -`; - -exports[`generates types from GraphQL SDL file 6`] = ` -"/* eslint-disable */ - -import * as $ from '../../../../../src/entrypoints/alpha/schema.js' -import * as $Scalar from './Scalar.js' - -export const ABCEnum = $.Enum(\`ABCEnum\`, [\`A\`, \`B\`, \`C\`]) - -export const InputObjectNested = $.InputObject(\`InputObjectNested\`, { - InputObject: $.Input.field(() => $.Input.Nullable(InputObject)), -}) - -export const InputObjectNestedNonNull = $.InputObject(\`InputObjectNestedNonNull\`, { - InputObject: $.Input.field(() => InputObject), -}) - -export const InputObject = $.InputObject(\`InputObject\`, { - id: $.Input.field($.Input.Nullable($Scalar.ID)), - idRequired: $.Input.field($Scalar.ID), - date: $.Input.field($.Input.Nullable($Scalar.Date)), - dateRequired: $.Input.field($Scalar.Date), -}) - -// @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 DateObject1 = $.Object$(\`DateObject1\`, { - date1: $.field($.Output.Nullable($Scalar.Date)), -}) - -// @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 DateObject2 = $.Object$(\`DateObject2\`, { - date2: $.field($.Output.Nullable($Scalar.Date)), -}) - -// @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 ObjectUnion = $.Object$(\`ObjectUnion\`, { - fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), -}) - -// @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 Foo = $.Object$(\`Foo\`, { - id: $.field($.Output.Nullable($Scalar.ID)), -}) - -// @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 Bar = $.Object$(\`Bar\`, { - int: $.field($.Output.Nullable($Scalar.Int)), -}) - -// @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 ObjectNested = $.Object$(\`ObjectNested\`, { - id: $.field($.Output.Nullable($Scalar.ID)), - object: $.field($.Output.Nullable(() => Object1)), -}) - -// @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 lowerCaseObject = $.Object$(\`lowerCaseObject\`, { - id: $.field($.Output.Nullable($Scalar.ID)), -}) - -// @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 lowerCaseObject2 = $.Object$(\`lowerCaseObject2\`, { - int: $.field($.Output.Nullable($Scalar.Int)), -}) - -// @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 Object1 = $.Object$(\`Object1\`, { - string: $.field($.Output.Nullable($Scalar.String)), - int: $.field($.Output.Nullable($Scalar.Int)), - float: $.field($.Output.Nullable($Scalar.Float)), - boolean: $.field($.Output.Nullable($Scalar.Boolean)), - id: $.field($.Output.Nullable($Scalar.ID)), -}) - -// @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 Object1ImplementingInterface = $.Object$(\`Object1ImplementingInterface\`, { - id: $.field($.Output.Nullable($Scalar.ID)), - int: $.field($.Output.Nullable($Scalar.Int)), -}) - -// @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 Object2ImplementingInterface = $.Object$(\`Object2ImplementingInterface\`, { - id: $.field($.Output.Nullable($Scalar.ID)), - boolean: $.field($.Output.Nullable($Scalar.Boolean)), -}) - -// @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 DateUnion = $.Union(\`DateUnion\`, [DateObject1, DateObject2]) - -// @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 FooBarUnion = $.Union(\`FooBarUnion\`, [Foo, Bar]) - -// @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 lowerCaseUnion = $.Union(\`lowerCaseUnion\`, [lowerCaseObject, lowerCaseObject2]) - -export const DateInterface1 = $.Interface(\`DateInterface1\`, { date1: $.field($.Output.Nullable($Scalar.Date)) }, [ - DateObject1, -]) -export const Interface = $.Interface(\`Interface\`, { id: $.field($.Output.Nullable($Scalar.ID)) }, [ - Object1ImplementingInterface, - Object2ImplementingInterface, -]) - -// @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 Query = $.Object$(\`Query\`, { - date: $.field($.Output.Nullable($Scalar.Date)), - dateNonNull: $.field($Scalar.Date), - dateList: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Date)))), - dateObject1: $.field($.Output.Nullable(() => DateObject1)), - dateUnion: $.field($.Output.Nullable(() => DateUnion)), - dateInterface1: $.field($.Output.Nullable(() => DateInterface1)), - dateListNonNull: $.field($.Output.List($Scalar.Date)), - dateArg: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.Nullable($Scalar.Date) })), - dateArgNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $Scalar.Date })), - dateArgList: $.field( - $.Output.Nullable($Scalar.Date), - $.Args({ date: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Date))) }), - ), - dateArgNonNullList: $.field( - $.Output.Nullable($Scalar.Date), - $.Args({ date: $.Input.List($.Input.Nullable($Scalar.Date)) }), - ), - dateArgNonNullListNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.List($Scalar.Date) })), - dateArgInputObject: $.field($.Output.Nullable($Scalar.Date), $.Args({ input: $.Input.Nullable(InputObject) })), - InputObjectNested: $.field($.Output.Nullable($Scalar.ID), $.Args({ input: $.Input.Nullable(InputObjectNested) })), - InputObjectNestedNonNull: $.field($.Output.Nullable($Scalar.ID), $.Args({ input: InputObjectNested })), - id: $.field($.Output.Nullable($Scalar.ID)), - idNonNull: $.field($Scalar.ID), - string: $.field($.Output.Nullable($Scalar.String)), - stringWithRequiredArg: $.field($.Output.Nullable($Scalar.String), $.Args({ string: $Scalar.String })), - stringWithArgs: $.field( - $.Output.Nullable($Scalar.String), - $.Args({ - string: $.Input.Nullable($Scalar.String), - int: $.Input.Nullable($Scalar.Int), - float: $.Input.Nullable($Scalar.Float), - boolean: $.Input.Nullable($Scalar.Boolean), - id: $.Input.Nullable($Scalar.ID), - }), - ), - stringWithArgEnum: $.field($.Output.Nullable($Scalar.String), $.Args({ ABCEnum: $.Input.Nullable(ABCEnum) })), - stringWithListArg: $.field( - $.Output.Nullable($Scalar.String), - $.Args({ ints: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Int))) }), - ), - stringWithListArgRequired: $.field( - $.Output.Nullable($Scalar.String), - $.Args({ ints: $.Input.List($.Input.Nullable($Scalar.Int)) }), - ), - stringWithArgInputObject: $.field( - $.Output.Nullable($Scalar.String), - $.Args({ input: $.Input.Nullable(InputObject) }), - ), - stringWithArgInputObjectRequired: $.field($.Output.Nullable($Scalar.String), $.Args({ input: InputObject })), - listListIntNonNull: $.field($.Output.List($.Output.List($Scalar.Int))), - listListInt: $.field( - $.Output.Nullable($.Output.List($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int))))), - ), - listInt: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int)))), - listIntNonNull: $.field($.Output.List($Scalar.Int)), - object: $.field($.Output.Nullable(() => Object1)), - objectNonNull: $.field(() => Object1), - objectNested: $.field($.Output.Nullable(() => ObjectNested)), - objectWithArgs: $.field( - $.Output.Nullable(() => Object1), - $.Args({ - string: $.Input.Nullable($Scalar.String), - int: $.Input.Nullable($Scalar.Int), - float: $.Input.Nullable($Scalar.Float), - boolean: $.Input.Nullable($Scalar.Boolean), - id: $.Input.Nullable($Scalar.ID), - }), - ), - fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), - objectList: $.field($.Output.Nullable($.Output.List($.Output.Nullable(() => Object1)))), - objectListNonNull: $.field($.Output.List(() => Object1)), - abcEnum: $.field($.Output.Nullable(ABCEnum)), - lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)), - interface: $.field($.Output.Nullable(() => Interface)), - interfaceWithArgs: $.field($.Output.Nullable(() => Interface), $.Args({ id: $Scalar.ID })), - interfaceNonNull: $.field(() => Interface), - unionFooBar: $.field($.Output.Nullable(() => FooBarUnion)), - unionFooBarWithArgs: $.field($.Output.Nullable(() => FooBarUnion), $.Args({ id: $.Input.Nullable($Scalar.ID) })), - unionObject: $.field($.Output.Nullable(() => ObjectUnion)), - unionFooBarNonNull: $.field(() => FooBarUnion), - unionObjectNonNull: $.field(() => ObjectUnion), -}) - -export const $Index = { - Root: { - Query, - Mutation: null, - Subscription: null, - }, - objects: { - DateObject1, - DateObject2, - ObjectUnion, - Foo, - Bar, - ObjectNested, - lowerCaseObject, - lowerCaseObject2, - Object1, - Object1ImplementingInterface, - Object2ImplementingInterface, - }, - unions: { - DateUnion, - FooBarUnion, - lowerCaseUnion, - }, - interfaces: { - DateInterface1, - Interface, - }, - error: { - objects: {}, - }, -} -" -`; - exports[`schema2 1`] = ` "type Include = Exclude> @@ -720,6 +52,9 @@ export type Bar<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index> +export type DateObject2<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index> + export type ErrorOne<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$<$SelectionSet, Index['objects']['ErrorOne'], Index> @@ -746,9 +81,27 @@ export type Object2ImplementingInterface< $SelectionSet extends SelectionSet.Object, > = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index> +export type ObjectNested<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index> + +export type ObjectUnion<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index> + +export type lowerCaseObject<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index> + +export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index> + // Union Types // ----------- +export type DateUnion<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< + $SelectionSet, + Index['unions']['DateUnion'], + Index +> + export type FooBarUnion<$SelectionSet extends SelectionSet.Union> = ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index> @@ -758,9 +111,15 @@ export type Result<$SelectionSet extends SelectionSet.Union +export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union> = + ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index> + // Interface Types // --------------- +export type DateInterface1<$SelectionSet extends SelectionSet.Interface> = + ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index> + export type Error<$SelectionSet extends SelectionSet.Interface> = ResultSet.Interface<$SelectionSet, Index['interfaces']['Error'], Index> @@ -783,18 +142,26 @@ export interface Index { objects: { Bar: Schema.Object.Bar DateObject1: Schema.Object.DateObject1 + DateObject2: Schema.Object.DateObject2 ErrorOne: Schema.Object.ErrorOne ErrorTwo: Schema.Object.ErrorTwo Foo: Schema.Object.Foo Object1: Schema.Object.Object1 Object1ImplementingInterface: Schema.Object.Object1ImplementingInterface Object2ImplementingInterface: Schema.Object.Object2ImplementingInterface + ObjectNested: Schema.Object.ObjectNested + ObjectUnion: Schema.Object.ObjectUnion + lowerCaseObject: Schema.Object.lowerCaseObject + lowerCaseObject2: Schema.Object.lowerCaseObject2 } unions: { + DateUnion: Schema.Union.DateUnion FooBarUnion: Schema.Union.FooBarUnion Result: Schema.Union.Result + lowerCaseUnion: Schema.Union.lowerCaseUnion } interfaces: { + DateInterface1: Schema.Interface.DateInterface1 Error: Schema.Interface.Error Interface: Schema.Interface.Interface } @@ -823,11 +190,39 @@ export namespace Root { }> export type Query = $.Object$2<'Query', { + InputObjectNested: $.Field< + $.Output.Nullable<$Scalar.ID>, + $.Args<{ + input: $.Input.Nullable + }> + > + InputObjectNestedNonNull: $.Field< + $.Output.Nullable<$Scalar.ID>, + $.Args<{ + input: InputObject.InputObjectNestedNonNull + }> + > + /** + * Query enum field documentation. + */ + abcEnum: $.Field<$.Output.Nullable, null> date: $.Field<$.Output.Nullable<$Scalar.Date>, null> dateArg: $.Field< $.Output.Nullable<$Scalar.Date>, $.Args<{ - date: $.Input.Nullable<$Scalar.Date> + date: $.Input.Nullable<$Scalar.Date> + }> + > + dateArgInputObject: $.Field< + $.Output.Nullable<$Scalar.Date>, + $.Args<{ + input: $.Input.Nullable + }> + > + dateArgList: $.Field< + $.Output.Nullable<$Scalar.Date>, + $.Args<{ + date: $.Input.Nullable<$.Input.List<$Scalar.Date>> }> > dateArgNonNull: $.Field< @@ -836,11 +231,47 @@ export namespace Root { date: $Scalar.Date }> > + dateArgNonNullList: $.Field< + $.Output.Nullable<$Scalar.Date>, + $.Args<{ + date: $.Input.List<$.Input.Nullable<$Scalar.Date>> + }> + > + dateArgNonNullListNonNull: $.Field< + $.Output.Nullable<$Scalar.Date>, + $.Args<{ + date: $.Input.List<$Scalar.Date> + }> + > + dateInterface1: $.Field<$.Output.Nullable, null> + dateList: $.Field<$.Output.Nullable<$.Output.List<$Scalar.Date>>, null> + dateListNonNull: $.Field<$.Output.List<$Scalar.Date>, null> dateNonNull: $.Field<$Scalar.Date, null> dateObject1: $.Field<$.Output.Nullable, null> + dateUnion: $.Field<$.Output.Nullable, null> id: $.Field<$.Output.Nullable<$Scalar.ID>, null> idNonNull: $.Field<$Scalar.ID, null> interface: $.Field<$.Output.Nullable, null> + interfaceNonNull: $.Field + interfaceWithArgs: $.Field< + $.Output.Nullable, + $.Args<{ + id: $Scalar.ID + }> + > + listInt: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>, null> + listIntNonNull: $.Field<$.Output.List<$Scalar.Int>, null> + listListInt: $.Field< + $.Output.Nullable<$.Output.List<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>>>, + null + > + listListIntNonNull: $.Field<$.Output.List<$.Output.List<$Scalar.Int>>, null> + lowerCaseUnion: $.Field<$.Output.Nullable, null> + object: $.Field<$.Output.Nullable, null> + objectList: $.Field<$.Output.Nullable<$.Output.List>, null> + objectListNonNull: $.Field<$.Output.List, null> + objectNested: $.Field<$.Output.Nullable, null> + objectNonNull: $.Field objectWithArgs: $.Field< $.Output.Nullable, $.Args<{ @@ -857,7 +288,63 @@ export namespace Root { case: Enum.Case }> > + string: $.Field<$.Output.Nullable<$Scalar.String>, null> + stringWithArgEnum: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + ABCEnum: $.Input.Nullable + }> + > + stringWithArgInputObject: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + input: $.Input.Nullable + }> + > + stringWithArgInputObjectRequired: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + input: InputObject.InputObject + }> + > + stringWithArgs: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + boolean: $.Input.Nullable<$Scalar.Boolean> + float: $.Input.Nullable<$Scalar.Float> + id: $.Input.Nullable<$Scalar.ID> + int: $.Input.Nullable<$Scalar.Int> + string: $.Input.Nullable<$Scalar.String> + }> + > + stringWithListArg: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + ints: $.Input.Nullable<$.Input.List<$.Input.Nullable<$Scalar.Int>>> + }> + > + stringWithListArgRequired: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + ints: $.Input.List<$Scalar.Int> + }> + > + stringWithRequiredArg: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + string: $Scalar.String + }> + > unionFooBar: $.Field<$.Output.Nullable, null> + unionFooBarNonNull: $.Field + unionFooBarWithArgs: $.Field< + $.Output.Nullable, + $.Args<{ + id: $.Input.Nullable<$Scalar.ID> + }> + > + unionObject: $.Field<$.Output.Nullable, null> + unionObjectNonNull: $.Field }> } @@ -866,6 +353,16 @@ export namespace Root { // ------------------------------------------------------------ // export namespace Enum { + /** + * Enum documentation. + * + * Members + * "A" - (DEPRECATED: Enum value A is deprecated.) + * "B" - Enum B member documentation. + * "C" - (DEPRECATED: Enum value C is deprecated.) + */ + export type ABCEnum = $.Enum<'ABCEnum', ['A', 'B', 'C']> + export type Case = $.Enum<'Case', ['ErrorOne', 'ErrorTwo', 'Object1']> } @@ -874,7 +371,20 @@ export namespace Enum { // ------------------------------------------------------------ // export namespace InputObject { - // -- no types -- + export type InputObject = $.InputObject<'InputObject', { + date: $.Input.Nullable<$Scalar.Date> + dateRequired: $Scalar.Date + id: $.Input.Nullable<$Scalar.ID> + idRequired: $Scalar.ID + }> + + export type InputObjectNested = $.InputObject<'InputObjectNested', { + InputObject: $.Input.Nullable + }> + + export type InputObjectNestedNonNull = $.InputObject<'InputObjectNestedNonNull', { + InputObject: InputObject.InputObject + }> } // ------------------------------------------------------------ // @@ -882,6 +392,10 @@ export namespace InputObject { // ------------------------------------------------------------ // export namespace Interface { + export type DateInterface1 = $.Interface<'DateInterface1', { + date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> + }, [Object.DateObject1]> + export type Error = $.Interface<'Error', { message: $.Field<$Scalar.String, null> }, [Object.ErrorOne, Object.ErrorTwo]> @@ -904,6 +418,10 @@ export namespace Object { date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> }> + export type DateObject2 = $.Object$2<'DateObject2', { + date2: $.Field<$.Output.Nullable<$Scalar.Date>, null> + }> + export type ErrorOne = $.Object$2<'ErrorOne', { infoId: $.Field<$.Output.Nullable<$Scalar.ID>, null> message: $.Field<$Scalar.String, null> @@ -943,6 +461,23 @@ export namespace Object { boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }> + + export type ObjectNested = $.Object$2<'ObjectNested', { + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + object: $.Field<$.Output.Nullable, null> + }> + + export type ObjectUnion = $.Object$2<'ObjectUnion', { + fooBarUnion: $.Field<$.Output.Nullable, null> + }> + + export type lowerCaseObject = $.Object$2<'lowerCaseObject', { + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + }> + + export type lowerCaseObject2 = $.Object$2<'lowerCaseObject2', { + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> + }> } // ------------------------------------------------------------ // @@ -950,12 +485,16 @@ export namespace Object { // ------------------------------------------------------------ // export namespace Union { + export type DateUnion = $.Union<'DateUnion', [Object.DateObject1, Object.DateObject2]> + /** * Union documentation. */ export type FooBarUnion = $.Union<'FooBarUnion', [Object.Bar, Object.Foo]> export type Result = $.Union<'Result', [Object.ErrorOne, Object.ErrorTwo, Object.Object1]> + + export type lowerCaseUnion = $.Union<'lowerCaseUnion', [Object.lowerCaseObject, Object.lowerCaseObject2]> } " `; @@ -972,8 +511,24 @@ exports[`schema2 6`] = ` import * as $ from '../../../../src/entrypoints/alpha/schema.js' import * as $Scalar from './Scalar.js' +export const ABCEnum = $.Enum(\`ABCEnum\`, [\`A\`, \`B\`, \`C\`]) export const Case = $.Enum(\`Case\`, [\`ErrorOne\`, \`ErrorTwo\`, \`Object1\`]) +export const InputObject = $.InputObject(\`InputObject\`, { + date: $.Input.field($.Input.Nullable($Scalar.Date)), + dateRequired: $.Input.field($Scalar.Date), + id: $.Input.field($.Input.Nullable($Scalar.ID)), + idRequired: $.Input.field($Scalar.ID), +}) + +export const InputObjectNested = $.InputObject(\`InputObjectNested\`, { + InputObject: $.Input.field(() => $.Input.Nullable(InputObject)), +}) + +export const InputObjectNestedNonNull = $.InputObject(\`InputObjectNestedNonNull\`, { + InputObject: $.Input.field(() => InputObject), +}) + // @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 Bar = $.Object$(\`Bar\`, { int: $.field($.Output.Nullable($Scalar.Int)), @@ -984,6 +539,11 @@ export const DateObject1 = $.Object$(\`DateObject1\`, { date1: $.field($.Output.Nullable($Scalar.Date)), }) +// @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 DateObject2 = $.Object$(\`DateObject2\`, { + date2: $.field($.Output.Nullable($Scalar.Date)), +}) + // @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 ErrorOne = $.Object$(\`ErrorOne\`, { infoId: $.field($.Output.Nullable($Scalar.ID)), @@ -1022,12 +582,42 @@ export const Object2ImplementingInterface = $.Object$(\`Object2ImplementingInter id: $.field($.Output.Nullable($Scalar.ID)), }) +// @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 ObjectNested = $.Object$(\`ObjectNested\`, { + id: $.field($.Output.Nullable($Scalar.ID)), + object: $.field($.Output.Nullable(() => Object1)), +}) + +// @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 ObjectUnion = $.Object$(\`ObjectUnion\`, { + fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), +}) + +// @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 lowerCaseObject = $.Object$(\`lowerCaseObject\`, { + id: $.field($.Output.Nullable($Scalar.ID)), +}) + +// @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 lowerCaseObject2 = $.Object$(\`lowerCaseObject2\`, { + int: $.field($.Output.Nullable($Scalar.Int)), +}) + +// @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 DateUnion = $.Union(\`DateUnion\`, [DateObject1, DateObject2]) + // @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 FooBarUnion = $.Union(\`FooBarUnion\`, [Bar, Foo]) // @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 Result = $.Union(\`Result\`, [ErrorOne, ErrorTwo, Object1]) +// @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 lowerCaseUnion = $.Union(\`lowerCaseUnion\`, [lowerCaseObject, lowerCaseObject2]) + +export const DateInterface1 = $.Interface(\`DateInterface1\`, { date1: $.field($.Output.Nullable($Scalar.Date)) }, [ + DateObject1, +]) export const Error = $.Interface(\`Error\`, { message: $.field($Scalar.String) }, [ErrorOne, ErrorTwo]) export const Interface = $.Interface(\`Interface\`, { id: $.field($.Output.Nullable($Scalar.ID)) }, [ Object1ImplementingInterface, @@ -1042,14 +632,42 @@ export const Mutation = $.Object$(\`Mutation\`, { // @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 Query = $.Object$(\`Query\`, { + InputObjectNested: $.field($.Output.Nullable($Scalar.ID), $.Args({ input: $.Input.Nullable(InputObjectNested) })), + InputObjectNestedNonNull: $.field($.Output.Nullable($Scalar.ID), $.Args({ input: InputObjectNestedNonNull })), + abcEnum: $.field($.Output.Nullable(ABCEnum)), date: $.field($.Output.Nullable($Scalar.Date)), dateArg: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.Nullable($Scalar.Date) })), + dateArgInputObject: $.field($.Output.Nullable($Scalar.Date), $.Args({ input: $.Input.Nullable(InputObject) })), + dateArgList: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.Nullable($.Input.List($Scalar.Date)) })), dateArgNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $Scalar.Date })), + dateArgNonNullList: $.field( + $.Output.Nullable($Scalar.Date), + $.Args({ date: $.Input.List($.Input.Nullable($Scalar.Date)) }), + ), + dateArgNonNullListNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.List($Scalar.Date) })), + dateInterface1: $.field($.Output.Nullable(() => DateInterface1)), + dateList: $.field($.Output.Nullable($.Output.List($Scalar.Date))), + dateListNonNull: $.field($.Output.List($Scalar.Date)), dateNonNull: $.field($Scalar.Date), dateObject1: $.field($.Output.Nullable(() => DateObject1)), + dateUnion: $.field($.Output.Nullable(() => DateUnion)), id: $.field($.Output.Nullable($Scalar.ID)), idNonNull: $.field($Scalar.ID), interface: $.field($.Output.Nullable(() => Interface)), + interfaceNonNull: $.field(() => Interface), + interfaceWithArgs: $.field($.Output.Nullable(() => Interface), $.Args({ id: $Scalar.ID })), + listInt: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int)))), + listIntNonNull: $.field($.Output.List($Scalar.Int)), + listListInt: $.field( + $.Output.Nullable($.Output.List($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int))))), + ), + listListIntNonNull: $.field($.Output.List($.Output.List($Scalar.Int))), + lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)), + object: $.field($.Output.Nullable(() => Object1)), + objectList: $.field($.Output.Nullable($.Output.List(() => Object1))), + objectListNonNull: $.field($.Output.List(() => Object1)), + objectNested: $.field($.Output.Nullable(() => ObjectNested)), + objectNonNull: $.field(() => Object1), objectWithArgs: $.field( $.Output.Nullable(() => Object1), $.Args({ @@ -1061,7 +679,34 @@ export const Query = $.Object$(\`Query\`, { }), ), result: $.field($.Output.Nullable(() => Result), $.Args({ case: Case })), + string: $.field($.Output.Nullable($Scalar.String)), + stringWithArgEnum: $.field($.Output.Nullable($Scalar.String), $.Args({ ABCEnum: $.Input.Nullable(ABCEnum) })), + stringWithArgInputObject: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ input: $.Input.Nullable(InputObject) }), + ), + stringWithArgInputObjectRequired: $.field($.Output.Nullable($Scalar.String), $.Args({ input: InputObject })), + stringWithArgs: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ + boolean: $.Input.Nullable($Scalar.Boolean), + float: $.Input.Nullable($Scalar.Float), + id: $.Input.Nullable($Scalar.ID), + int: $.Input.Nullable($Scalar.Int), + string: $.Input.Nullable($Scalar.String), + }), + ), + stringWithListArg: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ ints: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Int))) }), + ), + stringWithListArgRequired: $.field($.Output.Nullable($Scalar.String), $.Args({ ints: $.Input.List($Scalar.Int) })), + stringWithRequiredArg: $.field($.Output.Nullable($Scalar.String), $.Args({ string: $Scalar.String })), unionFooBar: $.field($.Output.Nullable(() => FooBarUnion)), + unionFooBarNonNull: $.field(() => FooBarUnion), + unionFooBarWithArgs: $.field($.Output.Nullable(() => FooBarUnion), $.Args({ id: $.Input.Nullable($Scalar.ID) })), + unionObject: $.field($.Output.Nullable(() => ObjectUnion)), + unionObjectNonNull: $.field(() => ObjectUnion), }) export const $Index = { @@ -1073,18 +718,26 @@ export const $Index = { objects: { Bar, DateObject1, + DateObject2, ErrorOne, ErrorTwo, Foo, Object1, Object1ImplementingInterface, Object2ImplementingInterface, + ObjectNested, + ObjectUnion, + lowerCaseObject, + lowerCaseObject2, }, unions: { + DateUnion, FooBarUnion, Result, + lowerCaseUnion, }, interfaces: { + DateInterface1, Error, Interface, }, diff --git a/src/generator/files.test.ts b/src/generator/files.test.ts index 810d01731..9191c7a78 100644 --- a/src/generator/files.test.ts +++ b/src/generator/files.test.ts @@ -1,27 +1,6 @@ import { readFile } from 'fs/promises' import { expect, test } from 'vitest' -test(`generates types from GraphQL SDL file`, async () => { - expect( - await readFile(`./tests/ts/_/schema/generated/Error.ts`, `utf8`), - ).toMatchSnapshot() - expect( - await readFile(`./tests/ts/_/schema/generated/Select.ts`, `utf8`), - ).toMatchSnapshot() - expect( - await readFile(`./tests/ts/_/schema/generated/Index.ts`, `utf8`), - ).toMatchSnapshot() - expect( - await readFile(`./tests/ts/_/schema/generated/SchemaBuildtime.ts`, `utf8`), - ).toMatchSnapshot() - expect( - await readFile(`./tests/ts/_/schema/generated/Scalar.ts`, `utf8`), - ).toMatchSnapshot() - expect( - await readFile(`./tests/ts/_/schema/generated/SchemaRuntime.ts`, `utf8`), - ).toMatchSnapshot() -}) - test(`schema2`, async () => { expect( await readFile(`./tests/_/schema/generated/Error.ts`, `utf8`), diff --git a/tests/_/db.ts b/tests/_/db.ts index 047a8cb4f..225f071ee 100644 --- a/tests/_/db.ts +++ b/tests/_/db.ts @@ -1,22 +1,57 @@ +const date0 = new Date(0) + +const id = `abc` + +const int = 123 + +const string = `hi` + +const float = 123.456 + +const boolean = true + +const Object1 = { + string, + int, + float, + boolean, + id, +} + +const Foo = { + id, +} + export const db = { - ErrorOne: { message: `errorOne`, infoId: `abc` }, - ErrorTwo: { message: `errorOne`, infoInt: 123 }, - int: 123, - id: `abc`, - id1: `abc`, + lowerCaseObject: { + id, + }, + lowerCaseObject2: { + int, + }, + Interface: { id }, + ABCEnum: `A`, + ErrorOne: { message: `errorOne`, infoId: id }, + ErrorTwo: { message: `errorOne`, infoInt: int }, + int, + id, + id1: id, + string, date0: new Date(0), date1: new Date(1), - foo: { - id: `abc`, + Foo, + Bar: { + int, }, - bar: { - int: 123, + Object1, + ObjectNested: { + id, + nested: Object1, }, - Object1: { - string: `abc`, - int: 123, - float: 123.456, - boolean: true, - id: `abc`, + ObjectUnion: { + fooBarUnion: Foo, }, -} + DateInterface1: { + date1: date0, + }, +} as const diff --git a/tests/_/schema/generated/Index.ts b/tests/_/schema/generated/Index.ts index c11d0b086..e5b51a663 100644 --- a/tests/_/schema/generated/Index.ts +++ b/tests/_/schema/generated/Index.ts @@ -11,18 +11,26 @@ export interface Index { objects: { Bar: Schema.Object.Bar DateObject1: Schema.Object.DateObject1 + DateObject2: Schema.Object.DateObject2 ErrorOne: Schema.Object.ErrorOne ErrorTwo: Schema.Object.ErrorTwo Foo: Schema.Object.Foo Object1: Schema.Object.Object1 Object1ImplementingInterface: Schema.Object.Object1ImplementingInterface Object2ImplementingInterface: Schema.Object.Object2ImplementingInterface + ObjectNested: Schema.Object.ObjectNested + ObjectUnion: Schema.Object.ObjectUnion + lowerCaseObject: Schema.Object.lowerCaseObject + lowerCaseObject2: Schema.Object.lowerCaseObject2 } unions: { + DateUnion: Schema.Union.DateUnion FooBarUnion: Schema.Union.FooBarUnion Result: Schema.Union.Result + lowerCaseUnion: Schema.Union.lowerCaseUnion } interfaces: { + DateInterface1: Schema.Interface.DateInterface1 Error: Schema.Interface.Error Interface: Schema.Interface.Interface } diff --git a/tests/_/schema/generated/SchemaBuildtime.ts b/tests/_/schema/generated/SchemaBuildtime.ts index 139c7739f..f4bda1e7e 100644 --- a/tests/_/schema/generated/SchemaBuildtime.ts +++ b/tests/_/schema/generated/SchemaBuildtime.ts @@ -12,6 +12,22 @@ export namespace Root { }> export type Query = $.Object$2<'Query', { + InputObjectNested: $.Field< + $.Output.Nullable<$Scalar.ID>, + $.Args<{ + input: $.Input.Nullable + }> + > + InputObjectNestedNonNull: $.Field< + $.Output.Nullable<$Scalar.ID>, + $.Args<{ + input: InputObject.InputObjectNestedNonNull + }> + > + /** + * Query enum field documentation. + */ + abcEnum: $.Field<$.Output.Nullable, null> date: $.Field<$.Output.Nullable<$Scalar.Date>, null> dateArg: $.Field< $.Output.Nullable<$Scalar.Date>, @@ -19,17 +35,65 @@ export namespace Root { date: $.Input.Nullable<$Scalar.Date> }> > + dateArgInputObject: $.Field< + $.Output.Nullable<$Scalar.Date>, + $.Args<{ + input: $.Input.Nullable + }> + > + dateArgList: $.Field< + $.Output.Nullable<$Scalar.Date>, + $.Args<{ + date: $.Input.Nullable<$.Input.List<$Scalar.Date>> + }> + > dateArgNonNull: $.Field< $.Output.Nullable<$Scalar.Date>, $.Args<{ date: $Scalar.Date }> > + dateArgNonNullList: $.Field< + $.Output.Nullable<$Scalar.Date>, + $.Args<{ + date: $.Input.List<$.Input.Nullable<$Scalar.Date>> + }> + > + dateArgNonNullListNonNull: $.Field< + $.Output.Nullable<$Scalar.Date>, + $.Args<{ + date: $.Input.List<$Scalar.Date> + }> + > + dateInterface1: $.Field<$.Output.Nullable, null> + dateList: $.Field<$.Output.Nullable<$.Output.List<$Scalar.Date>>, null> + dateListNonNull: $.Field<$.Output.List<$Scalar.Date>, null> dateNonNull: $.Field<$Scalar.Date, null> dateObject1: $.Field<$.Output.Nullable, null> + dateUnion: $.Field<$.Output.Nullable, null> id: $.Field<$.Output.Nullable<$Scalar.ID>, null> idNonNull: $.Field<$Scalar.ID, null> interface: $.Field<$.Output.Nullable, null> + interfaceNonNull: $.Field + interfaceWithArgs: $.Field< + $.Output.Nullable, + $.Args<{ + id: $Scalar.ID + }> + > + listInt: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>, null> + listIntNonNull: $.Field<$.Output.List<$Scalar.Int>, null> + listListInt: $.Field< + $.Output.Nullable<$.Output.List<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>>>, + null + > + listListIntNonNull: $.Field<$.Output.List<$.Output.List<$Scalar.Int>>, null> + lowerCaseUnion: $.Field<$.Output.Nullable, null> + object: $.Field<$.Output.Nullable, null> + objectList: $.Field<$.Output.Nullable<$.Output.List>, null> + objectListNonNull: $.Field<$.Output.List, null> + objectNested: $.Field<$.Output.Nullable, null> + objectNonNull: $.Field objectWithArgs: $.Field< $.Output.Nullable, $.Args<{ @@ -46,7 +110,63 @@ export namespace Root { case: Enum.Case }> > + string: $.Field<$.Output.Nullable<$Scalar.String>, null> + stringWithArgEnum: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + ABCEnum: $.Input.Nullable + }> + > + stringWithArgInputObject: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + input: $.Input.Nullable + }> + > + stringWithArgInputObjectRequired: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + input: InputObject.InputObject + }> + > + stringWithArgs: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + boolean: $.Input.Nullable<$Scalar.Boolean> + float: $.Input.Nullable<$Scalar.Float> + id: $.Input.Nullable<$Scalar.ID> + int: $.Input.Nullable<$Scalar.Int> + string: $.Input.Nullable<$Scalar.String> + }> + > + stringWithListArg: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + ints: $.Input.Nullable<$.Input.List<$.Input.Nullable<$Scalar.Int>>> + }> + > + stringWithListArgRequired: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + ints: $.Input.List<$Scalar.Int> + }> + > + stringWithRequiredArg: $.Field< + $.Output.Nullable<$Scalar.String>, + $.Args<{ + string: $Scalar.String + }> + > unionFooBar: $.Field<$.Output.Nullable, null> + unionFooBarNonNull: $.Field + unionFooBarWithArgs: $.Field< + $.Output.Nullable, + $.Args<{ + id: $.Input.Nullable<$Scalar.ID> + }> + > + unionObject: $.Field<$.Output.Nullable, null> + unionObjectNonNull: $.Field }> } @@ -55,6 +175,16 @@ export namespace Root { // ------------------------------------------------------------ // export namespace Enum { + /** + * Enum documentation. + * + * Members + * "A" - (DEPRECATED: Enum value A is deprecated.) + * "B" - Enum B member documentation. + * "C" - (DEPRECATED: Enum value C is deprecated.) + */ + export type ABCEnum = $.Enum<'ABCEnum', ['A', 'B', 'C']> + export type Case = $.Enum<'Case', ['ErrorOne', 'ErrorTwo', 'Object1']> } @@ -63,7 +193,20 @@ export namespace Enum { // ------------------------------------------------------------ // export namespace InputObject { - // -- no types -- + export type InputObject = $.InputObject<'InputObject', { + date: $.Input.Nullable<$Scalar.Date> + dateRequired: $Scalar.Date + id: $.Input.Nullable<$Scalar.ID> + idRequired: $Scalar.ID + }> + + export type InputObjectNested = $.InputObject<'InputObjectNested', { + InputObject: $.Input.Nullable + }> + + export type InputObjectNestedNonNull = $.InputObject<'InputObjectNestedNonNull', { + InputObject: InputObject.InputObject + }> } // ------------------------------------------------------------ // @@ -71,6 +214,10 @@ export namespace InputObject { // ------------------------------------------------------------ // export namespace Interface { + export type DateInterface1 = $.Interface<'DateInterface1', { + date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> + }, [Object.DateObject1]> + export type Error = $.Interface<'Error', { message: $.Field<$Scalar.String, null> }, [Object.ErrorOne, Object.ErrorTwo]> @@ -93,6 +240,10 @@ export namespace Object { date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> }> + export type DateObject2 = $.Object$2<'DateObject2', { + date2: $.Field<$.Output.Nullable<$Scalar.Date>, null> + }> + export type ErrorOne = $.Object$2<'ErrorOne', { infoId: $.Field<$.Output.Nullable<$Scalar.ID>, null> message: $.Field<$Scalar.String, null> @@ -132,6 +283,23 @@ export namespace Object { boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }> + + export type ObjectNested = $.Object$2<'ObjectNested', { + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + object: $.Field<$.Output.Nullable, null> + }> + + export type ObjectUnion = $.Object$2<'ObjectUnion', { + fooBarUnion: $.Field<$.Output.Nullable, null> + }> + + export type lowerCaseObject = $.Object$2<'lowerCaseObject', { + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + }> + + export type lowerCaseObject2 = $.Object$2<'lowerCaseObject2', { + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> + }> } // ------------------------------------------------------------ // @@ -139,10 +307,14 @@ export namespace Object { // ------------------------------------------------------------ // export namespace Union { + export type DateUnion = $.Union<'DateUnion', [Object.DateObject1, Object.DateObject2]> + /** * Union documentation. */ export type FooBarUnion = $.Union<'FooBarUnion', [Object.Bar, Object.Foo]> export type Result = $.Union<'Result', [Object.ErrorOne, Object.ErrorTwo, Object.Object1]> + + export type lowerCaseUnion = $.Union<'lowerCaseUnion', [Object.lowerCaseObject, Object.lowerCaseObject2]> } diff --git a/tests/_/schema/generated/SchemaRuntime.ts b/tests/_/schema/generated/SchemaRuntime.ts index 48a57ea97..55f64efb2 100644 --- a/tests/_/schema/generated/SchemaRuntime.ts +++ b/tests/_/schema/generated/SchemaRuntime.ts @@ -3,8 +3,24 @@ import * as $ from '../../../../src/entrypoints/alpha/schema.js' import * as $Scalar from './Scalar.js' +export const ABCEnum = $.Enum(`ABCEnum`, [`A`, `B`, `C`]) export const Case = $.Enum(`Case`, [`ErrorOne`, `ErrorTwo`, `Object1`]) +export const InputObject = $.InputObject(`InputObject`, { + date: $.Input.field($.Input.Nullable($Scalar.Date)), + dateRequired: $.Input.field($Scalar.Date), + id: $.Input.field($.Input.Nullable($Scalar.ID)), + idRequired: $.Input.field($Scalar.ID), +}) + +export const InputObjectNested = $.InputObject(`InputObjectNested`, { + InputObject: $.Input.field(() => $.Input.Nullable(InputObject)), +}) + +export const InputObjectNestedNonNull = $.InputObject(`InputObjectNestedNonNull`, { + InputObject: $.Input.field(() => InputObject), +}) + // @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 Bar = $.Object$(`Bar`, { int: $.field($.Output.Nullable($Scalar.Int)), @@ -15,6 +31,11 @@ export const DateObject1 = $.Object$(`DateObject1`, { date1: $.field($.Output.Nullable($Scalar.Date)), }) +// @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 DateObject2 = $.Object$(`DateObject2`, { + date2: $.field($.Output.Nullable($Scalar.Date)), +}) + // @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 ErrorOne = $.Object$(`ErrorOne`, { infoId: $.field($.Output.Nullable($Scalar.ID)), @@ -53,12 +74,42 @@ export const Object2ImplementingInterface = $.Object$(`Object2ImplementingInterf id: $.field($.Output.Nullable($Scalar.ID)), }) +// @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 ObjectNested = $.Object$(`ObjectNested`, { + id: $.field($.Output.Nullable($Scalar.ID)), + object: $.field($.Output.Nullable(() => Object1)), +}) + +// @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 ObjectUnion = $.Object$(`ObjectUnion`, { + fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), +}) + +// @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 lowerCaseObject = $.Object$(`lowerCaseObject`, { + id: $.field($.Output.Nullable($Scalar.ID)), +}) + +// @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 lowerCaseObject2 = $.Object$(`lowerCaseObject2`, { + int: $.field($.Output.Nullable($Scalar.Int)), +}) + +// @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 DateUnion = $.Union(`DateUnion`, [DateObject1, DateObject2]) + // @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 FooBarUnion = $.Union(`FooBarUnion`, [Bar, Foo]) // @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 Result = $.Union(`Result`, [ErrorOne, ErrorTwo, Object1]) +// @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 lowerCaseUnion = $.Union(`lowerCaseUnion`, [lowerCaseObject, lowerCaseObject2]) + +export const DateInterface1 = $.Interface(`DateInterface1`, { date1: $.field($.Output.Nullable($Scalar.Date)) }, [ + DateObject1, +]) export const Error = $.Interface(`Error`, { message: $.field($Scalar.String) }, [ErrorOne, ErrorTwo]) export const Interface = $.Interface(`Interface`, { id: $.field($.Output.Nullable($Scalar.ID)) }, [ Object1ImplementingInterface, @@ -73,14 +124,42 @@ export const Mutation = $.Object$(`Mutation`, { // @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 Query = $.Object$(`Query`, { + InputObjectNested: $.field($.Output.Nullable($Scalar.ID), $.Args({ input: $.Input.Nullable(InputObjectNested) })), + InputObjectNestedNonNull: $.field($.Output.Nullable($Scalar.ID), $.Args({ input: InputObjectNestedNonNull })), + abcEnum: $.field($.Output.Nullable(ABCEnum)), date: $.field($.Output.Nullable($Scalar.Date)), dateArg: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.Nullable($Scalar.Date) })), + dateArgInputObject: $.field($.Output.Nullable($Scalar.Date), $.Args({ input: $.Input.Nullable(InputObject) })), + dateArgList: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.Nullable($.Input.List($Scalar.Date)) })), dateArgNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $Scalar.Date })), + dateArgNonNullList: $.field( + $.Output.Nullable($Scalar.Date), + $.Args({ date: $.Input.List($.Input.Nullable($Scalar.Date)) }), + ), + dateArgNonNullListNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.List($Scalar.Date) })), + dateInterface1: $.field($.Output.Nullable(() => DateInterface1)), + dateList: $.field($.Output.Nullable($.Output.List($Scalar.Date))), + dateListNonNull: $.field($.Output.List($Scalar.Date)), dateNonNull: $.field($Scalar.Date), dateObject1: $.field($.Output.Nullable(() => DateObject1)), + dateUnion: $.field($.Output.Nullable(() => DateUnion)), id: $.field($.Output.Nullable($Scalar.ID)), idNonNull: $.field($Scalar.ID), interface: $.field($.Output.Nullable(() => Interface)), + interfaceNonNull: $.field(() => Interface), + interfaceWithArgs: $.field($.Output.Nullable(() => Interface), $.Args({ id: $Scalar.ID })), + listInt: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int)))), + listIntNonNull: $.field($.Output.List($Scalar.Int)), + listListInt: $.field( + $.Output.Nullable($.Output.List($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int))))), + ), + listListIntNonNull: $.field($.Output.List($.Output.List($Scalar.Int))), + lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)), + object: $.field($.Output.Nullable(() => Object1)), + objectList: $.field($.Output.Nullable($.Output.List(() => Object1))), + objectListNonNull: $.field($.Output.List(() => Object1)), + objectNested: $.field($.Output.Nullable(() => ObjectNested)), + objectNonNull: $.field(() => Object1), objectWithArgs: $.field( $.Output.Nullable(() => Object1), $.Args({ @@ -92,7 +171,34 @@ export const Query = $.Object$(`Query`, { }), ), result: $.field($.Output.Nullable(() => Result), $.Args({ case: Case })), + string: $.field($.Output.Nullable($Scalar.String)), + stringWithArgEnum: $.field($.Output.Nullable($Scalar.String), $.Args({ ABCEnum: $.Input.Nullable(ABCEnum) })), + stringWithArgInputObject: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ input: $.Input.Nullable(InputObject) }), + ), + stringWithArgInputObjectRequired: $.field($.Output.Nullable($Scalar.String), $.Args({ input: InputObject })), + stringWithArgs: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ + boolean: $.Input.Nullable($Scalar.Boolean), + float: $.Input.Nullable($Scalar.Float), + id: $.Input.Nullable($Scalar.ID), + int: $.Input.Nullable($Scalar.Int), + string: $.Input.Nullable($Scalar.String), + }), + ), + stringWithListArg: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ ints: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Int))) }), + ), + stringWithListArgRequired: $.field($.Output.Nullable($Scalar.String), $.Args({ ints: $.Input.List($Scalar.Int) })), + stringWithRequiredArg: $.field($.Output.Nullable($Scalar.String), $.Args({ string: $Scalar.String })), unionFooBar: $.field($.Output.Nullable(() => FooBarUnion)), + unionFooBarNonNull: $.field(() => FooBarUnion), + unionFooBarWithArgs: $.field($.Output.Nullable(() => FooBarUnion), $.Args({ id: $.Input.Nullable($Scalar.ID) })), + unionObject: $.field($.Output.Nullable(() => ObjectUnion)), + unionObjectNonNull: $.field(() => ObjectUnion), }) export const $Index = { @@ -104,18 +210,26 @@ export const $Index = { objects: { Bar, DateObject1, + DateObject2, ErrorOne, ErrorTwo, Foo, Object1, Object1ImplementingInterface, Object2ImplementingInterface, + ObjectNested, + ObjectUnion, + lowerCaseObject, + lowerCaseObject2, }, unions: { + DateUnion, FooBarUnion, Result, + lowerCaseUnion, }, interfaces: { + DateInterface1, Error, Interface, }, diff --git a/tests/_/schema/generated/Select.ts b/tests/_/schema/generated/Select.ts index 61e6e78a6..9f39d8356 100644 --- a/tests/_/schema/generated/Select.ts +++ b/tests/_/schema/generated/Select.ts @@ -28,6 +28,9 @@ export type Bar<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index> +export type DateObject2<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index> + export type ErrorOne<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$<$SelectionSet, Index['objects']['ErrorOne'], Index> @@ -54,9 +57,27 @@ export type Object2ImplementingInterface< $SelectionSet extends SelectionSet.Object, > = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index> +export type ObjectNested<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index> + +export type ObjectUnion<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index> + +export type lowerCaseObject<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index> + +export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index> + // Union Types // ----------- +export type DateUnion<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< + $SelectionSet, + Index['unions']['DateUnion'], + Index +> + export type FooBarUnion<$SelectionSet extends SelectionSet.Union> = ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index> @@ -66,9 +87,15 @@ export type Result<$SelectionSet extends SelectionSet.Union +export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union> = + ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index> + // Interface Types // --------------- +export type DateInterface1<$SelectionSet extends SelectionSet.Interface> = + ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index> + export type Error<$SelectionSet extends SelectionSet.Interface> = ResultSet.Interface<$SelectionSet, Index['interfaces']['Error'], Index> diff --git a/tests/_/schema/schema.graphql b/tests/_/schema/schema.graphql index 41a570fcf..a6856912b 100644 --- a/tests/_/schema/schema.graphql +++ b/tests/_/schema/schema.graphql @@ -1,3 +1,12 @@ +"""Enum documentation.""" +enum ABCEnum { + A @deprecated(reason: "Enum value A is deprecated.") + + """Enum B member documentation.""" + B + C @deprecated(reason: "Enum value C is deprecated.") +} + type Bar { int: Int } @@ -13,10 +22,20 @@ A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `dat """ scalar Date -type DateObject1 { +interface DateInterface1 { + date1: Date +} + +type DateObject1 implements DateInterface1 { date1: Date } +type DateObject2 { + date2: Date +} + +union DateUnion = DateObject1 | DateObject2 + interface Error { message: String! } @@ -40,6 +59,21 @@ type Foo { """Union documentation.""" union FooBarUnion = Bar | Foo +input InputObject { + date: Date + dateRequired: Date! + id: ID + idRequired: ID! +} + +input InputObjectNested { + InputObject: InputObject +} + +input InputObjectNestedNonNull { + InputObject: InputObject! +} + interface Interface { id: ID } @@ -67,18 +101,74 @@ type Object2ImplementingInterface implements Interface { id: ID } +type ObjectNested { + id: ID + object: Object1 +} + +type ObjectUnion { + fooBarUnion: FooBarUnion +} + type Query { + InputObjectNested(input: InputObjectNested): ID + InputObjectNestedNonNull(input: InputObjectNestedNonNull!): ID + + """Query enum field documentation.""" + abcEnum: ABCEnum date: Date dateArg(date: Date): Date + dateArgInputObject(input: InputObject): Date + dateArgList(date: [Date!]): Date dateArgNonNull(date: Date!): Date + dateArgNonNullList(date: [Date]!): Date + dateArgNonNullListNonNull(date: [Date!]!): Date + dateInterface1: DateInterface1 + dateList: [Date!] + dateListNonNull: [Date!]! dateNonNull: Date! dateObject1: DateObject1 + dateUnion: DateUnion id: ID idNonNull: ID! interface: Interface + interfaceNonNull: Interface! + interfaceWithArgs(id: ID!): Interface + listInt: [Int] + listIntNonNull: [Int!]! + listListInt: [[Int]] + listListIntNonNull: [[Int!]!]! + lowerCaseUnion: lowerCaseUnion + object: Object1 + objectList: [Object1!] + objectListNonNull: [Object1!]! + objectNested: ObjectNested + objectNonNull: Object1! objectWithArgs(boolean: Boolean, float: Float, id: ID, int: Int, string: String): Object1 result(case: Case!): Result + string: String + stringWithArgEnum(ABCEnum: ABCEnum): String + stringWithArgInputObject(input: InputObject): String + stringWithArgInputObjectRequired(input: InputObject!): String + stringWithArgs(boolean: Boolean, float: Float, id: ID, int: Int, string: String): String + stringWithListArg(ints: [Int]): String + stringWithListArgRequired(ints: [Int!]!): String + stringWithRequiredArg(string: String!): String unionFooBar: FooBarUnion + unionFooBarNonNull: FooBarUnion! + unionFooBarWithArgs(id: ID): FooBarUnion + unionObject: ObjectUnion + unionObjectNonNull: ObjectUnion! +} + +union Result = ErrorOne | ErrorTwo | Object1 + +type lowerCaseObject { + id: ID +} + +type lowerCaseObject2 { + int: Int } -union Result = ErrorOne | ErrorTwo | Object1 \ No newline at end of file +union lowerCaseUnion = lowerCaseObject | lowerCaseObject2 \ No newline at end of file diff --git a/tests/_/schema/schema.ts b/tests/_/schema/schema.ts index 9140b75d5..52bc65469 100644 --- a/tests/_/schema/schema.ts +++ b/tests/_/schema/schema.ts @@ -1,3 +1,5 @@ +// TODO test case for recursive input objects +// import SchemaBuilder from '@pothos/core' import SimpleObjectsPlugin from '@pothos/plugin-simple-objects' import { DateTimeISOResolver } from 'graphql-scalars' @@ -7,26 +9,40 @@ import type { ID } from './generated/Scalar.js' const builder = new SchemaBuilder<{ DefaultFieldNullability: true Scalars: { - Date: SchemaBuilderTypeDate + Date: { + Input: Date + Output: Date + } } }>({ defaultFieldNullability: true, plugins: [SimpleObjectsPlugin], }) -export type SchemaBuilderTypeDate = { - Input: Date - Output: Date -} - builder.addScalarType(`Date`, DateTimeISOResolver, {}) +const DateInterface1 = builder.simpleInterface(`DateInterface1`, { + fields: t => ({ + date1: t.field({ type: `Date` }), + }), + resolveType: value => { + if (`date1` in value) return `DateObject1` + throw new Error(`Cannot resolve type`) + }, +}) const DateObject1 = builder.simpleObject(`DateObject1`, { + interfaces: [DateInterface1], fields: t => ({ date1: t.field({ type: `Date` }), }), }) +const DateObject2 = builder.simpleObject(`DateObject2`, { + fields: t => ({ + date2: t.field({ type: `Date` }), + }), +}) + const Object1 = builder.simpleObject(`Object1`, { fields: t => ({ string: t.string(), @@ -121,19 +137,98 @@ const Result = builder.unionType(`Result`, { const ResultCase = builder.enumType(`Case`, { values: [`Object1`, `ErrorOne`, `ErrorTwo`] as const }) +const DateUnion = builder.unionType(`DateUnion`, { + types: [DateObject1, DateObject2], + resolveType: value => { + return `date1` in value ? `DateObject1` : `DateObject2` + }, +}) + +const InputObject = builder.inputType(`InputObject`, { + fields: t => ({ + id: t.id(), + idRequired: t.id({ required: true }), + date: t.field({ type: `Date` }), + dateRequired: t.field({ type: `Date`, required: true }), + }), +}) + +const InputObjectNested = builder.inputType(`InputObjectNested`, { + fields: t => ({ + InputObject: t.field({ type: InputObject }), + }), +}) + +const InputObjectNestedNonNull = builder.inputType(`InputObjectNestedNonNull`, { + fields: t => ({ + InputObject: t.field({ type: InputObject, required: true }), + }), +}) + +const ABCEnum = builder.enumType(`ABCEnum`, { + description: `Enum documentation.`, + values: { + A: { + deprecationReason: `Enum value A is deprecated.`, + }, + B: { + description: `Enum B member documentation.`, + }, + C: { + deprecationReason: `Enum value C is deprecated.`, + }, + }, +}) + +const ObjectNested = builder.simpleObject(`ObjectNested`, { + fields: t => ({ + id: t.field({ type: `ID` }), + object: t.field({ type: Object1 }), + }), +}) + +const lowerCaseObject = builder.simpleObject(`lowerCaseObject`, { + fields: t => ({ + id: t.id(), + }), +}) +const lowerCaseObject2 = builder.simpleObject(`lowerCaseObject2`, { + fields: t => ({ + int: t.int(), + }), +}) +const lowerCaseUnion = builder.unionType(`lowerCaseUnion`, { + types: [lowerCaseObject, lowerCaseObject2], + resolveType: value => { + return `int` in value ? `lowerCaseObject2` : `lowerCaseObject` + }, +}) +const ObjectUnion = builder.simpleObject(`ObjectUnion`, { + fields: t => ({ + fooBarUnion: t.field({ type: FooBarUnion }), + }), +}) + builder.queryType({ fields: t => ({ - result: t.field({ - args: { case: t.arg({ type: ResultCase, required: true }) }, - type: Result, - resolve: (_, args) => { - return db[args.case] - }, - }), // Custom Scalar date: t.field({ type: `Date`, resolve: () => db.date0 }), dateNonNull: t.field({ nullable: false, type: `Date`, resolve: () => db.date0 }), + dateList: t.field({ + type: t.listRef(`Date`), + resolve: () => [db.date0, db.date1], + }), dateObject1: t.field({ type: DateObject1, resolve: () => ({ date1: db.date0 }) }), + dateUnion: t.field({ type: DateUnion, resolve: () => ({ date1: db.date0 }) }), + dateInterface1: t.field({ + type: DateInterface1, + resolve: () => ({ date1: db.date0 }), + }), + dateListNonNull: t.field({ + nullable: false, + type: t.listRef(`Date`, { nullable: false }), + resolve: () => [db.date0, db.date1], + }), dateArg: t.field({ type: `Date`, args: { date: t.arg({ type: `Date` }) }, @@ -144,6 +239,125 @@ builder.queryType({ args: { date: t.arg({ required: true, type: `Date` }) }, resolve: (_, args) => args.date, }), + dateArgList: t.field({ + type: `Date`, + args: { date: t.arg({ type: t.arg.listRef(`Date`) }) }, + resolve: (_, args) => args.date?.[0] ?? db.date0, + }), + dateArgNonNullList: t.field({ + type: `Date`, + args: { date: t.arg({ required: true, type: t.arg.listRef(`Date`, { required: false }) }) }, + resolve: (_, args) => args.date[0] ?? db.date0, + }), + dateArgNonNullListNonNull: t.field({ + type: `Date`, + args: { date: t.arg({ required: true, type: t.arg.listRef(`Date`, { required: true }) }) }, + resolve: (_, args) => args.date[0] ?? db.date0, + }), + dateArgInputObject: t.field({ + type: `Date`, + args: { input: t.arg({ type: InputObject }) }, + resolve: (_, args) => args.input?.date ?? db.date0, + }), + // Input Object + // Note: It is important that the type `InputObjectNested` is defined before `InputObject` in the generated runtime schema. + // This is to force the case of needing a thunk, to make sure our tests for it are actually testing the case. + InputObjectNested: t.field({ + type: `ID`, + args: { input: t.arg({ type: InputObjectNested }) }, + resolve: (_, args) => args.input?.InputObject?.id ?? db.id1, + }), + InputObjectNestedNonNull: t.field({ + type: `ID`, + args: { input: t.arg({ type: InputObjectNestedNonNull, required: true }) }, + resolve: (_, args) => args.input.InputObject.idRequired, + }), + // Scalar + id: t.id({ resolve: () => db.id1 }), + idNonNull: t.id({ nullable: false, resolve: () => db.id1 }), + string: t.string({ resolve: () => db.string }), + stringWithRequiredArg: t.field({ + type: `String`, + args: { string: t.arg.string({ required: true }) }, + resolve: (_, args) => args.string, + }), + stringWithArgs: t.field({ + type: `String`, + args: { + string: t.arg.string(), + int: t.arg.int(), + float: t.arg.float(), + boolean: t.arg.boolean(), + id: t.arg.id(), + }, + resolve: (_, args) => { + return JSON.stringify(args) + }, + }), + stringWithArgEnum: t.field({ + type: `String`, + args: { ABCEnum: t.arg({ type: ABCEnum }) }, + resolve: (_, args) => args.ABCEnum, + }), + stringWithListArg: t.field({ + type: `String`, + args: { ints: t.arg({ type: t.arg.listRef(`Int`, { required: false }) }) }, + resolve: (_, args) => JSON.stringify(args), + }), + stringWithListArgRequired: t.field({ + type: `String`, + args: { ints: t.arg({ type: t.arg.listRef(`Int`), required: true }) }, + resolve: (_, args) => JSON.stringify(args), + }), + stringWithArgInputObject: t.field({ + type: `String`, + args: { input: t.arg({ type: InputObject }) }, + resolve: (_, args) => JSON.stringify(args), + }), + stringWithArgInputObjectRequired: t.field({ + type: `String`, + args: { input: t.arg({ type: InputObject, required: true }) }, + resolve: (_, args) => JSON.stringify(args), + }), + // List Scalar + listListIntNonNull: t.field({ + nullable: false, + type: t.listRef(t.listRef(`Int`, { nullable: false }), { nullable: false }), + resolve: () => [[1], [2]], + }), + listListInt: t.field({ + type: t.listRef(t.listRef(`Int`, { nullable: true }), { nullable: true }), + resolve: () => [[1], [2]], + }), + listInt: t.field({ + type: t.listRef(`Int`, { nullable: true }), + resolve: () => [1, 2], + }), + listIntNonNull: t.field({ + nullable: false, + type: t.listRef(`Int`, { nullable: false }), + resolve: () => [1, 2], + }), + // Enum + abcEnum: t.field({ + type: ABCEnum, + description: `Query enum field documentation.`, + resolve: () => db.ABCEnum, + }), + // Object + object: t.field({ + type: Object1, + resolve: () => db.Object1, + }), + objectNonNull: t.field({ + type: Object1, + nullable: false, + resolve: () => db.Object1, + }), + objectNested: t.field({ + type: ObjectNested, + resolve: () => db.ObjectNested, + }), objectWithArgs: t.field({ args: { string: t.arg.string(), @@ -155,18 +369,56 @@ builder.queryType({ type: Object1, resolve: (_, args) => ({ ...db.Object1, ...args }), }), + // Object List + objectList: t.field({ + type: t.listRef(Object1), + resolve: () => [db.Object1], + }), + objectListNonNull: t.field({ + nullable: false, + type: t.listRef(Object1, { nullable: false }), + resolve: () => [db.Object1], + }), + // Interface interface: t.field({ type: Interface, resolve: () => ({ - id: db.id, + ...db.Interface, int: db.int, }), }), - // ... - id: t.id({ resolve: () => db.id1 }), - idNonNull: t.id({ nullable: false, resolve: () => db.id1 }), - // union - unionFooBar: t.field({ type: FooBarUnion, resolve: () => db.foo }), + interfaceNonNull: t.field({ + type: Interface, + nullable: false, + resolve: () => ({ + ...db.Interface, + int: db.int, + }), + }), + interfaceWithArgs: t.field({ + type: Interface, + args: { id: t.arg.id({ required: true }) }, + resolve: (_, args) => ({ id: args.id }), + }), + // Union + lowerCaseUnion: t.field({ type: lowerCaseUnion, resolve: () => db.lowerCaseObject }), + unionFooBar: t.field({ type: FooBarUnion, resolve: () => db.Foo }), + unionFooBarNonNull: t.field({ type: FooBarUnion, nullable: false, resolve: () => db.Foo }), + unionFooBarWithArgs: t.field({ + args: { id: t.arg.id() }, + type: FooBarUnion, + resolve: () => db.Foo, + }), + unionObject: t.field({ type: ObjectUnion, resolve: () => db.ObjectUnion }), + unionObjectNonNull: t.field({ type: ObjectUnion, nullable: false, resolve: () => db.ObjectUnion }), + // Result + result: t.field({ + args: { case: t.arg({ type: ResultCase, required: true }) }, + type: Result, + resolve: (_, args) => { + return db[args.case] + }, + }), }), }) diff --git a/tests/_/schemaGenerate.ts b/tests/_/schemaGenerate.ts index d97d985b5..623b51f66 100644 --- a/tests/_/schemaGenerate.ts +++ b/tests/_/schemaGenerate.ts @@ -48,16 +48,3 @@ await generate({ outputSchemaPath: `./tests/_/schema/schema.graphql`, options: { errorTypeNamePattern: /^Error.+/ }, }) - -await generateFiles({ - name: `MigrateMe`, - sourceDirPath: `./tests/ts/_/schema`, - sourceCustomScalarCodecsFilePath: join(`./tests/_/customScalarCodecs.ts`), - outputDirPath: `./tests/ts/_/schema/generated`, - code: { - libraryPaths: { - schema: `../../../../../src/entrypoints/alpha/schema.js`, - scalars: `../../../../../src/Schema/Hybrid/types/Scalar/Scalar.js`, - }, - }, -}) diff --git a/tests/_/schemaMutationOnly/generated/Global.ts b/tests/_/schemaMutationOnly/generated/Global.ts index d68ac9b52..057e83abb 100644 --- a/tests/_/schemaMutationOnly/generated/Global.ts +++ b/tests/_/schemaMutationOnly/generated/Global.ts @@ -1,7 +1,5 @@ import { Index } from './Index.js' -import type * as CustomScalar from '../../customScalarCodecs.js' - declare global { interface NamedSchemas { MutationOnly: { diff --git a/tests/_/schemaQueryOnly/generated/Global.ts b/tests/_/schemaQueryOnly/generated/Global.ts index 25bd03e9f..3c68df87b 100644 --- a/tests/_/schemaQueryOnly/generated/Global.ts +++ b/tests/_/schemaQueryOnly/generated/Global.ts @@ -1,7 +1,5 @@ import { Index } from './Index.js' -import type * as CustomScalar from '../../customScalarCodecs.js' - declare global { interface NamedSchemas { QueryOnly: { diff --git a/tests/ts/_/schema/generated/Error.ts b/tests/ts/_/schema/generated/Error.ts deleted file mode 100644 index 6a480e85c..000000000 --- a/tests/ts/_/schema/generated/Error.ts +++ /dev/null @@ -1,14 +0,0 @@ -type Include = Exclude> - -type ObjectWithTypeName = { __typename: string } - -const ErrorObjectsTypeNameSelectedEnum = {} as Record - -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) -} diff --git a/tests/ts/_/schema/generated/Global.ts b/tests/ts/_/schema/generated/Global.ts deleted file mode 100644 index 0f6846edf..000000000 --- a/tests/ts/_/schema/generated/Global.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Index } from './Index.js' - -import type * as CustomScalar from '../../../../_/customScalarCodecs.js' - -declare global { - interface NamedSchemas { - MigrateMe: { - index: Index - customScalars: { - Date: CustomScalar.Date - } - } - } -} diff --git a/tests/ts/_/schema/generated/Index.ts b/tests/ts/_/schema/generated/Index.ts deleted file mode 100644 index 259ef4c2f..000000000 --- a/tests/ts/_/schema/generated/Index.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint-disable */ - -import type * as Schema from './SchemaBuildtime.js' - -export interface Index { - Root: { - Query: Schema.Root.Query - Mutation: null - Subscription: null - } - objects: { - DateObject1: Schema.Object.DateObject1 - DateObject2: Schema.Object.DateObject2 - ObjectUnion: Schema.Object.ObjectUnion - Foo: Schema.Object.Foo - Bar: Schema.Object.Bar - ObjectNested: Schema.Object.ObjectNested - lowerCaseObject: Schema.Object.lowerCaseObject - lowerCaseObject2: Schema.Object.lowerCaseObject2 - Object1: Schema.Object.Object1 - Object1ImplementingInterface: Schema.Object.Object1ImplementingInterface - Object2ImplementingInterface: Schema.Object.Object2ImplementingInterface - } - unions: { - DateUnion: Schema.Union.DateUnion - FooBarUnion: Schema.Union.FooBarUnion - lowerCaseUnion: Schema.Union.lowerCaseUnion - } - interfaces: { - DateInterface1: Schema.Interface.DateInterface1 - Interface: Schema.Interface.Interface - } - error: { - objects: {} - } -} diff --git a/tests/ts/_/schema/generated/Scalar.ts b/tests/ts/_/schema/generated/Scalar.ts deleted file mode 100644 index 2a0b8ac80..000000000 --- a/tests/ts/_/schema/generated/Scalar.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from '../../../../../src/Schema/Hybrid/types/Scalar/Scalar.js' -export * from '../../../../_/customScalarCodecs.js' diff --git a/tests/ts/_/schema/generated/SchemaBuildtime.ts b/tests/ts/_/schema/generated/SchemaBuildtime.ts deleted file mode 100644 index 3a5bd1a55..000000000 --- a/tests/ts/_/schema/generated/SchemaBuildtime.ts +++ /dev/null @@ -1,292 +0,0 @@ -import type * as $ from '../../../../../src/entrypoints/alpha/schema.js' -import type * as $Scalar from './Scalar.ts' - -// ------------------------------------------------------------ // -// Root // -// ------------------------------------------------------------ // - -export namespace Root { - export type Query = $.Object$2<'Query', { - date: $.Field<$.Output.Nullable<$Scalar.Date>, null> - dateNonNull: $.Field<$Scalar.Date, null> - dateList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Date>>>, null> - dateObject1: $.Field<$.Output.Nullable, null> - dateUnion: $.Field<$.Output.Nullable, null> - dateInterface1: $.Field<$.Output.Nullable, null> - dateListNonNull: $.Field<$.Output.List<$Scalar.Date>, null> - dateArg: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $.Input.Nullable<$Scalar.Date> - }> - > - dateArgNonNull: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $Scalar.Date - }> - > - dateArgList: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $.Input.Nullable<$.Input.List<$.Input.Nullable<$Scalar.Date>>> - }> - > - dateArgNonNullList: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $.Input.List<$.Input.Nullable<$Scalar.Date>> - }> - > - dateArgNonNullListNonNull: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - date: $.Input.List<$Scalar.Date> - }> - > - dateArgInputObject: $.Field< - $.Output.Nullable<$Scalar.Date>, - $.Args<{ - input: $.Input.Nullable - }> - > - InputObjectNested: $.Field< - $.Output.Nullable<$Scalar.ID>, - $.Args<{ - input: $.Input.Nullable - }> - > - InputObjectNestedNonNull: $.Field< - $.Output.Nullable<$Scalar.ID>, - $.Args<{ - input: InputObject.InputObjectNested - }> - > - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - idNonNull: $.Field<$Scalar.ID, null> - string: $.Field<$.Output.Nullable<$Scalar.String>, null> - stringWithRequiredArg: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - string: $Scalar.String - }> - > - stringWithArgs: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - string: $.Input.Nullable<$Scalar.String> - int: $.Input.Nullable<$Scalar.Int> - float: $.Input.Nullable<$Scalar.Float> - boolean: $.Input.Nullable<$Scalar.Boolean> - id: $.Input.Nullable<$Scalar.ID> - }> - > - stringWithArgEnum: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - ABCEnum: $.Input.Nullable - }> - > - stringWithListArg: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - ints: $.Input.Nullable<$.Input.List<$.Input.Nullable<$Scalar.Int>>> - }> - > - stringWithListArgRequired: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - ints: $.Input.List<$.Input.Nullable<$Scalar.Int>> - }> - > - stringWithArgInputObject: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - input: $.Input.Nullable - }> - > - stringWithArgInputObjectRequired: $.Field< - $.Output.Nullable<$Scalar.String>, - $.Args<{ - input: InputObject.InputObject - }> - > - listListIntNonNull: $.Field<$.Output.List<$.Output.List<$Scalar.Int>>, null> - listListInt: $.Field< - $.Output.Nullable<$.Output.List<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>>>, - null - > - listInt: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>, null> - listIntNonNull: $.Field<$.Output.List<$Scalar.Int>, null> - object: $.Field<$.Output.Nullable, null> - objectNonNull: $.Field - objectNested: $.Field<$.Output.Nullable, null> - objectWithArgs: $.Field< - $.Output.Nullable, - $.Args<{ - string: $.Input.Nullable<$Scalar.String> - int: $.Input.Nullable<$Scalar.Int> - float: $.Input.Nullable<$Scalar.Float> - boolean: $.Input.Nullable<$Scalar.Boolean> - id: $.Input.Nullable<$Scalar.ID> - }> - > - fooBarUnion: $.Field<$.Output.Nullable, null> - objectList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable>>, null> - objectListNonNull: $.Field<$.Output.List, null> - /** - * Query enum field documentation. - */ - abcEnum: $.Field<$.Output.Nullable, null> - lowerCaseUnion: $.Field<$.Output.Nullable, null> - interface: $.Field<$.Output.Nullable, null> - interfaceWithArgs: $.Field< - $.Output.Nullable, - $.Args<{ - id: $Scalar.ID - }> - > - interfaceNonNull: $.Field - unionFooBar: $.Field<$.Output.Nullable, null> - unionFooBarWithArgs: $.Field< - $.Output.Nullable, - $.Args<{ - id: $.Input.Nullable<$Scalar.ID> - }> - > - unionObject: $.Field<$.Output.Nullable, null> - unionFooBarNonNull: $.Field - unionObjectNonNull: $.Field - }> -} - -// ------------------------------------------------------------ // -// Enum // -// ------------------------------------------------------------ // - -export namespace Enum { - /** - * Enum documentation. - * - * Members - * "A" - (DEPRECATED: Enum value A is deprecated.) - * "B" - Enum B member documentation. - * "C" - Enum C member documentation. (DEPRECATED: Enum value C is deprecated.) - */ - export type ABCEnum = $.Enum<'ABCEnum', ['A', 'B', 'C']> -} - -// ------------------------------------------------------------ // -// InputObject // -// ------------------------------------------------------------ // - -export namespace InputObject { - export type InputObjectNested = $.InputObject<'InputObjectNested', { - InputObject: $.Input.Nullable - }> - - export type InputObjectNestedNonNull = $.InputObject<'InputObjectNestedNonNull', { - InputObject: InputObject.InputObject - }> - - export type InputObject = $.InputObject<'InputObject', { - id: $.Input.Nullable<$Scalar.ID> - idRequired: $Scalar.ID - date: $.Input.Nullable<$Scalar.Date> - dateRequired: $Scalar.Date - }> -} - -// ------------------------------------------------------------ // -// Interface // -// ------------------------------------------------------------ // - -export namespace Interface { - export type DateInterface1 = $.Interface<'DateInterface1', { - date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> - }, [Object.DateObject1]> - - export type Interface = $.Interface<'Interface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - }, [Object.Object1ImplementingInterface, Object.Object2ImplementingInterface]> -} - -// ------------------------------------------------------------ // -// Object // -// ------------------------------------------------------------ // - -export namespace Object { - export type DateObject1 = $.Object$2<'DateObject1', { - date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> - }> - - export type DateObject2 = $.Object$2<'DateObject2', { - date2: $.Field<$.Output.Nullable<$Scalar.Date>, null> - }> - - export type ObjectUnion = $.Object$2<'ObjectUnion', { - fooBarUnion: $.Field<$.Output.Nullable, null> - }> - - /** - * Object documentation. - */ - export type Foo = $.Object$2<'Foo', { - /** - * Field documentation. - * - * @deprecated Field a is deprecated. - */ - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - }> - - export type Bar = $.Object$2<'Bar', { - int: $.Field<$.Output.Nullable<$Scalar.Int>, null> - }> - - export type ObjectNested = $.Object$2<'ObjectNested', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - object: $.Field<$.Output.Nullable, null> - }> - - export type lowerCaseObject = $.Object$2<'lowerCaseObject', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - }> - - export type lowerCaseObject2 = $.Object$2<'lowerCaseObject2', { - int: $.Field<$.Output.Nullable<$Scalar.Int>, null> - }> - - export type Object1 = $.Object$2<'Object1', { - string: $.Field<$.Output.Nullable<$Scalar.String>, null> - int: $.Field<$.Output.Nullable<$Scalar.Int>, null> - float: $.Field<$.Output.Nullable<$Scalar.Float>, null> - boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - }> - - export type Object1ImplementingInterface = $.Object$2<'Object1ImplementingInterface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - int: $.Field<$.Output.Nullable<$Scalar.Int>, null> - }> - - export type Object2ImplementingInterface = $.Object$2<'Object2ImplementingInterface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>, null> - boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> - }> -} - -// ------------------------------------------------------------ // -// Union // -// ------------------------------------------------------------ // - -export namespace Union { - export type DateUnion = $.Union<'DateUnion', [Object.DateObject1, Object.DateObject2]> - - /** - * Union documentation. - */ - export type FooBarUnion = $.Union<'FooBarUnion', [Object.Foo, Object.Bar]> - - export type lowerCaseUnion = $.Union<'lowerCaseUnion', [Object.lowerCaseObject, Object.lowerCaseObject2]> -} diff --git a/tests/ts/_/schema/generated/SchemaRuntime.ts b/tests/ts/_/schema/generated/SchemaRuntime.ts deleted file mode 100644 index 1f1170e3f..000000000 --- a/tests/ts/_/schema/generated/SchemaRuntime.ts +++ /dev/null @@ -1,218 +0,0 @@ -/* eslint-disable */ - -import * as $ from '../../../../../src/entrypoints/alpha/schema.js' -import * as $Scalar from './Scalar.js' - -export const ABCEnum = $.Enum(`ABCEnum`, [`A`, `B`, `C`]) - -export const InputObjectNested = $.InputObject(`InputObjectNested`, { - InputObject: $.Input.field(() => $.Input.Nullable(InputObject)), -}) - -export const InputObjectNestedNonNull = $.InputObject(`InputObjectNestedNonNull`, { - InputObject: $.Input.field(() => InputObject), -}) - -export const InputObject = $.InputObject(`InputObject`, { - id: $.Input.field($.Input.Nullable($Scalar.ID)), - idRequired: $.Input.field($Scalar.ID), - date: $.Input.field($.Input.Nullable($Scalar.Date)), - dateRequired: $.Input.field($Scalar.Date), -}) - -// @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 DateObject1 = $.Object$(`DateObject1`, { - date1: $.field($.Output.Nullable($Scalar.Date)), -}) - -// @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 DateObject2 = $.Object$(`DateObject2`, { - date2: $.field($.Output.Nullable($Scalar.Date)), -}) - -// @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 ObjectUnion = $.Object$(`ObjectUnion`, { - fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), -}) - -// @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 Foo = $.Object$(`Foo`, { - id: $.field($.Output.Nullable($Scalar.ID)), -}) - -// @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 Bar = $.Object$(`Bar`, { - int: $.field($.Output.Nullable($Scalar.Int)), -}) - -// @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 ObjectNested = $.Object$(`ObjectNested`, { - id: $.field($.Output.Nullable($Scalar.ID)), - object: $.field($.Output.Nullable(() => Object1)), -}) - -// @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 lowerCaseObject = $.Object$(`lowerCaseObject`, { - id: $.field($.Output.Nullable($Scalar.ID)), -}) - -// @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 lowerCaseObject2 = $.Object$(`lowerCaseObject2`, { - int: $.field($.Output.Nullable($Scalar.Int)), -}) - -// @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 Object1 = $.Object$(`Object1`, { - string: $.field($.Output.Nullable($Scalar.String)), - int: $.field($.Output.Nullable($Scalar.Int)), - float: $.field($.Output.Nullable($Scalar.Float)), - boolean: $.field($.Output.Nullable($Scalar.Boolean)), - id: $.field($.Output.Nullable($Scalar.ID)), -}) - -// @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 Object1ImplementingInterface = $.Object$(`Object1ImplementingInterface`, { - id: $.field($.Output.Nullable($Scalar.ID)), - int: $.field($.Output.Nullable($Scalar.Int)), -}) - -// @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 Object2ImplementingInterface = $.Object$(`Object2ImplementingInterface`, { - id: $.field($.Output.Nullable($Scalar.ID)), - boolean: $.field($.Output.Nullable($Scalar.Boolean)), -}) - -// @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 DateUnion = $.Union(`DateUnion`, [DateObject1, DateObject2]) - -// @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 FooBarUnion = $.Union(`FooBarUnion`, [Foo, Bar]) - -// @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 lowerCaseUnion = $.Union(`lowerCaseUnion`, [lowerCaseObject, lowerCaseObject2]) - -export const DateInterface1 = $.Interface(`DateInterface1`, { date1: $.field($.Output.Nullable($Scalar.Date)) }, [ - DateObject1, -]) -export const Interface = $.Interface(`Interface`, { id: $.field($.Output.Nullable($Scalar.ID)) }, [ - Object1ImplementingInterface, - Object2ImplementingInterface, -]) - -// @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 Query = $.Object$(`Query`, { - date: $.field($.Output.Nullable($Scalar.Date)), - dateNonNull: $.field($Scalar.Date), - dateList: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Date)))), - dateObject1: $.field($.Output.Nullable(() => DateObject1)), - dateUnion: $.field($.Output.Nullable(() => DateUnion)), - dateInterface1: $.field($.Output.Nullable(() => DateInterface1)), - dateListNonNull: $.field($.Output.List($Scalar.Date)), - dateArg: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.Nullable($Scalar.Date) })), - dateArgNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $Scalar.Date })), - dateArgList: $.field( - $.Output.Nullable($Scalar.Date), - $.Args({ date: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Date))) }), - ), - dateArgNonNullList: $.field( - $.Output.Nullable($Scalar.Date), - $.Args({ date: $.Input.List($.Input.Nullable($Scalar.Date)) }), - ), - dateArgNonNullListNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.List($Scalar.Date) })), - dateArgInputObject: $.field($.Output.Nullable($Scalar.Date), $.Args({ input: $.Input.Nullable(InputObject) })), - InputObjectNested: $.field($.Output.Nullable($Scalar.ID), $.Args({ input: $.Input.Nullable(InputObjectNested) })), - InputObjectNestedNonNull: $.field($.Output.Nullable($Scalar.ID), $.Args({ input: InputObjectNested })), - id: $.field($.Output.Nullable($Scalar.ID)), - idNonNull: $.field($Scalar.ID), - string: $.field($.Output.Nullable($Scalar.String)), - stringWithRequiredArg: $.field($.Output.Nullable($Scalar.String), $.Args({ string: $Scalar.String })), - stringWithArgs: $.field( - $.Output.Nullable($Scalar.String), - $.Args({ - string: $.Input.Nullable($Scalar.String), - int: $.Input.Nullable($Scalar.Int), - float: $.Input.Nullable($Scalar.Float), - boolean: $.Input.Nullable($Scalar.Boolean), - id: $.Input.Nullable($Scalar.ID), - }), - ), - stringWithArgEnum: $.field($.Output.Nullable($Scalar.String), $.Args({ ABCEnum: $.Input.Nullable(ABCEnum) })), - stringWithListArg: $.field( - $.Output.Nullable($Scalar.String), - $.Args({ ints: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Int))) }), - ), - stringWithListArgRequired: $.field( - $.Output.Nullable($Scalar.String), - $.Args({ ints: $.Input.List($.Input.Nullable($Scalar.Int)) }), - ), - stringWithArgInputObject: $.field( - $.Output.Nullable($Scalar.String), - $.Args({ input: $.Input.Nullable(InputObject) }), - ), - stringWithArgInputObjectRequired: $.field($.Output.Nullable($Scalar.String), $.Args({ input: InputObject })), - listListIntNonNull: $.field($.Output.List($.Output.List($Scalar.Int))), - listListInt: $.field( - $.Output.Nullable($.Output.List($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int))))), - ), - listInt: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int)))), - listIntNonNull: $.field($.Output.List($Scalar.Int)), - object: $.field($.Output.Nullable(() => Object1)), - objectNonNull: $.field(() => Object1), - objectNested: $.field($.Output.Nullable(() => ObjectNested)), - objectWithArgs: $.field( - $.Output.Nullable(() => Object1), - $.Args({ - string: $.Input.Nullable($Scalar.String), - int: $.Input.Nullable($Scalar.Int), - float: $.Input.Nullable($Scalar.Float), - boolean: $.Input.Nullable($Scalar.Boolean), - id: $.Input.Nullable($Scalar.ID), - }), - ), - fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), - objectList: $.field($.Output.Nullable($.Output.List($.Output.Nullable(() => Object1)))), - objectListNonNull: $.field($.Output.List(() => Object1)), - abcEnum: $.field($.Output.Nullable(ABCEnum)), - lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)), - interface: $.field($.Output.Nullable(() => Interface)), - interfaceWithArgs: $.field($.Output.Nullable(() => Interface), $.Args({ id: $Scalar.ID })), - interfaceNonNull: $.field(() => Interface), - unionFooBar: $.field($.Output.Nullable(() => FooBarUnion)), - unionFooBarWithArgs: $.field($.Output.Nullable(() => FooBarUnion), $.Args({ id: $.Input.Nullable($Scalar.ID) })), - unionObject: $.field($.Output.Nullable(() => ObjectUnion)), - unionFooBarNonNull: $.field(() => FooBarUnion), - unionObjectNonNull: $.field(() => ObjectUnion), -}) - -export const $Index = { - Root: { - Query, - Mutation: null, - Subscription: null, - }, - objects: { - DateObject1, - DateObject2, - ObjectUnion, - Foo, - Bar, - ObjectNested, - lowerCaseObject, - lowerCaseObject2, - Object1, - Object1ImplementingInterface, - Object2ImplementingInterface, - }, - unions: { - DateUnion, - FooBarUnion, - lowerCaseUnion, - }, - interfaces: { - DateInterface1, - Interface, - }, - error: { - objects: {}, - }, -} diff --git a/tests/ts/_/schema/generated/Select.ts b/tests/ts/_/schema/generated/Select.ts deleted file mode 100644 index 860fdd73d..000000000 --- a/tests/ts/_/schema/generated/Select.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { ResultSet, SelectionSet } from '../../../../../src/entrypoints/alpha/schema.js' -import { Index } from './Index.js' - -// Root Types -// ---------- - -export type Query<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< - $SelectionSet, - Index, - 'Query' -> - -// Object Types -// ------------ - -export type DateObject1<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index> - -export type DateObject2<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index> - -export type ObjectUnion<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index> - -export type Foo<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Foo'], - Index -> - -export type Bar<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Bar'], - Index -> - -export type ObjectNested<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index> - -export type lowerCaseObject<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index> - -export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index> - -export type Object1<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Object1'], - Index -> - -export type Object1ImplementingInterface< - $SelectionSet extends SelectionSet.Object, -> = ResultSet.Object$<$SelectionSet, Index['objects']['Object1ImplementingInterface'], Index> - -export type Object2ImplementingInterface< - $SelectionSet extends SelectionSet.Object, -> = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index> - -// Union Types -// ----------- - -export type DateUnion<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< - $SelectionSet, - Index['unions']['DateUnion'], - Index -> - -export type FooBarUnion<$SelectionSet extends SelectionSet.Union> = - ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index> - -export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union> = - ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index> - -// Interface Types -// --------------- - -export type DateInterface1<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index> - -export type Interface<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['Interface'], Index> diff --git a/tests/ts/_/schema/schema.graphql b/tests/ts/_/schema/schema.graphql deleted file mode 100644 index a8f415316..000000000 --- a/tests/ts/_/schema/schema.graphql +++ /dev/null @@ -1,166 +0,0 @@ -# TODO test case for recursive input objects -scalar Date - -type Query { - # Custom Scalar - date: Date - dateNonNull: Date! - dateList: [Date] - dateObject1: DateObject1 - dateUnion: DateUnion - dateInterface1: DateInterface1 - dateListNonNull: [Date!]! - dateArg(date: Date): Date - dateArgNonNull(date: Date!): Date - dateArgList(date: [Date]): Date - dateArgNonNullList(date: [Date]!): Date - dateArgNonNullListNonNull(date: [Date!]!): Date - dateArgInputObject(input: InputObject): Date - # Input Object - # Note: It is important that the type `InputObjectNested` is defined before `InputObject` in the generated runtime schema. - # This is to force the case of needing a thunk, to make sure our tests for it are actually testing the case. - InputObjectNested(input: InputObjectNested): ID - InputObjectNestedNonNull(input: InputObjectNested!): ID - # Scalar - id: ID - idNonNull: ID! - string: String - stringWithRequiredArg(string:String!): String - stringWithArgs(string:String, int:Int, float:Float, boolean:Boolean, id:ID): String - stringWithArgEnum(ABCEnum:ABCEnum): String - stringWithListArg(ints:[Int]): String - stringWithListArgRequired(ints:[Int]!): String - stringWithArgInputObject(input:InputObject): String - stringWithArgInputObjectRequired(input:InputObject!): String - # List Scalar - listListIntNonNull: [[Int!]!]! - listListInt: [[Int]] - listInt: [Int] - listIntNonNull: [Int!]! - # Object - object: Object1 - objectNonNull: Object1! - objectNested: ObjectNested - objectWithArgs(string:String, int:Int, float:Float, boolean:Boolean, id:ID): Object1 - fooBarUnion: FooBarUnion - # Object List - objectList: [Object1] - objectListNonNull: [Object1!]! - """ - Query enum field documentation. - """ - abcEnum: ABCEnum - lowerCaseUnion: lowerCaseUnion - # Interface - interface: Interface - interfaceWithArgs(id:ID!): Interface - interfaceNonNull: Interface! - # Union - unionFooBar: FooBarUnion - unionFooBarWithArgs(id:ID): FooBarUnion - unionObject: ObjectUnion - unionFooBarNonNull: FooBarUnion! - unionObjectNonNull: ObjectUnion! -} - -interface DateInterface1 { - date1: Date -} - -union DateUnion = DateObject1 | DateObject2 - -type DateObject1 implements DateInterface1 { - date1: Date -} - -type DateObject2 { - date2: Date -} - -input InputObjectNested { - InputObject: InputObject -} - -input InputObjectNestedNonNull { - InputObject: InputObject! -} - -input InputObject { - id: ID - idRequired: ID! - date: Date - dateRequired: Date! -} - -type ObjectUnion { - fooBarUnion: FooBarUnion -} - -""" -Union documentation. -""" -union FooBarUnion = Foo | Bar - -""" -Object documentation. -""" -type Foo { - """ - Field documentation. - """ - id: ID @deprecated(reason: "Field a is deprecated.") -} - -type Bar { - int: Int -} - -type ObjectNested { - id: ID - object: Object1 -} - -type lowerCaseObject { - id: ID -} -type lowerCaseObject2 { - int: Int -} -union lowerCaseUnion = lowerCaseObject | lowerCaseObject2 - -type Object1 { - string: String - int: Int - float: Float - boolean: Boolean - id: ID -} - -interface Interface { - id: ID -} - -type Object1ImplementingInterface implements Interface { - id: ID - int: Int -} - -type Object2ImplementingInterface implements Interface { - id: ID - boolean: Boolean -} - -""" -Enum documentation. -""" -enum ABCEnum { - A @deprecated(reason: "Enum value A is deprecated.") - """ - Enum B member documentation. - """ - B - """ - Enum C member documentation. - """ - C @deprecated(reason: "Enum value C is deprecated.") -}