diff --git a/src/extensions/SchemaErrors/SchemaErrors.ts b/src/extensions/SchemaErrors/SchemaErrors.ts index 2c6cdc054..f974a3c3f 100644 --- a/src/extensions/SchemaErrors/SchemaErrors.ts +++ b/src/extensions/SchemaErrors/SchemaErrors.ts @@ -88,7 +88,7 @@ interface OnRequestResult<$Params extends Extension.Hooks.OnRequestResult.Params [$Key in keyof ExcludeNullAndUndefined<$Params['result']['data']>]: Exclude< ExcludeNullAndUndefined<$Params['result']['data']>[$Key], - { __typename: $Params['registeredSchema']['index']['extensions']['SchemaErrors']['objectNames'] } + { __typename: $Params['registeredSchema']['schema']['extensions']['SchemaErrors']['objectNames'] } > } } & Omit<$Params['result'], 'data'> diff --git a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/Global.ts b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/Global.ts index bded69237..6e41f4003 100644 --- a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/Global.ts +++ b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/Global.ts @@ -10,7 +10,7 @@ declare global { export interface Schemas { GraffleSchemaErrors: { name: Data.Name - index: Schema + schema: Schema interfaces: { MethodsSelect: MethodsSelect.$MethodsSelect Document: MethodsDocument.BuilderMethodsDocumentFn diff --git a/src/layers/1_Schema/Hybrid/types/Scalar/Scalar.ts b/src/layers/1_Schema/Hybrid/types/Scalar/Scalar.ts index 775261cb9..8e638c3f9 100644 --- a/src/layers/1_Schema/Hybrid/types/Scalar/Scalar.ts +++ b/src/layers/1_Schema/Hybrid/types/Scalar/Scalar.ts @@ -106,6 +106,6 @@ export type $Any = | Boolean | ID | Float - | Values + | Values type Values = T extends any ? keyof T extends never ? never : T[keyof T] : never diff --git a/src/layers/4_generator/generator/__snapshots__/generate.test.ts.snap b/src/layers/4_generator/generator/__snapshots__/generate.test.ts.snap index aab726407..eff02e372 100644 --- a/src/layers/4_generator/generator/__snapshots__/generate.test.ts.snap +++ b/src/layers/4_generator/generator/__snapshots__/generate.test.ts.snap @@ -50,7 +50,7 @@ declare global { export interface Schemas { default: { name: Data.Name - index: Schema + schema: Schema interfaces: { MethodsSelect: MethodsSelect.$MethodsSelect Document: MethodsDocument.BuilderMethodsDocumentFn diff --git a/src/layers/4_generator/generators/global.ts b/src/layers/4_generator/generators/global.ts index 9599424ac..191488a3f 100644 --- a/src/layers/4_generator/generators/global.ts +++ b/src/layers/4_generator/generators/global.ts @@ -1,4 +1,5 @@ import { Code } from '../../../lib/Code.js' +import { identifiers } from '../helpers/identifiers.js' import { createModuleGenerator } from '../helpers/moduleGenerator.js' import { ModuleGeneratorData } from './Data.js' import { ModuleGeneratorMethodsDocument } from './MethodsDocument.js' @@ -10,16 +11,12 @@ import { ModuleGeneratorSchema } from './Schema.js' export const ModuleGeneratorGlobal = createModuleGenerator( `Global`, ({ config, code }) => { - const identifiers = { - Scalar: `Scalar`, - } - code( `import type * as Data from './${ModuleGeneratorData.name}.js'`, `import type * as MethodsSelect from './${ModuleGeneratorMethodsSelect.name}.js'`, `import type * as MethodsDocument from './${ModuleGeneratorMethodsDocument.name}.js'`, `import type * as MethodsRoot from './${ModuleGeneratorMethodsRoot.name}.js'`, - `import type { Schema } from './${ModuleGeneratorSchema.name}.js'`, + `import type { ${identifiers.Schema} } from './${ModuleGeneratorSchema.name}.js'`, ) if (config.schema.kindMap.GraphQLScalarTypeCustom.length > 0) { @@ -34,10 +31,10 @@ export const ModuleGeneratorGlobal = createModuleGenerator( const customScalarsProperties = config.schema.kindMap.GraphQLScalarTypeCustom .map((_) => [_.name, `${identifiers.Scalar}.${_.name}`]) - const SchemasFields = Code.termObjectFields({ + const ClientFields = Code.termObjectFields({ [config.name]: { name: `Data.Name`, - index: `Schema`, + schema: identifiers.Schema, interfaces: { MethodsSelect: `MethodsSelect.$MethodsSelect`, Document: `MethodsDocument.BuilderMethodsDocumentFn`, @@ -51,11 +48,12 @@ export const ModuleGeneratorGlobal = createModuleGenerator( }, }) + // todo rename "Schemas" to "Clients" code(` declare global { export namespace GraffleGlobal { export interface Schemas { - ${SchemasFields} + ${ClientFields} } } } diff --git a/src/layers/4_generator/globalRegistry.ts b/src/layers/4_generator/globalRegistry.ts index 475a7f775..b2168fca4 100644 --- a/src/layers/4_generator/globalRegistry.ts +++ b/src/layers/4_generator/globalRegistry.ts @@ -12,11 +12,12 @@ declare global { } } -type ZeroSchema = { +interface ZeroClient extends GlobalRegistry.RegisteredSchema { name: GlobalRegistry.DefaultSchemaName - index: { name: never } - // featureOptions: {} + schema: Schema interfaces: { + Root: TypeFunction.Fn + Document: TypeFunction.Fn MethodsSelect: {} } defaultSchemaUrl: null @@ -37,7 +38,7 @@ export namespace GlobalRegistry { export interface RegisteredSchema<$Extensions extends Extensions = Extensions> { name: string - index: Schema<$Extensions['Schema']> + schema: Schema<$Extensions['Schema']> interfaces: { Root: TypeFunction.Fn Document: TypeFunction.Fn @@ -51,29 +52,29 @@ export namespace GlobalRegistry { export type DefaultSchemaName = 'default' - export type Schemas = GraffleGlobal.Schemas + export type Clients = GraffleGlobal.Schemas // todo rename to Clients - export type IsEmpty = keyof Schemas extends never ? true : false + export type IsEmpty = keyof Clients extends never ? true : false - export type SchemaUnion = IsEmpty extends true ? ZeroSchema : Values + export type ClientUnion = IsEmpty extends true ? ZeroClient : Values export type SchemaNames = keyof GraffleGlobal.Schemas extends never ? TSErrorDescriptive<'SchemaNames', 'No schemas have been registered. Did you run graffle generate?'> : keyof GraffleGlobal.Schemas // dprint-ignore - export type HasDefaultUrlForSchema<$Schema extends SchemaUnion> = + export type HasDefaultUrlForSchema<$Schema extends ClientUnion> = $Schema['defaultSchemaUrl'] extends null ? false : true // eslint-disable-next-line // @ts-ignore passes after generation - export type GetSchemaIndex<$Name extends SchemaNames> = GraffleGlobal.Schemas[$Name]['index'] + export type GetSchema<$Name extends SchemaNames> = GraffleGlobal.Schemas[$Name]['schema'] // eslint-disable-next-line // @ts-ignore passes after generation - export type SchemaIndexDefault = GetSchemaIndex + export type SchemaDefault = GetSchema // dprint-ignore export type GetOrDefault<$Name extends SchemaNames | undefined> = @@ -86,8 +87,8 @@ export namespace GlobalRegistry { : GraffleGlobal.Schemas[DefaultSchemaName] // dprint-ignore - export type GetSchemaIndexOrDefault<$Name extends SchemaNames | undefined> = + export type GetSchemaOrDefault<$Name extends SchemaNames | undefined> = $Name extends SchemaNames - ? GetSchemaIndex<$Name> - : SchemaIndexDefault + ? GetSchema<$Name> + : SchemaDefault } diff --git a/src/layers/4_generator/helpers/identifiers.ts b/src/layers/4_generator/helpers/identifiers.ts index 2244ff184..d8cdf6147 100644 --- a/src/layers/4_generator/helpers/identifiers.ts +++ b/src/layers/4_generator/helpers/identifiers.ts @@ -2,4 +2,5 @@ export const identifiers = { Schema: `Schema`, Utilities: `Utilities`, MethodsRoot: `MethodsRoot`, + Scalar: `Scalar`, } diff --git a/src/layers/5_select/select.ts b/src/layers/5_select/select.ts index 33cbdf26b..dea4567d1 100644 --- a/src/layers/5_select/select.ts +++ b/src/layers/5_select/select.ts @@ -12,4 +12,4 @@ export const create: Create = (_name) => identityProxy as any // todo is an any type // eslint-disable-next-line // @ts-ignore generated types -export const select: TypeSelectionSets = identityProxy +export const select: TypeSelectionSets = identityProxy diff --git a/src/layers/6_client/Settings/Input.ts b/src/layers/6_client/Settings/Input.ts index 1867bf45e..1982454a0 100644 --- a/src/layers/6_client/Settings/Input.ts +++ b/src/layers/6_client/Settings/Input.ts @@ -19,8 +19,8 @@ export type InputOutputEnvelopeLonghand = { /** * @remarks This input extends base with properties that can be filled with exports from the generated client. */ -export type InputStatic<$Schema extends GlobalRegistry.SchemaUnion = GlobalRegistry.SchemaUnion> = - & InputBase<$Schema> +export type InputStatic<$RegisteredClient extends GlobalRegistry.ClientUnion = GlobalRegistry.ClientUnion> = + & InputBase<$RegisteredClient> & { /** * The schema to use. @@ -29,7 +29,7 @@ export type InputStatic<$Schema extends GlobalRegistry.SchemaUnion = GlobalRegis * * @defaultValue 'default' */ - name?: $Schema['index']['name'] + name?: $RegisteredClient['name'] /** * todo */ @@ -39,10 +39,10 @@ export type InputStatic<$Schema extends GlobalRegistry.SchemaUnion = GlobalRegis // TODO use code generation to display // TODO test that schema is optional when introspection was used to generate client. // dprint-ignore -export type InputBase<$Schema extends GlobalRegistry.SchemaUnion> = +export type InputBase<$RegisteredClient extends GlobalRegistry.ClientUnion> = | ( & ( - GlobalRegistry.HasDefaultUrlForSchema<$Schema> extends true + GlobalRegistry.HasDefaultUrlForSchema<$RegisteredClient> extends true ? { /** * @defaultValue The introspection URL used to generate this Graffle client. @@ -55,11 +55,11 @@ export type InputBase<$Schema extends GlobalRegistry.SchemaUnion> = ) // eslint-disable-next-line // @ts-ignore passes after generation - & WithInput<{ name: $Schema['name']; transport: { type: 'http'} }> + & WithInput<{ name: $RegisteredClient['name']; transport: { type: 'http'} }> ) | ( & ( - GlobalRegistry.HasDefaultUrlForSchema<$Schema> extends true + GlobalRegistry.HasDefaultUrlForSchema<$RegisteredClient> extends true ? { /** * TODO this TSDoc is never rendered in VSCode... @@ -71,5 +71,5 @@ export type InputBase<$Schema extends GlobalRegistry.SchemaUnion> = ) // eslint-disable-next-line // @ts-ignore passes after generation - & WithInput<{ name: $Schema['name']; transport: { type: 'memory'} }> + & WithInput<{ name: $RegisteredClient['name']; transport: { type: 'memory'} }> ) diff --git a/src/layers/6_client/Settings/InputToConfig.ts b/src/layers/6_client/Settings/InputToConfig.ts index 7d01eb639..1f82fd397 100644 --- a/src/layers/6_client/Settings/InputToConfig.ts +++ b/src/layers/6_client/Settings/InputToConfig.ts @@ -56,7 +56,9 @@ export const inputToConfig = <$Input extends InputStatic>( return { initialInput: input, - // @ts-expect-error conditional type fixme + // todo fixme: passes before generation + // eslint-disable-next-line + // @ts-ignore name: input.name ?? defaultSchemaName, transport, schemaMap: input.schemaMap ?? null as any, diff --git a/src/layers/6_client/prefilled.ts b/src/layers/6_client/prefilled.ts index 0ea97d4b0..2cef6255c 100644 --- a/src/layers/6_client/prefilled.ts +++ b/src/layers/6_client/prefilled.ts @@ -24,18 +24,18 @@ export type CreatePrefilled = < // eslint-disable-next-line // @ts-ignore passes after generation - $Input extends InputPrefilled, + $Input extends InputPrefilled, >(...args: // eslint-disable-next-line // @ts-ignore passes after generation - HasRequiredKeys> extends true + HasRequiredKeys> extends true // eslint-disable-next-line // @ts-ignore passes after generation - ? [input: Exact<$Input, InputPrefilled>] + ? [input: Exact<$Input, InputPrefilled>] // TODO test that input optional when no required properties // eslint-disable-next-line // @ts-ignore passes after generation - : ([input: Exact<$Input, InputPrefilled>] | []) + : ([input: Exact<$Input, InputPrefilled>] | []) ) => // eslint-disable-next-line // @ts-ignore passes after generation @@ -45,7 +45,7 @@ export type CreatePrefilled = }> // dprint-ignore -export type InputPrefilled<$Schema extends GlobalRegistry.SchemaUnion> = +export type InputPrefilled<$Schema extends GlobalRegistry.ClientUnion> = $Schema extends any ? InputBase<$Schema> : never diff --git a/tests/_/schemas/kitchen-sink/graffle/modules/Global.ts b/tests/_/schemas/kitchen-sink/graffle/modules/Global.ts index 5ddb0d115..bf3823ce7 100644 --- a/tests/_/schemas/kitchen-sink/graffle/modules/Global.ts +++ b/tests/_/schemas/kitchen-sink/graffle/modules/Global.ts @@ -10,7 +10,7 @@ declare global { export interface Schemas { default: { name: Data.Name - index: Schema + schema: Schema interfaces: { MethodsSelect: MethodsSelect.$MethodsSelect Document: MethodsDocument.BuilderMethodsDocumentFn diff --git a/tests/_/schemas/mutation-only/graffle/modules/Global.ts b/tests/_/schemas/mutation-only/graffle/modules/Global.ts index 429d323c6..1149b5b46 100644 --- a/tests/_/schemas/mutation-only/graffle/modules/Global.ts +++ b/tests/_/schemas/mutation-only/graffle/modules/Global.ts @@ -9,7 +9,7 @@ declare global { export interface Schemas { MutationOnly: { name: Data.Name - index: Schema + schema: Schema interfaces: { MethodsSelect: MethodsSelect.$MethodsSelect Document: MethodsDocument.BuilderMethodsDocumentFn diff --git a/tests/_/schemas/pokemon/graffle/modules/Global.ts b/tests/_/schemas/pokemon/graffle/modules/Global.ts index de1b4bf26..4d4edb526 100644 --- a/tests/_/schemas/pokemon/graffle/modules/Global.ts +++ b/tests/_/schemas/pokemon/graffle/modules/Global.ts @@ -9,7 +9,7 @@ declare global { export interface Schemas { Pokemon: { name: Data.Name - index: Schema + schema: Schema interfaces: { MethodsSelect: MethodsSelect.$MethodsSelect Document: MethodsDocument.BuilderMethodsDocumentFn diff --git a/tests/_/schemas/query-only/graffle/modules/Global.ts b/tests/_/schemas/query-only/graffle/modules/Global.ts index 39dc37fa7..7b5b0be10 100644 --- a/tests/_/schemas/query-only/graffle/modules/Global.ts +++ b/tests/_/schemas/query-only/graffle/modules/Global.ts @@ -9,7 +9,7 @@ declare global { export interface Schemas { QueryOnly: { name: Data.Name - index: Schema + schema: Schema interfaces: { MethodsSelect: MethodsSelect.$MethodsSelect Document: MethodsDocument.BuilderMethodsDocumentFn diff --git a/website/graffle/modules/Global.ts b/website/graffle/modules/Global.ts index f3567e88c..2bab7dc10 100644 --- a/website/graffle/modules/Global.ts +++ b/website/graffle/modules/Global.ts @@ -9,7 +9,7 @@ declare global { export interface Schemas { default: { name: Data.Name - index: Schema + schema: Schema interfaces: { MethodsSelect: MethodsSelect.$MethodsSelect Document: MethodsDocument.BuilderMethodsDocumentFn diff --git a/website/pokemon/modules/Global.ts b/website/pokemon/modules/Global.ts index de1b4bf26..4d4edb526 100644 --- a/website/pokemon/modules/Global.ts +++ b/website/pokemon/modules/Global.ts @@ -9,7 +9,7 @@ declare global { export interface Schemas { Pokemon: { name: Data.Name - index: Schema + schema: Schema interfaces: { MethodsSelect: MethodsSelect.$MethodsSelect Document: MethodsDocument.BuilderMethodsDocumentFn