diff --git a/examples/70_type-level/selection-sets.ts b/examples/70_type-level/selection-sets.ts index 4f8b116ee..fef8de893 100644 --- a/examples/70_type-level/selection-sets.ts +++ b/examples/70_type-level/selection-sets.ts @@ -114,7 +114,6 @@ const getPokemonsLike = async (filter: Graffle.SelectionSets.Query.pokemons$Argu name: true, }) -// todo add test coverage for $ stripping on arguments. const pokemons = await getPokemonsLike({ $type: `water` }) // We don't lose any type safety. :) diff --git a/examples/__outputs__/10_transport-http/transport-http_extension_headers__dynamicHeaders.output.txt b/examples/__outputs__/10_transport-http/transport-http_extension_headers__dynamicHeaders.output.txt index ea028871c..c71c96f53 100644 --- a/examples/__outputs__/10_transport-http/transport-http_extension_headers__dynamicHeaders.output.txt +++ b/examples/__outputs__/10_transport-http/transport-http_extension_headers__dynamicHeaders.output.txt @@ -4,7 +4,7 @@ headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1734878384165' + 'x-sent-at-time': '1735104630184' }, method: 'post', url: 'http://localhost:3000/graphql', diff --git a/examples/__outputs__/20_output/output_envelope.output.txt b/examples/__outputs__/20_output/output_envelope.output.txt index 1d338b552..3c7e2c17f 100644 --- a/examples/__outputs__/20_output/output_envelope.output.txt +++ b/examples/__outputs__/20_output/output_envelope.output.txt @@ -16,7 +16,7 @@ headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Sun, 22 Dec 2024 14:39:45 GMT', + date: 'Wed, 25 Dec 2024 05:30:30 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt b/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt index f4add7a67..734f33d8f 100644 --- a/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt +++ b/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt @@ -9,14 +9,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'encode', - id: 'f723a4047c4f8246', + id: '1ef2540c3612ae74', kind: 0, - timestamp: 1734878385686000, - duration: 1952.542, + timestamp: 1735104630493000, + duration: 965.459, attributes: {}, status: { code: 0 }, events: [], @@ -33,14 +33,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'pack', - id: '8404e21eb12fbc92', + id: '12dbd874c3b489ce', kind: 0, - timestamp: 1734878385689000, - duration: 12830.875, + timestamp: 1735104630495000, + duration: 10833.958, attributes: {}, status: { code: 0 }, events: [], @@ -57,14 +57,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'exchange', - id: 'c5691fe0bcfc9991', + id: '837a3ca4af1a71df', kind: 0, - timestamp: 1734878385703000, - duration: 20900.792, + timestamp: 1735104630506000, + duration: 19948.584, attributes: {}, status: { code: 0 }, events: [], @@ -81,14 +81,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'unpack', - id: 'bafdd78624e21445', + id: '392e6c2ad292f089', kind: 0, - timestamp: 1734878385724000, - duration: 992.417, + timestamp: 1735104630526000, + duration: 1046.75, attributes: {}, status: { code: 0 }, events: [], @@ -105,14 +105,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'decode', - id: '32fa8b5942d69ca9', + id: 'f6f9b43acdbbb5d3', kind: 0, - timestamp: 1734878385725000, - duration: 446.542, + timestamp: 1735104630528000, + duration: 480.041, attributes: {}, status: { code: 0 }, events: [], @@ -129,14 +129,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', + traceId: '2d49d55d453267b20a3306c412c2c4bb', parentId: undefined, traceState: undefined, name: 'request', - id: '45c84f0a43771166', + id: '3294547ab163e342', kind: 0, - timestamp: 1734878385686000, - duration: 39771.791, + timestamp: 1735104630492000, + duration: 35822.333, attributes: {}, status: { code: 0 }, events: [], diff --git a/package.json b/package.json index 60d557aaa..8d4af4ff2 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ "serve:pokemon": "tsx tests/_/services/pokemonManual.ts", "gen:graffle": "pnpm gen:graffle:tests && pnpm build && cd website && pnpm gen:graffle", "gen:graffle:tests": "tsx tests/_/schemas/generate.ts && pnpm graffle --project src/extensions/SchemaErrors/tests/fixture", - "gen:graffle:examples": "pnpm build && cd examples && pnpm i && pnpm gen:graffle", + "examples:gen:graffle": "pnpm build && cd examples && pnpm i && pnpm gen:graffle", "examples:link-mode": "cd examples && pnpm add ..", "graffle": "tsx ./src/generator/cli/generate.ts", "gen:examples": "tsx scripts/generate-examples-derivatives/generate.ts && pnpm format", diff --git a/src/documentBuilder/Select/$parseSelection.ts b/src/documentBuilder/Select/$parseSelection.ts index 0d9c974a1..285ffa561 100644 --- a/src/documentBuilder/Select/$parseSelection.ts +++ b/src/documentBuilder/Select/$parseSelection.ts @@ -1,3 +1,5 @@ +import { Grafaid } from '../../lib/grafaid/__.js' +import { Select } from './../Select/__.js' import type { SelectionSet } from './_.js' import { Arguments, Directive, Indicator, InlineFragment, SelectAlias, SelectScalarsWildcard } from './_.js' @@ -88,9 +90,15 @@ export const parseSelectionInlineFragment = (key: string, value: any): ParsedInl export const parseSelection = (key: string, value: any): ParsedSelection => { if (key === Arguments.key) { + const argumentsNormalized = Grafaid.mapVariables(value, (key, value) => { + return { + key: Select.Arguments.enumKeyPrefixStrip(key), + value, + } + }) return { type: `Arguments`, - arguments: value, + arguments: argumentsNormalized ?? {}, } } diff --git a/src/documentBuilder/Select/arguments.ts b/src/documentBuilder/Select/arguments.ts index 4bb5c4e1b..1a35e81d5 100644 --- a/src/documentBuilder/Select/arguments.ts +++ b/src/documentBuilder/Select/arguments.ts @@ -8,4 +8,6 @@ export const enumKeyPrefix = `$` export const enumKeyPrefixPattern = /^\$/g +export const enumKeyPrefixStrip = (key: string) => key.replace(enumKeyPrefixPattern, ``) + export const isEnumKey = (key: string) => key.startsWith(enumKeyPrefix) diff --git a/src/documentBuilder/SelectGraphQLMapper/__snapshots__/toGraphQL.test.ts.snap b/src/documentBuilder/SelectGraphQLMapper/__snapshots__/toGraphQL.test.ts.snap index 29e94c067..98ab34b40 100644 --- a/src/documentBuilder/SelectGraphQLMapper/__snapshots__/toGraphQL.test.ts.snap +++ b/src/documentBuilder/SelectGraphQLMapper/__snapshots__/toGraphQL.test.ts.snap @@ -675,6 +675,52 @@ exports[`( variables: false; scalars: (none) ) - Query - args - custom scalar - " `; +exports[`( variables: false; scalars: (none) ) - Query - args - enum > args - enum 1`] = ` +" + +--------------GRAFFLE QUERY------------- +{ + "stringWithArgEnum": { + "$": { + "$ABCEnum": "A" + } + } +} +--------GRAPHQL DOCUMENT & VARIABLES-------- +{ + stringWithArgEnum(ABCEnum: A) +} +---------------- +{ + "$default": {} +} +" +`; + +exports[`( variables: false; scalars: (none) ) - Query - args - input object enum > args - input object enum 1`] = ` +" + +--------------GRAFFLE QUERY------------- +{ + "stringWithArgInputObjectEnum": { + "$": { + "input": { + "$abcEnum": "A" + } + } + } +} +--------GRAPHQL DOCUMENT & VARIABLES-------- +{ + stringWithArgInputObjectEnum(input: {abcEnum: "A"}) +} +---------------- +{ + "$default": {} +} +" +`; + exports[`( variables: false; scalars: (none) ) - Query - args - object with args (empty object) > args - object with args (empty object) 1`] = ` " @@ -2146,6 +2192,58 @@ query ($input: InputObjectNested) { " `; +exports[`( variables: true; scalars: (none) ) - Query - args - enum > args - enum 1`] = ` +" + +--------------GRAFFLE QUERY------------- +{ + "stringWithArgEnum": { + "$": { + "$ABCEnum": "A" + } + } +} +--------GRAPHQL DOCUMENT & VARIABLES-------- +query ($ABCEnum: ABCEnum) { + stringWithArgEnum(ABCEnum: $ABCEnum) +} +---------------- +{ + "$default": { + "ABCEnum": "A" + } +} +" +`; + +exports[`( variables: true; scalars: (none) ) - Query - args - input object enum > args - input object enum 1`] = ` +" + +--------------GRAFFLE QUERY------------- +{ + "stringWithArgInputObjectEnum": { + "$": { + "input": { + "$abcEnum": "A" + } + } + } +} +--------GRAPHQL DOCUMENT & VARIABLES-------- +query ($input: InputObjectEnum!) { + stringWithArgInputObjectEnum(input: $input) +} +---------------- +{ + "$default": { + "input": { + "abcEnum": "A" + } + } +} +" +`; + exports[`( variables: true; scalars: (none) ) - Query - args - object with args (empty object) > args - object with args (empty object) 1`] = ` " diff --git a/src/documentBuilder/SelectGraphQLMapper/nodes/1_Document.ts b/src/documentBuilder/SelectGraphQLMapper/nodes/1_Document.ts index 145c6f649..f4d41e127 100644 --- a/src/documentBuilder/SelectGraphQLMapper/nodes/1_Document.ts +++ b/src/documentBuilder/SelectGraphQLMapper/nodes/1_Document.ts @@ -21,7 +21,7 @@ export const toGraphQLDocument = ( definitions: operationsAndVariables.map(_ => _.operation), }) - const operationsVariables = Object.fromEntries(operationsAndVariables.map((_): [string, Grafaid.Variables] => { + const operationsVariables = Object.fromEntries(operationsAndVariables.map((_) => { const name = _.operation.name?.value ?? defaultOperationName return [name, _.variables] })) diff --git a/src/documentBuilder/SelectGraphQLMapper/nodes/2_OperationDefinition.ts b/src/documentBuilder/SelectGraphQLMapper/nodes/2_OperationDefinition.ts index 34bef07bb..028c3f4b8 100644 --- a/src/documentBuilder/SelectGraphQLMapper/nodes/2_OperationDefinition.ts +++ b/src/documentBuilder/SelectGraphQLMapper/nodes/2_OperationDefinition.ts @@ -52,3 +52,5 @@ export const toGraphQLOperationDefinition: GraphQLPreOperationMapper< variables, } } + +// TODO: optimization: skip when using SDDM b/c we don't need $-directed enums diff --git a/src/documentBuilder/SelectGraphQLMapper/nodes/5_Field.ts b/src/documentBuilder/SelectGraphQLMapper/nodes/5_Field.ts index d7d6a1e7c..1f35f63bb 100644 --- a/src/documentBuilder/SelectGraphQLMapper/nodes/5_Field.ts +++ b/src/documentBuilder/SelectGraphQLMapper/nodes/5_Field.ts @@ -38,7 +38,7 @@ export const toGraphQLField: GraphQLPostOperationMapper< case `Arguments`: { const sddmArguments = sddm?.a for (const argName in keyParsed.arguments) { - const argNameSchema = argName.replace(/^\$/, ``) + const argNameSchema = argName const sddmArgument = sddmArguments?.[argNameSchema] const argValue = keyParsed.arguments[argName] diff --git a/src/documentBuilder/SelectGraphQLMapper/toGraphQL.test.ts b/src/documentBuilder/SelectGraphQLMapper/toGraphQL.test.ts index b70114052..e1b75558c 100644 --- a/src/documentBuilder/SelectGraphQLMapper/toGraphQL.test.ts +++ b/src/documentBuilder/SelectGraphQLMapper/toGraphQL.test.ts @@ -65,6 +65,7 @@ const tester = <$Scalars extends Schema.Scalar.ScalarMap>( // todo test a case where we provide an operation name // dprint-ignore const cases = testEachQueryWithDescription([ + // inline fragment [`fg - one` , { ___: { __typename: true } }], [`fg - multiple` , { ___: [{ __typename: true }, { abcEnum: true }] }], [`fg - interface` , { interface: { ___: { __typename: true } } }], @@ -81,6 +82,8 @@ const cases = testEachQueryWithDescription([ [`alias - scalar directive` , { id: [`x`, { $skip: true }] }], [`alias - scalar directive+select` , { object: [`x`, { $skip: true, id: true }] }], // arguments + [`args - enum` , { stringWithArgEnum: { $: { $ABCEnum: `A` }}}], + [`args - input object enum` , { stringWithArgInputObjectEnum: { $: { input: { $abcEnum: `A` }}}}], [`args - on union` , { result: { $: { $case: `Object1` }, __typename: true } }], [`args - string with args` , { stringWithArgs: { $: { boolean: true, float: 1 } } }], [`args - alias` , { stringWithArgs: [[`a`, { $: { id: `` }}]] }], diff --git a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/methods-root.ts b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/methods-root.ts index 627954a32..bde82c9c9 100644 --- a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/methods-root.ts +++ b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/methods-root.ts @@ -673,6 +673,26 @@ export interface QueryMethods<$Context extends $$Utilities.Context> { > > + stringWithArgInputObjectEnum: $$Utilities.ClientTransports.PreflightCheck< + $Context, + <$SelectionSet>( + selectionSet: $$Utilities.Exact< + $SelectionSet, + $$SelectionSets.Query.stringWithArgInputObjectEnum<$Context['scalars']> + >, + ) => Promise< + & (null | {}) + & $$Utilities.HandleOutputGraffleRootField< + $Context, + InferResult.OperationQuery< + { stringWithArgInputObjectEnum: $SelectionSet }, + $$Schema.Schema<$Context['scalars']> + >, + 'stringWithArgInputObjectEnum' + > + > + > + stringWithArgInputObjectRequired: $$Utilities.ClientTransports.PreflightCheck< $Context, <$SelectionSet>( diff --git a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema-driven-data-map.ts b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema-driven-data-map.ts index c3628841c..fbd1e9c1d 100644 --- a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema-driven-data-map.ts +++ b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema-driven-data-map.ts @@ -110,6 +110,7 @@ const InputObject: $$Utilities.SchemaDrivenDataMap.InputObject = { n: 'InputObject', fcs: ['date', 'dateRequired'], f: { + abcEnum: {}, date: { nt: Date, }, @@ -134,6 +135,13 @@ const InputObjectCircular: $$Utilities.SchemaDrivenDataMap.InputObject = { }, } +const InputObjectEnum: $$Utilities.SchemaDrivenDataMap.InputObject = { + n: 'InputObjectEnum', + f: { + abcEnum: {}, + }, +} + const InputObjectNested: $$Utilities.SchemaDrivenDataMap.InputObject = { n: 'InputObjectNested', fcs: ['InputObject'], @@ -648,6 +656,14 @@ const Query: $$Utilities.SchemaDrivenDataMap.OutputObject = { }, }, }, + stringWithArgInputObjectEnum: { + a: { + input: { + nt: InputObjectEnum, + it: [1], + }, + }, + }, stringWithArgInputObjectRequired: { a: { input: { @@ -819,6 +835,7 @@ const $schemaDrivenDataMap: $$Utilities.SchemaDrivenDataMap = { ParentInterfaceHierarchyMember, InputObject, InputObjectCircular, + InputObjectEnum, InputObjectNested, InputObjectNestedNonNull, Bar, diff --git a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema.ts b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema.ts index 9354aa1f6..19830b4f7 100644 --- a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema.ts +++ b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema.ts @@ -72,6 +72,7 @@ export namespace Schema { string: Query.$string stringWithArgEnum: Query.stringWithArgEnum stringWithArgInputObject: Query.stringWithArgInputObject + stringWithArgInputObjectEnum: Query.stringWithArgInputObjectEnum stringWithArgInputObjectRequired: Query.stringWithArgInputObjectRequired stringWithArgs: Query.stringWithArgs stringWithListArg: Query.stringWithListArg @@ -571,6 +572,20 @@ export namespace Schema { namedType: $$NamedTypes.$$String } + export interface stringWithArgInputObjectEnum extends $.OutputField { + name: 'stringWithArgInputObjectEnum' + arguments: { + input: { + kind: 'InputField' + name: 'input' + inlineType: [1] + namedType: $$NamedTypes.$$InputObjectEnum + } + } + inlineType: [0] + namedType: $$NamedTypes.$$String + } + export interface stringWithArgInputObjectRequired extends $.OutputField { name: 'stringWithArgInputObjectRequired' arguments: { @@ -1483,6 +1498,7 @@ export namespace Schema { name: 'InputObject' isAllFieldsNullable: true fields: { + abcEnum: InputObject.abcEnum date: InputObject.date dateRequired: InputObject.dateRequired id: InputObject.id @@ -1491,6 +1507,12 @@ export namespace Schema { } export namespace InputObject { + export interface abcEnum extends $.InputField { + name: 'abcEnum' + inlineType: [0] + namedType: $$NamedTypes.$$ABCEnum + } + export interface date extends $.InputField { name: 'date' inlineType: [0] @@ -1543,6 +1565,26 @@ export namespace Schema { } } + // InputObjectEnum + // -------------------------------------------------------------------------------------------------- + // + + export interface InputObjectEnum extends $.InputObject { + name: 'InputObjectEnum' + isAllFieldsNullable: true + fields: { + abcEnum: InputObjectEnum.abcEnum + } + } + + export namespace InputObjectEnum { + export interface abcEnum extends $.InputField { + name: 'abcEnum' + inlineType: [0] + namedType: $$NamedTypes.$$ABCEnum + } + } + // InputObjectNested // -------------------------------------------------------------------------------------------------- // @@ -2216,6 +2258,7 @@ export namespace Schema { export type $$lowerCaseObject2 = lowerCaseObject2 export type $$InputObject = InputObject export type $$InputObjectCircular = InputObjectCircular + export type $$InputObjectEnum = InputObjectEnum export type $$InputObjectNested = InputObjectNested export type $$InputObjectNestedNonNull = InputObjectNestedNonNull export type $$DateInterface1 = DateInterface1 diff --git a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/selection-sets.ts b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/selection-sets.ts index 1445e7e97..f10fc2f66 100644 --- a/src/extensions/SchemaErrors/tests/fixture/graffle/modules/selection-sets.ts +++ b/src/extensions/SchemaErrors/tests/fixture/graffle/modules/selection-sets.ts @@ -271,6 +271,12 @@ export interface Query< stringWithArgInputObject?: | Query.stringWithArgInputObject$Expanded<_$Scalars> | $Select.SelectAlias.SelectAlias> + /** + * Select the `stringWithArgInputObjectEnum` field on the `Query` object. Its type is `String` (a `ScalarStandard` kind of type). + */ + stringWithArgInputObjectEnum?: + | Query.stringWithArgInputObjectEnum<_$Scalars> + | $Select.SelectAlias.SelectAlias> /** * Select the `stringWithArgInputObjectRequired` field on the `Query` object. Its type is `String` (a `ScalarStandard` kind of type). */ @@ -1669,6 +1675,40 @@ export namespace Query { // -------------------------------------------------------------------------------------------------- + export type stringWithArgInputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = stringWithArgInputObjectEnum$SelectionSet<_$Scalars> + + export interface stringWithArgInputObjectEnum$SelectionSet< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > extends $Select.Bases.Base { + /** + * Arguments for `stringWithArgInputObjectEnum` field. All arguments are required so you must include this. + */ + $: stringWithArgInputObjectEnum$Arguments<_$Scalars> + } + + export interface stringWithArgInputObjectEnum$Arguments< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > { + input: $NamedTypes.$InputObjectEnum<_$Scalars> + } + + // --- expanded --- + + /** + * This is the "expanded" version of the `stringWithArgInputObjectEnum` type. It is identical except for the fact + * that IDEs will display its contents (a union type) directly, rather than the name of this type. + * In some cases, this is a preferable DX, making the types easier to read for users. + */ + export type stringWithArgInputObjectEnum$Expanded< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = $$Utilities.Simplify< + stringWithArgInputObjectEnum$SelectionSet<_$Scalars> + > + + // -------------------------------------------------------------------------------------------------- + export type stringWithArgInputObjectRequired< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = stringWithArgInputObjectRequired$SelectionSet<_$Scalars> @@ -2145,6 +2185,7 @@ export type ParentInterfaceHierarchyMember = export interface InputObject< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > { + $abcEnum?: $NamedTypes.$ABCEnum | undefined | null date?: | $$Utilities.Schema.Scalar.GetDecoded< $$Utilities.Schema.Scalar.LookupCustomScalarOrFallbackToString<'Date', _$Scalars> @@ -2170,6 +2211,12 @@ export interface InputObjectCircular< | null } +export interface InputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, +> { + $abcEnum?: $NamedTypes.$ABCEnum | undefined | null +} + export interface InputObjectNested< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > { @@ -4637,6 +4684,9 @@ export namespace $NamedTypes { export type $InputObjectCircular< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = InputObjectCircular<_$Scalars> + export type $InputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = InputObjectEnum<_$Scalars> export type $InputObjectNested< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = InputObjectNested<_$Scalars> diff --git a/src/generator/generator/__snapshots__/generate.test.ts.snap b/src/generator/generator/__snapshots__/generate.test.ts.snap index 950322f38..0d94737db 100644 --- a/src/generator/generator/__snapshots__/generate.test.ts.snap +++ b/src/generator/generator/__snapshots__/generate.test.ts.snap @@ -839,6 +839,26 @@ export interface QueryMethods<$Context extends $$Utilities.Context> { > > + stringWithArgInputObjectEnum: $$Utilities.ClientTransports.PreflightCheck< + $Context, + <$SelectionSet>( + selectionSet: $$Utilities.Exact< + $SelectionSet, + $$SelectionSets.Query.stringWithArgInputObjectEnum<$Context['scalars']> + >, + ) => Promise< + & (null | {}) + & $$Utilities.HandleOutputGraffleRootField< + $Context, + InferResult.OperationQuery< + { stringWithArgInputObjectEnum: $SelectionSet }, + $$Schema.Schema<$Context['scalars']> + >, + 'stringWithArgInputObjectEnum' + > + > + > + stringWithArgInputObjectRequired: $$Utilities.ClientTransports.PreflightCheck< $Context, <$SelectionSet>( @@ -1421,6 +1441,7 @@ export namespace Schema { string: Query.$string stringWithArgEnum: Query.stringWithArgEnum stringWithArgInputObject: Query.stringWithArgInputObject + stringWithArgInputObjectEnum: Query.stringWithArgInputObjectEnum stringWithArgInputObjectRequired: Query.stringWithArgInputObjectRequired stringWithArgs: Query.stringWithArgs stringWithListArg: Query.stringWithListArg @@ -1920,6 +1941,20 @@ export namespace Schema { namedType: $$NamedTypes.$$String } + export interface stringWithArgInputObjectEnum extends $.OutputField { + name: 'stringWithArgInputObjectEnum' + arguments: { + input: { + kind: 'InputField' + name: 'input' + inlineType: [1] + namedType: $$NamedTypes.$$InputObjectEnum + } + } + inlineType: [0] + namedType: $$NamedTypes.$$String + } + export interface stringWithArgInputObjectRequired extends $.OutputField { name: 'stringWithArgInputObjectRequired' arguments: { @@ -2832,6 +2867,7 @@ export namespace Schema { name: 'InputObject' isAllFieldsNullable: true fields: { + abcEnum: InputObject.abcEnum date: InputObject.date dateRequired: InputObject.dateRequired id: InputObject.id @@ -2840,6 +2876,12 @@ export namespace Schema { } export namespace InputObject { + export interface abcEnum extends $.InputField { + name: 'abcEnum' + inlineType: [0] + namedType: $$NamedTypes.$$ABCEnum + } + export interface date extends $.InputField { name: 'date' inlineType: [0] @@ -2892,6 +2934,26 @@ export namespace Schema { } } + // InputObjectEnum + // -------------------------------------------------------------------------------------------------- + // + + export interface InputObjectEnum extends $.InputObject { + name: 'InputObjectEnum' + isAllFieldsNullable: true + fields: { + abcEnum: InputObjectEnum.abcEnum + } + } + + export namespace InputObjectEnum { + export interface abcEnum extends $.InputField { + name: 'abcEnum' + inlineType: [0] + namedType: $$NamedTypes.$$ABCEnum + } + } + // InputObjectNested // -------------------------------------------------------------------------------------------------- // @@ -3565,6 +3627,7 @@ export namespace Schema { export type $$lowerCaseObject2 = lowerCaseObject2 export type $$InputObject = InputObject export type $$InputObjectCircular = InputObjectCircular + export type $$InputObjectEnum = InputObjectEnum export type $$InputObjectNested = InputObjectNested export type $$InputObjectNestedNonNull = InputObjectNestedNonNull export type $$DateInterface1 = DateInterface1 @@ -3826,6 +3889,7 @@ const InputObject: $$Utilities.SchemaDrivenDataMap.InputObject = { n: 'InputObject', fcs: ['date', 'dateRequired'], f: { + abcEnum: {}, date: { nt: Date, }, @@ -3850,6 +3914,13 @@ const InputObjectCircular: $$Utilities.SchemaDrivenDataMap.InputObject = { }, } +const InputObjectEnum: $$Utilities.SchemaDrivenDataMap.InputObject = { + n: 'InputObjectEnum', + f: { + abcEnum: {}, + }, +} + const InputObjectNested: $$Utilities.SchemaDrivenDataMap.InputObject = { n: 'InputObjectNested', fcs: ['InputObject'], @@ -4360,6 +4431,14 @@ const Query: $$Utilities.SchemaDrivenDataMap.OutputObject = { }, }, }, + stringWithArgInputObjectEnum: { + a: { + input: { + nt: InputObjectEnum, + it: [1], + }, + }, + }, stringWithArgInputObjectRequired: { a: { input: { @@ -4531,6 +4610,7 @@ const $schemaDrivenDataMap: $$Utilities.SchemaDrivenDataMap = { ParentInterfaceHierarchyMember, InputObject, InputObjectCircular, + InputObjectEnum, InputObjectNested, InputObjectNestedNonNull, Bar, @@ -5054,6 +5134,12 @@ export interface Query< stringWithArgInputObject?: | Query.stringWithArgInputObject$Expanded<_$Scalars> | $Select.SelectAlias.SelectAlias> + /** + * Select the \`stringWithArgInputObjectEnum\` field on the \`Query\` object. Its type is \`String\` (a \`ScalarStandard\` kind of type). + */ + stringWithArgInputObjectEnum?: + | Query.stringWithArgInputObjectEnum<_$Scalars> + | $Select.SelectAlias.SelectAlias> /** * Select the \`stringWithArgInputObjectRequired\` field on the \`Query\` object. Its type is \`String\` (a \`ScalarStandard\` kind of type). */ @@ -6452,6 +6538,40 @@ export namespace Query { // -------------------------------------------------------------------------------------------------- + export type stringWithArgInputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = stringWithArgInputObjectEnum$SelectionSet<_$Scalars> + + export interface stringWithArgInputObjectEnum$SelectionSet< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > extends $Select.Bases.Base { + /** + * Arguments for \`stringWithArgInputObjectEnum\` field. All arguments are required so you must include this. + */ + $: stringWithArgInputObjectEnum$Arguments<_$Scalars> + } + + export interface stringWithArgInputObjectEnum$Arguments< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > { + input: $NamedTypes.$InputObjectEnum<_$Scalars> + } + + // --- expanded --- + + /** + * This is the "expanded" version of the \`stringWithArgInputObjectEnum\` type. It is identical except for the fact + * that IDEs will display its contents (a union type) directly, rather than the name of this type. + * In some cases, this is a preferable DX, making the types easier to read for users. + */ + export type stringWithArgInputObjectEnum$Expanded< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = $$Utilities.Simplify< + stringWithArgInputObjectEnum$SelectionSet<_$Scalars> + > + + // -------------------------------------------------------------------------------------------------- + export type stringWithArgInputObjectRequired< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = stringWithArgInputObjectRequired$SelectionSet<_$Scalars> @@ -6928,6 +7048,7 @@ export type ParentInterfaceHierarchyMember = export interface InputObject< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > { + $abcEnum?: $NamedTypes.$ABCEnum | undefined | null date?: | $$Utilities.Schema.Scalar.GetDecoded< $$Utilities.Schema.Scalar.LookupCustomScalarOrFallbackToString<'Date', _$Scalars> @@ -6953,6 +7074,12 @@ export interface InputObjectCircular< | null } +export interface InputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, +> { + $abcEnum?: $NamedTypes.$ABCEnum | undefined | null +} + export interface InputObjectNested< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > { @@ -9420,6 +9547,9 @@ export namespace $NamedTypes { export type $InputObjectCircular< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = InputObjectCircular<_$Scalars> + export type $InputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = InputObjectEnum<_$Scalars> export type $InputObjectNested< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = InputObjectNested<_$Scalars> diff --git a/src/lib/grafaid/request.ts b/src/lib/grafaid/request.ts index d6aa23b26..eb71827c6 100644 --- a/src/lib/grafaid/request.ts +++ b/src/lib/grafaid/request.ts @@ -26,9 +26,11 @@ export interface RequestAnalyzedDocumentNodeInput extends RequestDocumentNodeInp } export type Variables = { - [key: string]: string | boolean | null | number | Variables + [key: string]: VariableValue } +export type VariableValue = string | boolean | null | number | Variables | VariableValue[] + export type SomeObjectData = { [fieldName: string]: any // SomeFieldData <-- If we put this here tsc has crashes with OOM. } @@ -71,25 +73,33 @@ export const normalizeRequestToNode = <$R extends RequestInput | RequestAnalyzed } as any } -// todo: refactor into concise visitor pattern. -export const normalizeVariables = (variables?: Variables): Variables => { - return normalizeVariables_(variables) +export const mapVariables = ( + variables: Grafaid.Variables | undefined, + visitor: (key: string, value: Grafaid.VariableValue) => undefined | { key: string; value: Grafaid.VariableValue }, +): Grafaid.Variables | undefined => { + if (variables === undefined) return + return mapVariableValue(variables, visitor) } -const normalizeVariables_ = (value: unknown): any => { - if (value === undefined) return undefined - if (value === null) return null - if (typeof value !== `object`) return value - if (Array.isArray(value)) return value.map(normalizeVariables_) - if (!isPlainObject(value)) return value // todo: optimize - - const normalized: Variables = {} - - for (const key in value) { - const normalizedKey = key.replace(/^\$/, ``) - const normalizedValue = normalizeVariables_(value[key]) - normalized[normalizedKey] = normalizedValue +export const mapVariableValue = <$Value extends Grafaid.VariableValue>( + value: $Value, + visitor: (key: string, value: Grafaid.VariableValue) => undefined | { key: string; value: Grafaid.VariableValue }, +): $Value => { + if (Array.isArray(value)) { + return value.map(item => mapVariableValue(item, visitor)) as any + } else if (isPlainObject(value)) { + const newObject: Grafaid.Variables = {} + for (const currentKey in value) { + const currentValue = mapVariableValue(value[currentKey]!, visitor) + const visitorResult = visitor(currentKey, currentValue) + if (visitorResult) { + newObject[visitorResult.key] = visitorResult.value + } else { + newObject[currentKey] = currentValue + } + } + return newObject as any } - return normalized + return value } diff --git a/src/requestPipeline/RequestPipeline.ts b/src/requestPipeline/RequestPipeline.ts index 4d224ae34..4b1859be6 100644 --- a/src/requestPipeline/RequestPipeline.ts +++ b/src/requestPipeline/RequestPipeline.ts @@ -3,7 +3,7 @@ import type { GraffleExecutionResultEnvelope } from '../client/handleOutput.js' import { Anyware } from '../lib/anyware/__.js' import type { Config } from '../lib/anyware/PipelineDef/Config.js' import type { Grafaid } from '../lib/grafaid/__.js' -import { normalizeRequestToNode, normalizeVariables } from '../lib/grafaid/request.js' +import { normalizeRequestToNode } from '../lib/grafaid/request.js' import { isAbortError } from '../lib/prelude.js' import type { Context } from '../types/context.js' import { decodeResultData } from './CustomScalars/decode.js' @@ -90,10 +90,7 @@ export const requestPipelineBaseDefinition: RequestPipelineBaseDefinition = Anyw input.request.query = request.query encodeRequestVariables({ sddm, scalars, request }) - // input.request.variables = request.variables // enum $ stripping } - - input.request.variables = normalizeVariables(input.request.variables) return input }, }) diff --git a/tests/_/schemas/kitchen-sink/graffle/modules/methods-root.ts b/tests/_/schemas/kitchen-sink/graffle/modules/methods-root.ts index 1bfe6d8a1..e1fe8add1 100644 --- a/tests/_/schemas/kitchen-sink/graffle/modules/methods-root.ts +++ b/tests/_/schemas/kitchen-sink/graffle/modules/methods-root.ts @@ -673,6 +673,26 @@ export interface QueryMethods<$Context extends $$Utilities.Context> { > > + stringWithArgInputObjectEnum: $$Utilities.ClientTransports.PreflightCheck< + $Context, + <$SelectionSet>( + selectionSet: $$Utilities.Exact< + $SelectionSet, + $$SelectionSets.Query.stringWithArgInputObjectEnum<$Context['scalars']> + >, + ) => Promise< + & (null | {}) + & $$Utilities.HandleOutputGraffleRootField< + $Context, + InferResult.OperationQuery< + { stringWithArgInputObjectEnum: $SelectionSet }, + $$Schema.Schema<$Context['scalars']> + >, + 'stringWithArgInputObjectEnum' + > + > + > + stringWithArgInputObjectRequired: $$Utilities.ClientTransports.PreflightCheck< $Context, <$SelectionSet>( diff --git a/tests/_/schemas/kitchen-sink/graffle/modules/schema-driven-data-map.ts b/tests/_/schemas/kitchen-sink/graffle/modules/schema-driven-data-map.ts index 7e2a524bb..4d186f039 100644 --- a/tests/_/schemas/kitchen-sink/graffle/modules/schema-driven-data-map.ts +++ b/tests/_/schemas/kitchen-sink/graffle/modules/schema-driven-data-map.ts @@ -110,6 +110,7 @@ const InputObject: $$Utilities.SchemaDrivenDataMap.InputObject = { n: 'InputObject', fcs: ['date', 'dateRequired'], f: { + abcEnum: {}, date: { nt: Date, }, @@ -134,6 +135,13 @@ const InputObjectCircular: $$Utilities.SchemaDrivenDataMap.InputObject = { }, } +const InputObjectEnum: $$Utilities.SchemaDrivenDataMap.InputObject = { + n: 'InputObjectEnum', + f: { + abcEnum: {}, + }, +} + const InputObjectNested: $$Utilities.SchemaDrivenDataMap.InputObject = { n: 'InputObjectNested', fcs: ['InputObject'], @@ -644,6 +652,14 @@ const Query: $$Utilities.SchemaDrivenDataMap.OutputObject = { }, }, }, + stringWithArgInputObjectEnum: { + a: { + input: { + nt: InputObjectEnum, + it: [1], + }, + }, + }, stringWithArgInputObjectRequired: { a: { input: { @@ -815,6 +831,7 @@ const $schemaDrivenDataMap: $$Utilities.SchemaDrivenDataMap = { ParentInterfaceHierarchyMember, InputObject, InputObjectCircular, + InputObjectEnum, InputObjectNested, InputObjectNestedNonNull, Bar, diff --git a/tests/_/schemas/kitchen-sink/graffle/modules/schema.ts b/tests/_/schemas/kitchen-sink/graffle/modules/schema.ts index 4a798412f..8f1167574 100644 --- a/tests/_/schemas/kitchen-sink/graffle/modules/schema.ts +++ b/tests/_/schemas/kitchen-sink/graffle/modules/schema.ts @@ -72,6 +72,7 @@ export namespace Schema { string: Query.$string stringWithArgEnum: Query.stringWithArgEnum stringWithArgInputObject: Query.stringWithArgInputObject + stringWithArgInputObjectEnum: Query.stringWithArgInputObjectEnum stringWithArgInputObjectRequired: Query.stringWithArgInputObjectRequired stringWithArgs: Query.stringWithArgs stringWithListArg: Query.stringWithListArg @@ -571,6 +572,20 @@ export namespace Schema { namedType: $$NamedTypes.$$String } + export interface stringWithArgInputObjectEnum extends $.OutputField { + name: 'stringWithArgInputObjectEnum' + arguments: { + input: { + kind: 'InputField' + name: 'input' + inlineType: [1] + namedType: $$NamedTypes.$$InputObjectEnum + } + } + inlineType: [0] + namedType: $$NamedTypes.$$String + } + export interface stringWithArgInputObjectRequired extends $.OutputField { name: 'stringWithArgInputObjectRequired' arguments: { @@ -1483,6 +1498,7 @@ export namespace Schema { name: 'InputObject' isAllFieldsNullable: true fields: { + abcEnum: InputObject.abcEnum date: InputObject.date dateRequired: InputObject.dateRequired id: InputObject.id @@ -1491,6 +1507,12 @@ export namespace Schema { } export namespace InputObject { + export interface abcEnum extends $.InputField { + name: 'abcEnum' + inlineType: [0] + namedType: $$NamedTypes.$$ABCEnum + } + export interface date extends $.InputField { name: 'date' inlineType: [0] @@ -1543,6 +1565,26 @@ export namespace Schema { } } + // InputObjectEnum + // -------------------------------------------------------------------------------------------------- + // + + export interface InputObjectEnum extends $.InputObject { + name: 'InputObjectEnum' + isAllFieldsNullable: true + fields: { + abcEnum: InputObjectEnum.abcEnum + } + } + + export namespace InputObjectEnum { + export interface abcEnum extends $.InputField { + name: 'abcEnum' + inlineType: [0] + namedType: $$NamedTypes.$$ABCEnum + } + } + // InputObjectNested // -------------------------------------------------------------------------------------------------- // @@ -2216,6 +2258,7 @@ export namespace Schema { export type $$lowerCaseObject2 = lowerCaseObject2 export type $$InputObject = InputObject export type $$InputObjectCircular = InputObjectCircular + export type $$InputObjectEnum = InputObjectEnum export type $$InputObjectNested = InputObjectNested export type $$InputObjectNestedNonNull = InputObjectNestedNonNull export type $$DateInterface1 = DateInterface1 diff --git a/tests/_/schemas/kitchen-sink/graffle/modules/selection-sets.ts b/tests/_/schemas/kitchen-sink/graffle/modules/selection-sets.ts index 46036fab8..c808ff595 100644 --- a/tests/_/schemas/kitchen-sink/graffle/modules/selection-sets.ts +++ b/tests/_/schemas/kitchen-sink/graffle/modules/selection-sets.ts @@ -271,6 +271,12 @@ export interface Query< stringWithArgInputObject?: | Query.stringWithArgInputObject$Expanded<_$Scalars> | $Select.SelectAlias.SelectAlias> + /** + * Select the `stringWithArgInputObjectEnum` field on the `Query` object. Its type is `String` (a `ScalarStandard` kind of type). + */ + stringWithArgInputObjectEnum?: + | Query.stringWithArgInputObjectEnum<_$Scalars> + | $Select.SelectAlias.SelectAlias> /** * Select the `stringWithArgInputObjectRequired` field on the `Query` object. Its type is `String` (a `ScalarStandard` kind of type). */ @@ -1669,6 +1675,40 @@ export namespace Query { // -------------------------------------------------------------------------------------------------- + export type stringWithArgInputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = stringWithArgInputObjectEnum$SelectionSet<_$Scalars> + + export interface stringWithArgInputObjectEnum$SelectionSet< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > extends $Select.Bases.Base { + /** + * Arguments for `stringWithArgInputObjectEnum` field. All arguments are required so you must include this. + */ + $: stringWithArgInputObjectEnum$Arguments<_$Scalars> + } + + export interface stringWithArgInputObjectEnum$Arguments< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > { + input: $NamedTypes.$InputObjectEnum<_$Scalars> + } + + // --- expanded --- + + /** + * This is the "expanded" version of the `stringWithArgInputObjectEnum` type. It is identical except for the fact + * that IDEs will display its contents (a union type) directly, rather than the name of this type. + * In some cases, this is a preferable DX, making the types easier to read for users. + */ + export type stringWithArgInputObjectEnum$Expanded< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = $$Utilities.Simplify< + stringWithArgInputObjectEnum$SelectionSet<_$Scalars> + > + + // -------------------------------------------------------------------------------------------------- + export type stringWithArgInputObjectRequired< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = stringWithArgInputObjectRequired$SelectionSet<_$Scalars> @@ -2145,6 +2185,7 @@ export type ParentInterfaceHierarchyMember = export interface InputObject< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > { + $abcEnum?: $NamedTypes.$ABCEnum | undefined | null date?: | $$Utilities.Schema.Scalar.GetDecoded< $$Utilities.Schema.Scalar.LookupCustomScalarOrFallbackToString<'Date', _$Scalars> @@ -2170,6 +2211,12 @@ export interface InputObjectCircular< | null } +export interface InputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, +> { + $abcEnum?: $NamedTypes.$ABCEnum | undefined | null +} + export interface InputObjectNested< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > { @@ -4637,6 +4684,9 @@ export namespace $NamedTypes { export type $InputObjectCircular< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = InputObjectCircular<_$Scalars> + export type $InputObjectEnum< + _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, + > = InputObjectEnum<_$Scalars> export type $InputObjectNested< _$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty, > = InputObjectNested<_$Scalars> diff --git a/tests/_/schemas/kitchen-sink/graffle/schema.graphql b/tests/_/schemas/kitchen-sink/graffle/schema.graphql index f847cbd14..52801fc57 100644 --- a/tests/_/schemas/kitchen-sink/graffle/schema.graphql +++ b/tests/_/schemas/kitchen-sink/graffle/schema.graphql @@ -75,6 +75,7 @@ enum GrandparentInterfaceHierarchyMember { } input InputObject { + abcEnum: ABCEnum date: Date dateRequired: Date! id: ID @@ -86,6 +87,10 @@ input InputObjectCircular { date: Date } +input InputObjectEnum { + abcEnum: ABCEnum +} + input InputObjectNested { InputObject: InputObject } @@ -230,6 +235,7 @@ type Query { string: String stringWithArgEnum(ABCEnum: ABCEnum): String stringWithArgInputObject(input: InputObject): String + stringWithArgInputObjectEnum(input: InputObjectEnum!): String stringWithArgInputObjectRequired(input: InputObject!): String """The given arguments are reflected back as a JSON string.""" diff --git a/tests/_/schemas/kitchen-sink/schema.ts b/tests/_/schemas/kitchen-sink/schema.ts index 807edceac..0d6b28a76 100644 --- a/tests/_/schemas/kitchen-sink/schema.ts +++ b/tests/_/schemas/kitchen-sink/schema.ts @@ -226,6 +226,13 @@ const InputObject = builder.inputType(`InputObject`, { idRequired: t.id({ required: true }), date: t.field({ type: `Date` }), dateRequired: t.field({ type: `Date`, required: true }), + abcEnum: t.field({ type: ABCEnum }), + }), +}) + +const InputObjectEnum = builder.inputType(`InputObjectEnum`, { + fields: t => ({ + abcEnum: t.field({ type: ABCEnum }), }), }) @@ -463,6 +470,11 @@ builder.queryType({ args: { ABCEnum: t.arg({ type: ABCEnum }) }, resolve: (_, args) => args.ABCEnum, }), + stringWithArgInputObjectEnum: t.field({ + type: `String`, + args: { input: t.arg({ type: InputObjectEnum, required: true }) }, + resolve: (_, args) => args.input.abcEnum, + }), stringWithListArg: t.field({ type: `String`, args: { ints: t.arg({ type: t.arg.listRef(`Int`, { required: false }) }) }, diff --git a/website/content/_snippets/examples/extension/opentelemetry.detail.md b/website/content/_snippets/examples/extension/opentelemetry.detail.md index 54fd335b7..a2456e4c4 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.detail.md +++ b/website/content/_snippets/examples/extension/opentelemetry.detail.md @@ -43,14 +43,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'encode', - id: 'f723a4047c4f8246', + id: '1ef2540c3612ae74', kind: 0, - timestamp: 1734878385686000, - duration: 1952.542, + timestamp: 1735104630493000, + duration: 965.459, attributes: {}, status: { code: 0 }, events: [], @@ -70,14 +70,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'pack', - id: '8404e21eb12fbc92', + id: '12dbd874c3b489ce', kind: 0, - timestamp: 1734878385689000, - duration: 12830.875, + timestamp: 1735104630495000, + duration: 10833.958, attributes: {}, status: { code: 0 }, events: [], @@ -97,14 +97,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'exchange', - id: 'c5691fe0bcfc9991', + id: '837a3ca4af1a71df', kind: 0, - timestamp: 1734878385703000, - duration: 20900.792, + timestamp: 1735104630506000, + duration: 19948.584, attributes: {}, status: { code: 0 }, events: [], @@ -124,14 +124,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'unpack', - id: 'bafdd78624e21445', + id: '392e6c2ad292f089', kind: 0, - timestamp: 1734878385724000, - duration: 992.417, + timestamp: 1735104630526000, + duration: 1046.75, attributes: {}, status: { code: 0 }, events: [], @@ -151,14 +151,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'decode', - id: '32fa8b5942d69ca9', + id: 'f6f9b43acdbbb5d3', kind: 0, - timestamp: 1734878385725000, - duration: 446.542, + timestamp: 1735104630528000, + duration: 480.041, attributes: {}, status: { code: 0 }, events: [], @@ -178,14 +178,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', + traceId: '2d49d55d453267b20a3306c412c2c4bb', parentId: undefined, traceState: undefined, name: 'request', - id: '45c84f0a43771166', + id: '3294547ab163e342', kind: 0, - timestamp: 1734878385686000, - duration: 39771.791, + timestamp: 1735104630492000, + duration: 35822.333, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/extension/opentelemetry.md b/website/content/_snippets/examples/extension/opentelemetry.md index bf91b8937..709cef877 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.md +++ b/website/content/_snippets/examples/extension/opentelemetry.md @@ -41,14 +41,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'encode', - id: 'f723a4047c4f8246', + id: '1ef2540c3612ae74', kind: 0, - timestamp: 1734878385686000, - duration: 1952.542, + timestamp: 1735104630493000, + duration: 965.459, attributes: {}, status: { code: 0 }, events: [], @@ -68,14 +68,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'pack', - id: '8404e21eb12fbc92', + id: '12dbd874c3b489ce', kind: 0, - timestamp: 1734878385689000, - duration: 12830.875, + timestamp: 1735104630495000, + duration: 10833.958, attributes: {}, status: { code: 0 }, events: [], @@ -95,14 +95,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'exchange', - id: 'c5691fe0bcfc9991', + id: '837a3ca4af1a71df', kind: 0, - timestamp: 1734878385703000, - duration: 20900.792, + timestamp: 1735104630506000, + duration: 19948.584, attributes: {}, status: { code: 0 }, events: [], @@ -122,14 +122,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'unpack', - id: 'bafdd78624e21445', + id: '392e6c2ad292f089', kind: 0, - timestamp: 1734878385724000, - duration: 992.417, + timestamp: 1735104630526000, + duration: 1046.75, attributes: {}, status: { code: 0 }, events: [], @@ -149,14 +149,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'decode', - id: '32fa8b5942d69ca9', + id: 'f6f9b43acdbbb5d3', kind: 0, - timestamp: 1734878385725000, - duration: 446.542, + timestamp: 1735104630528000, + duration: 480.041, attributes: {}, status: { code: 0 }, events: [], @@ -176,14 +176,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', + traceId: '2d49d55d453267b20a3306c412c2c4bb', parentId: undefined, traceState: undefined, name: 'request', - id: '45c84f0a43771166', + id: '3294547ab163e342', kind: 0, - timestamp: 1734878385686000, - duration: 39771.791, + timestamp: 1735104630492000, + duration: 35822.333, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/output/envelope.detail.md b/website/content/_snippets/examples/output/envelope.detail.md index c9bd3962f..358a06fa5 100644 --- a/website/content/_snippets/examples/output/envelope.detail.md +++ b/website/content/_snippets/examples/output/envelope.detail.md @@ -44,7 +44,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Sun, 22 Dec 2024 14:39:45 GMT', + date: 'Wed, 25 Dec 2024 05:30:30 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/_snippets/examples/output/envelope.md b/website/content/_snippets/examples/output/envelope.md index bd4769b4d..441ec6768 100644 --- a/website/content/_snippets/examples/output/envelope.md +++ b/website/content/_snippets/examples/output/envelope.md @@ -42,7 +42,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Sun, 22 Dec 2024 14:39:45 GMT', + date: 'Wed, 25 Dec 2024 05:30:30 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md b/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md index cbfc55af0..d953cd07f 100644 --- a/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md +++ b/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md @@ -46,7 +46,7 @@ await graffle.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1734878384165' + 'x-sent-at-time': '1735104630184' }, method: 'post', url: 'http://localhost:3000/graphql', diff --git a/website/content/_snippets/examples/transport-http/dynamic-headers.md b/website/content/_snippets/examples/transport-http/dynamic-headers.md index 8ae50edc4..b7822c089 100644 --- a/website/content/_snippets/examples/transport-http/dynamic-headers.md +++ b/website/content/_snippets/examples/transport-http/dynamic-headers.md @@ -44,7 +44,7 @@ await graffle.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1734878384165' + 'x-sent-at-time': '1735104630184' }, method: 'post', url: 'http://localhost:3000/graphql', diff --git a/website/content/_snippets/examples/type-level/selection-sets.detail.md b/website/content/_snippets/examples/type-level/selection-sets.detail.md index 54c4ad379..193bad68a 100644 --- a/website/content/_snippets/examples/type-level/selection-sets.detail.md +++ b/website/content/_snippets/examples/type-level/selection-sets.detail.md @@ -122,7 +122,6 @@ const getPokemonsLike = async (filter: Graffle.SelectionSets.Query.pokemons$Argu name: true, }) -// todo add test coverage for $ stripping on arguments. const pokemons = await getPokemonsLike({ $type: `water` }) // We don't lose any type safety. :) diff --git a/website/content/_snippets/examples/type-level/selection-sets.md b/website/content/_snippets/examples/type-level/selection-sets.md index 2841721de..5d8a598ca 100644 --- a/website/content/_snippets/examples/type-level/selection-sets.md +++ b/website/content/_snippets/examples/type-level/selection-sets.md @@ -120,7 +120,6 @@ const getPokemonsLike = async (filter: Graffle.SelectionSets.Query.pokemons$Argu name: true, }) -// todo add test coverage for $ stripping on arguments. const pokemons = await getPokemonsLike({ $type: `water` }) // We don't lose any type safety. :) diff --git a/website/content/examples/10_transport-http/dynamic-headers.md b/website/content/examples/10_transport-http/dynamic-headers.md index 9ddedb839..99e2fbf04 100644 --- a/website/content/examples/10_transport-http/dynamic-headers.md +++ b/website/content/examples/10_transport-http/dynamic-headers.md @@ -51,7 +51,7 @@ await graffle.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1734878384165' + 'x-sent-at-time': '1735104630184' }, method: 'post', url: 'http://localhost:3000/graphql', diff --git a/website/content/examples/20_output/envelope.md b/website/content/examples/20_output/envelope.md index 71981ff1e..922581106 100644 --- a/website/content/examples/20_output/envelope.md +++ b/website/content/examples/20_output/envelope.md @@ -49,7 +49,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Sun, 22 Dec 2024 14:39:45 GMT', + date: 'Wed, 25 Dec 2024 05:30:30 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/examples/60_extension/opentelemetry.md b/website/content/examples/60_extension/opentelemetry.md index 439c6a8fe..e75a17d56 100644 --- a/website/content/examples/60_extension/opentelemetry.md +++ b/website/content/examples/60_extension/opentelemetry.md @@ -46,14 +46,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'encode', - id: 'f723a4047c4f8246', + id: '1ef2540c3612ae74', kind: 0, - timestamp: 1734878385686000, - duration: 1952.542, + timestamp: 1735104630493000, + duration: 965.459, attributes: {}, status: { code: 0 }, events: [], @@ -73,14 +73,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'pack', - id: '8404e21eb12fbc92', + id: '12dbd874c3b489ce', kind: 0, - timestamp: 1734878385689000, - duration: 12830.875, + timestamp: 1735104630495000, + duration: 10833.958, attributes: {}, status: { code: 0 }, events: [], @@ -100,14 +100,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'exchange', - id: 'c5691fe0bcfc9991', + id: '837a3ca4af1a71df', kind: 0, - timestamp: 1734878385703000, - duration: 20900.792, + timestamp: 1735104630506000, + duration: 19948.584, attributes: {}, status: { code: 0 }, events: [], @@ -127,14 +127,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'unpack', - id: 'bafdd78624e21445', + id: '392e6c2ad292f089', kind: 0, - timestamp: 1734878385724000, - duration: 992.417, + timestamp: 1735104630526000, + duration: 1046.75, attributes: {}, status: { code: 0 }, events: [], @@ -154,14 +154,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', - parentId: '45c84f0a43771166', + traceId: '2d49d55d453267b20a3306c412c2c4bb', + parentId: '3294547ab163e342', traceState: undefined, name: 'decode', - id: '32fa8b5942d69ca9', + id: 'f6f9b43acdbbb5d3', kind: 0, - timestamp: 1734878385725000, - duration: 446.542, + timestamp: 1735104630528000, + duration: 480.041, attributes: {}, status: { code: 0 }, events: [], @@ -181,14 +181,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '7adcc8f82ea6b22e5d53dc12a862e3b7', + traceId: '2d49d55d453267b20a3306c412c2c4bb', parentId: undefined, traceState: undefined, name: 'request', - id: '45c84f0a43771166', + id: '3294547ab163e342', kind: 0, - timestamp: 1734878385686000, - duration: 39771.791, + timestamp: 1735104630492000, + duration: 35822.333, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/examples/70_type-level/selection-sets.md b/website/content/examples/70_type-level/selection-sets.md index d7c5f0a84..b662638ca 100644 --- a/website/content/examples/70_type-level/selection-sets.md +++ b/website/content/examples/70_type-level/selection-sets.md @@ -125,7 +125,6 @@ const getPokemonsLike = async (filter: Graffle.SelectionSets.Query.pokemons$Argu name: true, }) -// todo add test coverage for $ stripping on arguments. const pokemons = await getPokemonsLike({ $type: `water` }) // We don't lose any type safety. :)