From 5c62024b713e2886acd4d1a268930f2ca933fd4f Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 24 Sep 2024 10:01:13 -0400 Subject: [PATCH] feat(document): no key plural for op types (#1114) --- .github/workflows/pr.yml | 14 +++ .../atlas/modules/MethodsDocument.ts | 2 +- .../pokemon/modules/MethodsDocument.ts | 4 +- .../generated_document__document.ts | 2 +- package.json | 1 + .../2_generator/code/MethodsDocument.ts | 4 +- src/layers/3_SelectionSet/encode.ts | 4 +- src/layers/6_client/client.ts | 8 +- src/layers/6_client/document.test-d.ts | 16 ++-- src/layers/6_client/document.test.ts | 14 +-- src/layers/6_client/document.ts | 83 ++++++++++------- .../7_extensions/Throws/Throws.test-d.ts | 6 +- src/layers/7_extensions/Throws/Throws.test.ts | 6 +- src/lib/graphql.ts | 6 ++ src/lib/prelude.ts | 90 ++++++++++++++++--- .../generated/modules/MethodsDocument.ts | 4 +- .../generated/modules/MethodsDocument.ts | 2 +- .../generated/modules/MethodsDocument.ts | 2 +- .../examples/generated/document.detail.md | 2 +- .../_snippets/examples/generated/document.md | 2 +- .../content/examples/55_generated/document.md | 2 +- .../guides/10_getting-started/20_generated.md | 2 +- website/graffle/modules/MethodsDocument.ts | 2 +- website/pokemon/modules/MethodsDocument.ts | 4 +- 24 files changed, 196 insertions(+), 86 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f58bb1397..edafb5e88 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -27,6 +27,20 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/setup - run: pnpm check:types + # While we do not deploy website for PRs we still want to know that it can be built. + # This catches issues before merging such as broken twoslash examples. + website: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + - run: pnpm build + - name: Install Website Dependencies + working-directory: website + run: pnpm install + - name: Build Website + working-directory: website + run: pnpm build test: runs-on: ubuntu-latest strategy: diff --git a/examples/$/generated-clients/atlas/modules/MethodsDocument.ts b/examples/$/generated-clients/atlas/modules/MethodsDocument.ts index 14d93b2eb..c4e21a6bb 100644 --- a/examples/$/generated-clients/atlas/modules/MethodsDocument.ts +++ b/examples/$/generated-clients/atlas/modules/MethodsDocument.ts @@ -3,7 +3,7 @@ import type { Index } from './SchemaIndex.js' import type * as SelectionSets from './SelectionSets.js' interface DocumentInput { - queries?: Record + query?: Record } export interface Document<$Config extends Utilities.Config> { diff --git a/examples/$/generated-clients/pokemon/modules/MethodsDocument.ts b/examples/$/generated-clients/pokemon/modules/MethodsDocument.ts index cffa51dd1..8418391be 100644 --- a/examples/$/generated-clients/pokemon/modules/MethodsDocument.ts +++ b/examples/$/generated-clients/pokemon/modules/MethodsDocument.ts @@ -3,8 +3,8 @@ import type { Index } from './SchemaIndex.js' import type * as SelectionSets from './SelectionSets.js' interface DocumentInput { - queries?: Record - mutations?: Record + query?: Record + mutation?: Record } export interface Document<$Config extends Utilities.Config> { diff --git a/examples/55_generated/generated_document__document.ts b/examples/55_generated/generated_document__document.ts index 3d4e5fd58..e5650008d 100644 --- a/examples/55_generated/generated_document__document.ts +++ b/examples/55_generated/generated_document__document.ts @@ -8,7 +8,7 @@ import { showJson } from '../$/helpers.js' const atlas = Atlas.create() const countries = await atlas.document({ - queries: { + query: { countriesQuery: { countries: [`countries2`, { $: { filter: { name: { in: [`Canada`, `Germany`, `Japan`] } } }, diff --git a/package.json b/package.json index 563d580b9..a44fbcd62 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ }, "homepage": "https://github.com/jasonkuhrt/graffle", "scripts": { + "gen:graffle": "pnpm gen:test:schema && pnpm gen:examples:clients && pnpm build && cd website && pnpm gen:graffle", "graffle": "tsx ./src/cli/generate.ts", "gen:test:schema": "tsx tests/_/schemaGenerate.ts", "gen:examples": "tsx scripts/generate-examples-derivatives/generate.ts && pnpm format", diff --git a/src/layers/2_generator/code/MethodsDocument.ts b/src/layers/2_generator/code/MethodsDocument.ts index 314536bee..3f4ee4fef 100644 --- a/src/layers/2_generator/code/MethodsDocument.ts +++ b/src/layers/2_generator/code/MethodsDocument.ts @@ -15,8 +15,8 @@ export const { generate: generateMethodsDocument, moduleName: moduleNameMethodsD code.push( `interface DocumentInput {`, - hasQuery(config.typeMapByKind) ? `queries?: Record` : null, - hasMutation(config.typeMapByKind) ? `mutations?: Record` : null, + hasQuery(config.typeMapByKind) ? `query?: Record` : null, + hasMutation(config.typeMapByKind) ? `mutation?: Record` : null, `}`, ) code.push(``) diff --git a/src/layers/3_SelectionSet/encode.ts b/src/layers/3_SelectionSet/encode.ts index b6899141d..4141936a8 100644 --- a/src/layers/3_SelectionSet/encode.ts +++ b/src/layers/3_SelectionSet/encode.ts @@ -32,8 +32,8 @@ type Args = { [k: string]: ArgValue } type ArgValue = string | boolean | null | number | Args export type DocumentObject = { - queries?: Record - mutations?: Record + query?: Record + mutation?: Record } export type GraphQLRootSelection = { query: GraphQLObjectSelection } | { mutation: GraphQLObjectSelection } diff --git a/src/layers/6_client/client.ts b/src/layers/6_client/client.ts index a861fc6b2..bcdadf060 100644 --- a/src/layers/6_client/client.ts +++ b/src/layers/6_client/client.ts @@ -3,7 +3,7 @@ import type { Anyware } from '../../lib/anyware/__.js' import type { Errors } from '../../lib/errors/__.js' import type { Fluent } from '../../lib/fluent/__.js' import type { FnProperty, ToFnPropertyObject } from '../../lib/fluent/Fluent.js' -import { type RootTypeName } from '../../lib/graphql.js' +import { type RootTypeName, RootTypeNameToOperationName } from '../../lib/graphql.js' import type { HKT } from '../../lib/hkt/__.js' import { mergeHeadersInit, mergeRequestInit } from '../../lib/http.js' import { proxyGet, type SimplifyExceptError } from '../../lib/prelude.js' @@ -423,8 +423,8 @@ const createWithState = ( Object.assign(clientDirect, { document: (documentObject: DocumentObject) => { - const queryOperationNames = Object.keys(documentObject.queries ?? {}) - const mutationOperationNames = Object.keys(documentObject.mutations ?? {}) + const queryOperationNames = Object.keys(documentObject.query ?? {}) + const mutationOperationNames = Object.keys(documentObject.mutation ?? {}) const operationNames = [ ...queryOperationNames, ...mutationOperationNames, @@ -466,7 +466,7 @@ const createWithState = ( } const operationName = maybeOperationName ? maybeOperationName : defaultOperationName const rootTypeName = queryOperationNames.includes(operationName) ? `Query` : `Mutation` - const selection = documentObject[rootTypeName === `Query` ? `queries` : `mutations`]![operationName]! + const selection = documentObject[RootTypeNameToOperationName[rootTypeName]]![operationName]! return { rootTypeName, selection, diff --git a/src/layers/6_client/document.test-d.ts b/src/layers/6_client/document.test-d.ts index ccac5ad10..d7adc16e0 100644 --- a/src/layers/6_client/document.test-d.ts +++ b/src/layers/6_client/document.test-d.ts @@ -18,13 +18,13 @@ test(`requires input`, () => { describe(`input`, () => { test(`document with one query`, () => { - const run = graffle.document({ queries: { foo: { id: true } } }).run + const run = graffle.document({ query: { foo: { id: true } } }).run expectTypeOf(run).toMatchTypeOf<(...params: ['foo'] | [] | [undefined]) => Promise>() }) test(`document with two queries`, () => { const run = graffle.document({ - queries: { + query: { foo: { id: true }, bar: { id: true }, }, @@ -37,10 +37,10 @@ describe(`input`, () => { schema: SchemaQueryOnly.schema, }) queryOnly.document({ - queries: { foo: { id: true } }, + query: { foo: { id: true } }, // todo // // @ts-expect-error mutation not in schema - // mutations: { foo: { id: true } }, + // mutation: { foo: { id: true } }, }) const mutationOnly = MutationOnly.create({ schema: SchemaMutationOnly.schema, @@ -56,21 +56,21 @@ describe(`input`, () => { describe(`document(...).run()`, () => { test(`document with one query`, () => { { - const result = graffle.document({ queries: { x: { id: true } } }).run() + const result = graffle.document({ query: { x: { id: true } } }).run() expectTypeOf(result).resolves.toEqualTypeOf<{ id: string | null }>() } { - const result = graffle.document({ queries: { x: { id: true } } }).run(`x`) + const result = graffle.document({ query: { x: { id: true } } }).run(`x`) expectTypeOf(result).resolves.toEqualTypeOf<{ id: string | null }>() } { - const result = graffle.document({ queries: { x: { id: true } } }).run(undefined) + const result = graffle.document({ query: { x: { id: true } } }).run(undefined) expectTypeOf(result).resolves.toEqualTypeOf<{ id: string | null }>() } }) test(`document with two queries`, () => { const result = graffle.document({ - queries: { + query: { foo: { id: true }, bar: { id: true }, }, diff --git a/src/layers/6_client/document.test.ts b/src/layers/6_client/document.test.ts index de5c16847..b64e8c72c 100644 --- a/src/layers/6_client/document.test.ts +++ b/src/layers/6_client/document.test.ts @@ -9,7 +9,7 @@ const graffle = Graffle.create({ schema }) describe(`document with two queries`, () => { const withTwo = graffle.document({ - queries: { + query: { foo: { id: true }, bar: { idNonNull: true }, }, @@ -64,7 +64,7 @@ describe(`document with two queries`, () => { test.skip(`error if invalid name in document`, async () => { // // todo // // @ts-expect-error - // const { run } = graffle.document({ queries: { foo$: { id: true } } }) + // const { run } = graffle.document({ query: { foo$: { id: true } } }) // await expect(run(`foo$`)).rejects.toMatchObject({ // errors: [{ message: `Syntax Error: Expected "{", found "$".` }], // }) @@ -72,30 +72,30 @@ describe(`document with two queries`, () => { }) test(`document with one query`, async () => { - const { run } = graffle.document({ queries: { foo: { id: true } } }) + const { run } = graffle.document({ query: { foo: { id: true } } }) await expect(run(`foo`)).resolves.toEqual({ id: db.id1 }) await expect(run()).resolves.toEqual({ id: db.id1 }) await expect(run(undefined)).resolves.toEqual({ id: db.id1 }) }) test(`document with one mutation`, async () => { - const { run } = graffle.document({ mutations: { foo: { id: true } } }) + const { run } = graffle.document({ mutation: { foo: { id: true } } }) await expect(run(`foo`)).resolves.toEqual({ id: db.id1 }) await expect(run()).resolves.toEqual({ id: db.id1 }) await expect(run(undefined)).resolves.toEqual({ id: db.id1 }) }) test(`error`, async () => { - const { run } = graffle.document({ queries: { foo: { error: true } } }) + const { run } = graffle.document({ query: { foo: { error: true } } }) await expect(run()).rejects.toMatchObject({ errors: [{ message: `Something went wrong.` }] }) }) test(`document with one mutation and one query`, async () => { const { run } = graffle.document({ - mutations: { + mutation: { foo: { id: true }, }, - queries: { + query: { bar: { idNonNull: true }, }, }) diff --git a/src/layers/6_client/document.ts b/src/layers/6_client/document.ts index bf93325ef..23044a22e 100644 --- a/src/layers/6_client/document.ts +++ b/src/layers/6_client/document.ts @@ -1,9 +1,12 @@ +import type { UnionToTuple } from 'type-fest' import { + type OperationType, operationTypeNameToRootTypeName, + OperationTypes, type RootTypeNameMutation, type RootTypeNameQuery, } from '../../lib/graphql.js' -import type { IsMultipleKeys, Values } from '../../lib/prelude.js' +import type { FirstNonUnknownNever, IsKeyInObjectOptional, IsTupleMultiple, Values } from '../../lib/prelude.js' import type { Schema } from '../1_Schema/__.js' import { SelectionSet } from '../3_SelectionSet/__.js' import type { Context, DocumentObject } from '../3_SelectionSet/encode.js' @@ -11,17 +14,25 @@ import type { ResultSet } from '../4_ResultSet/__.js' import type { ResolveOutputReturnRootType } from './handleOutput.js' import type { AddTypenameToSelectedRootTypeResultFields, Config } from './Settings/Config.js' +type OperationName = string + +interface SomeDocumentOperation { + [k: string]: object +} + interface SomeDocument { - mutations?: Record - queries?: Record + mutation?: SomeDocumentOperation + query?: SomeDocumentOperation } -// dprint-ignore -type HasMultipleOperations<$Document extends SomeDocument> = - IsMultipleKeys< - & ('mutations' extends keyof $Document ? $Document['mutations'] : {}) - & ('queries' extends keyof $Document ? $Document['queries'] : {}) - > +// --- Utility Types To Work With Documents --- + +// // dprint-ignore +// type IsHasMultipleOperations<$Document extends SomeDocument> = +// All<[ +// IsHasMultipleKeys<$Document[OperationType.Query]>, +// IsHasMultipleKeys<$Document[OperationType.Mutation]>, +// ]> // dprint-ignore type GetOperationNames<$Document extends SomeDocument> = Values< @@ -31,36 +42,46 @@ type GetOperationNames<$Document extends SomeDocument> = Values< > // dprint-ignore -type GetRootTypeName<$Document extends SomeDocument, $Name extends string> = - $Name extends keyof $Document['mutations'] ? RootTypeNameMutation : - $Name extends keyof $Document['queries'] ? RootTypeNameQuery : - never +type GetRootTypeNameOfOperation<$Document extends SomeDocument, $Name extends OperationName> = + IsKeyInObjectOptional<$Document[OperationType.Mutation], $Name> extends true ? RootTypeNameMutation : + IsKeyInObjectOptional<$Document[OperationType.Query], $Name> extends true ? RootTypeNameQuery : + never // dprint-ignore type GetOperation<$Document extends SomeDocument, $Name extends string> = - $Name extends keyof $Document['mutations'] ? $Document['mutations'][$Name] : - $Name extends keyof $Document['queries'] ? $Document['queries'][$Name] : - never + FirstNonUnknownNever<[ + // @ts-expect-error could be unknown + $Document[OperationType.Mutation][$Name], + // @ts-expect-error could be unknown + $Document[OperationType.Query][$Name] + ]> +// -- Interface -- +// // dprint-ignore -export type DocumentRunner<$Config extends Config, $Index extends Schema.Index, $Document extends SomeDocument> = { +export type DocumentRunner< + $$Config extends Config, + $$Index extends Schema.Index, + $$Document extends SomeDocument, + $$Name extends GetOperationNames<$$Document> = GetOperationNames<$$Document> +> = { run: < - $Name extends GetOperationNames<$Document>, - $Params extends (HasMultipleOperations<$Document> extends true ? [name: $Name] : ([] | [name: $Name | undefined])), + $Name extends $$Name, + $Params extends (IsTupleMultiple> extends true ? [name: $Name] : ([] | [name: $Name | undefined])), >(...params: $Params) => Promise< ResolveOutputReturnRootType< - $Config, - $Index, + $$Config, + $$Index, ResultSet.Root< AddTypenameToSelectedRootTypeResultFields< - $Config, - $Index, - GetRootTypeName<$Document, $Name>, - GetOperation<$Document, $Name> + $$Config, + $$Index, + GetRootTypeNameOfOperation<$$Document, $Name>, + GetOperation<$$Document, $Name> >, - $Index, - GetRootTypeName<$Document, $Name> + $$Index, + GetRootTypeNameOfOperation<$$Document, $Name> > > > @@ -71,15 +92,15 @@ export const toDocumentString = ( document: DocumentObject, ) => { const operations = [ - ...(Object.entries(document.queries || {}).map(([operationName, selectionSet]) => ({ + ...(Object.entries(document.query || {}).map(([operationName, selectionSet]) => ({ operationName, selectionSet, - operationType: `query` as const, + operationType: OperationTypes.query, }))), - ...(Object.entries(document.mutations || {}).map(([operationName, selectionSet]) => ({ + ...(Object.entries(document.mutation || {}).map(([operationName, selectionSet]) => ({ operationName, selectionSet, - operationType: `mutation` as const, + operationType: OperationTypes.mutation, }))), ] diff --git a/src/layers/7_extensions/Throws/Throws.test-d.ts b/src/layers/7_extensions/Throws/Throws.test-d.ts index a4cc4b549..19d24c9ce 100644 --- a/src/layers/7_extensions/Throws/Throws.test-d.ts +++ b/src/layers/7_extensions/Throws/Throws.test-d.ts @@ -8,16 +8,16 @@ const graffle = Graffle.create({ schema }).use(Throws()) describe(`document`, () => { describe(`query result field`, () => { test(`with __typename`, async () => { - const result = await graffle.throws().document({ queries: { x: { resultNonNull: { __typename: true } } } }).run() + const result = await graffle.throws().document({ query: { x: { resultNonNull: { __typename: true } } } }).run() expectTypeOf(result).toEqualTypeOf<{ resultNonNull: { __typename: 'Object1' } }>() }) test(`without __typename`, async () => { - const result = await graffle.throws().document({ queries: { x: { resultNonNull: {} } } }).run() + const result = await graffle.throws().document({ query: { x: { resultNonNull: {} } } }).run() expectTypeOf(result).toEqualTypeOf<{ resultNonNull: { __typename: 'Object1' } }>() }) test(`multiple via alias`, async () => { const result = await graffle.throws().document({ - queries: { x: { resultNonNull: [[`resultNonNull`, {}], [`x`, {}]] } }, + query: { x: { resultNonNull: [[`resultNonNull`, {}], [`x`, {}]] } }, }) .run() expectTypeOf(result).toEqualTypeOf< diff --git a/src/layers/7_extensions/Throws/Throws.test.ts b/src/layers/7_extensions/Throws/Throws.test.ts index 61d5d34b5..8511a0983 100644 --- a/src/layers/7_extensions/Throws/Throws.test.ts +++ b/src/layers/7_extensions/Throws/Throws.test.ts @@ -10,20 +10,20 @@ describe(`document`, () => { describe(`query result field`, () => { test(`with __typename`, async () => { const result = graffle.throws().document({ - queries: { x: { resultNonNull: { $: { case: `ErrorOne` }, __typename: true } } }, + query: { x: { resultNonNull: { $: { case: `ErrorOne` }, __typename: true } } }, }) .run() await expect(result).rejects.toMatchInlineSnapshot(`[Error: Failure on field resultNonNull: ErrorOne]`) }) test(`without __typename`, async () => { - const result = graffle.throws().document({ queries: { x: { resultNonNull: { $: { case: `ErrorOne` } } } } }).run() + const result = graffle.throws().document({ query: { x: { resultNonNull: { $: { case: `ErrorOne` } } } } }).run() await expect(result).rejects.toMatchInlineSnapshot( `[Error: Failure on field resultNonNull: ErrorOne]`, ) }) test.todo(`multiple via alias`, async () => { const result = graffle.throws().document({ - queries: { + query: { x: { resultNonNull: [ [`resultNonNull`, { $: { case: `ErrorOne` } }], diff --git a/src/lib/graphql.ts b/src/lib/graphql.ts index ea47b45b4..eb3fcf82c 100644 --- a/src/lib/graphql.ts +++ b/src/lib/graphql.ts @@ -317,6 +317,12 @@ export const OperationTypes = { subscription: `subscription`, } as const +export namespace OperationType { + export type Query = typeof OperationTypes['query'] + export type Mutation = typeof OperationTypes['mutation'] + export type Subscription = typeof OperationTypes['subscription'] +} + type OperationTypeQuery = typeof OperationTypes['query'] type OperationTypeMutation = typeof OperationTypes['mutation'] type OperationTypeSubscription = typeof OperationTypes['subscription'] diff --git a/src/lib/prelude.ts b/src/lib/prelude.ts index b74f86b67..8ebfb3947 100644 --- a/src/lib/prelude.ts +++ b/src/lib/prelude.ts @@ -1,4 +1,5 @@ -import type { IsEmptyObject, IsUnknown, Simplify } from 'type-fest' +import type { IsEmptyObject, IsNever, IsUnknown, Simplify } from 'type-fest' + import type { ConditionalSimplify, ConditionalSimplifyDeep } from 'type-fest/source/conditional-simplify.js' /* eslint-disable */ @@ -192,16 +193,16 @@ export type UnionToIntersection = (U extends any ? (k: U) => void : never) ex export type LastOf = UnionToIntersection T : never> extends () => infer R ? R : never -// TS4.0+ -export type Push = [...T, V] +// // TS4.0+ +// export type Push = [...T, V] -// TS4.1+ -export type UnionToTuple, N = [T] extends [never] ? true : false> = true extends N ? [] - : Push>, L> +// // TS4.1+ +// export type UnionToTuple, N = [T] extends [never] ? true : false> = true extends N ? [] +// : Push>, L> -export type CountKeys = keyof T extends never ? 0 : UnionToTuple['length'] -export type IsMultipleKeys = IsMultiple> -export type IsMultiple = T extends 0 ? false : T extends 1 ? false : true +// export type IsMultipleKeys = IsMultiple> +// export type CountKeys = keyof T extends never ? 0 : UnionToTuple['length'] +// export type IsMultiple = T extends 0 ? false : T extends 1 ? false : true export type ExcludeNull = Exclude @@ -467,5 +468,72 @@ export type IsEqual = A extends B ? B extends A ? true : false : false export type AssertIsEqual = IsEqual extends true ? true : never -export const AssertIsEqual = (..._: AssertIsEqual extends never ? [failure: `Types are not equal`] : []) => - undefined +export const AssertIsEqual = ( + ..._: AssertIsEqual extends never ? [reason: { message: `Type B not equal to A`; A: A }] : [] +) => undefined + +export type IfExtendsElse<$Type, $Extends, $Else> = $Type extends $Extends ? $Type : $Else + +// dprint-ignore +export type PickOptionalPropertyOrFallback<$Object extends object, $Property extends keyof $Object, $Fallback> = + undefined extends $Object[$Property] + ? $Fallback + : $Object[$Property] + +export type All<$Tuple extends [...boolean[]]> = $Tuple[number] extends true ? false : true + +export type HasOptionalProperty<$Object extends object, $Property extends keyof $Object> = undefined extends + $Object[$Property] ? false + : true + +export type Push = [...T, V] + +// dprint-ignore +export type UnionToTuple<$Union, L = LastOf<$Union>, N = [$Union] extends [never] ? true : false> = + true extends N + ? [] + : Push>, L> + +export type IsTupleMultiple = T extends [unknown, unknown, ...unknown[]] ? true : false + +// export type CountKeys = keyof T extends never ? 0 : UnionToTuple['length'] +// export type IsMultipleKeys = IsMultiple> +// export type IsMultiple = T extends 0 ? false : T extends 1 ? false : true + +// dprint-ignore +export type FirstNonUnknownNever = + T extends [infer First, ...infer Rest] + ? IsUnknown extends true + ? FirstNonUnknownNever + : IsNever extends true + ? FirstNonUnknownNever + : First + : never + +// type Test1 = FirstNonUnknownNever<[unknown, never, 'x', number]> // string +// type Test2 = FirstNonUnknownNever<[never, 1, unknown, number, boolean]> // number +// type Test3 = FirstNonUnknownNever<[unknown, never]> // never +// type Test4 = FirstNonUnknownNever<[never, unknown, boolean, never]> // boolean + +type Optional = T | undefined +type IsCanBeOptional = undefined extends T ? true : false + +// dprint-ignore +export type IsKeyInObjectOptional, K extends string> = + IsCanBeOptional extends true + ? false + : IsKeyInObject< + // @ts-expect-error TS thinks undefined could be here, + // it cannot because we checked with IsCanBeOptional. + T, + K + > + +// dprint-ignore +export type IsKeyInObject = + K extends keyof T + ? true + : false + +// type Test = IsKeyInObject<{a: 1}, 'a'> // true +// type Test2 = IsKeyInObject<{a: 1}, 'b'> // false diff --git a/tests/_/schema/generated/modules/MethodsDocument.ts b/tests/_/schema/generated/modules/MethodsDocument.ts index cffa51dd1..8418391be 100644 --- a/tests/_/schema/generated/modules/MethodsDocument.ts +++ b/tests/_/schema/generated/modules/MethodsDocument.ts @@ -3,8 +3,8 @@ import type { Index } from './SchemaIndex.js' import type * as SelectionSets from './SelectionSets.js' interface DocumentInput { - queries?: Record - mutations?: Record + query?: Record + mutation?: Record } export interface Document<$Config extends Utilities.Config> { diff --git a/tests/_/schemaMutationOnly/generated/modules/MethodsDocument.ts b/tests/_/schemaMutationOnly/generated/modules/MethodsDocument.ts index 7e4d0ef26..9dfbba88d 100644 --- a/tests/_/schemaMutationOnly/generated/modules/MethodsDocument.ts +++ b/tests/_/schemaMutationOnly/generated/modules/MethodsDocument.ts @@ -3,7 +3,7 @@ import type { Index } from './SchemaIndex.js' import type * as SelectionSets from './SelectionSets.js' interface DocumentInput { - mutations?: Record + mutation?: Record } export interface Document<$Config extends Utilities.Config> { diff --git a/tests/_/schemaQueryOnly/generated/modules/MethodsDocument.ts b/tests/_/schemaQueryOnly/generated/modules/MethodsDocument.ts index 14d93b2eb..c4e21a6bb 100644 --- a/tests/_/schemaQueryOnly/generated/modules/MethodsDocument.ts +++ b/tests/_/schemaQueryOnly/generated/modules/MethodsDocument.ts @@ -3,7 +3,7 @@ import type { Index } from './SchemaIndex.js' import type * as SelectionSets from './SelectionSets.js' interface DocumentInput { - queries?: Record + query?: Record } export interface Document<$Config extends Utilities.Config> { diff --git a/website/content/_snippets/examples/generated/document.detail.md b/website/content/_snippets/examples/generated/document.detail.md index 546a374d4..7039bd507 100644 --- a/website/content/_snippets/examples/generated/document.detail.md +++ b/website/content/_snippets/examples/generated/document.detail.md @@ -10,7 +10,7 @@ import { Graffle as Atlas } from './graffle/__.js' const atlas = Atlas.create() const countries = await atlas.document({ - queries: { + query: { countriesQuery: { countries: [`countries2`, { $: { filter: { name: { in: [`Canada`, `Germany`, `Japan`] } } }, diff --git a/website/content/_snippets/examples/generated/document.md b/website/content/_snippets/examples/generated/document.md index 5dcc3a85e..1b18a348a 100644 --- a/website/content/_snippets/examples/generated/document.md +++ b/website/content/_snippets/examples/generated/document.md @@ -8,7 +8,7 @@ import { Graffle as Atlas } from './graffle/__.js' const atlas = Atlas.create() const countries = await atlas.document({ - queries: { + query: { countriesQuery: { countries: [`countries2`, { $: { filter: { name: { in: [`Canada`, `Germany`, `Japan`] } } }, diff --git a/website/content/examples/55_generated/document.md b/website/content/examples/55_generated/document.md index 93e9685e8..6821a07a3 100644 --- a/website/content/examples/55_generated/document.md +++ b/website/content/examples/55_generated/document.md @@ -13,7 +13,7 @@ import { Graffle as Atlas } from './graffle/__.js' const atlas = Atlas.create() const countries = await atlas.document({ - queries: { + query: { countriesQuery: { countries: [`countries2`, { $: { filter: { name: { in: [`Canada`, `Germany`, `Japan`] } } }, diff --git a/website/content/guides/10_getting-started/20_generated.md b/website/content/guides/10_getting-started/20_generated.md index 21102fdd4..b778b8171 100644 --- a/website/content/guides/10_getting-started/20_generated.md +++ b/website/content/guides/10_getting-started/20_generated.md @@ -95,7 +95,7 @@ const graffle = Graffle.create() // ---cut--- const data /* [2] */ = await graffle .document({ // [1] - queries: { // Operation + query: { // Operation demoQuery: { // Operation name continents: { // Query field selection name: true, // Continent field selection diff --git a/website/graffle/modules/MethodsDocument.ts b/website/graffle/modules/MethodsDocument.ts index d2bd1a8fa..92ccbd49b 100644 --- a/website/graffle/modules/MethodsDocument.ts +++ b/website/graffle/modules/MethodsDocument.ts @@ -3,7 +3,7 @@ import type { Index } from './SchemaIndex.js' import type * as SelectionSets from './SelectionSets.js' interface DocumentInput { - queries?: Record + query?: Record } export interface Document<$Config extends Utilities.Config> { diff --git a/website/pokemon/modules/MethodsDocument.ts b/website/pokemon/modules/MethodsDocument.ts index 70deb7e56..59f5b6932 100644 --- a/website/pokemon/modules/MethodsDocument.ts +++ b/website/pokemon/modules/MethodsDocument.ts @@ -3,8 +3,8 @@ import type { Index } from './SchemaIndex.js' import type * as SelectionSets from './SelectionSets.js' interface DocumentInput { - queries?: Record - mutations?: Record + query?: Record + mutation?: Record } export interface Document<$Config extends Utilities.Config> {