diff --git a/__tests__/starwars/starwars.api.ts b/__tests__/starwars/starwars.api.ts index 1deae7b..b487970 100644 --- a/__tests__/starwars/starwars.api.ts +++ b/__tests__/starwars/starwars.api.ts @@ -1,7 +1,6 @@ import { NamedType, Argument, - Value, Field, InlineFragment, Operation, @@ -425,7 +424,9 @@ interface HumanSelector { * @description Height in the preferred unit, default is meters */ - height: (variables: { unit: unknown }) => Field<"height", [/* @todo */]>; + height: (variables: { + unit?: Variable<"unit"> | LengthUnit; + }) => Field<"height", [Argument<"unit", Variable<"unit"> | LengthUnit>]>; /** * @description Mass in kilograms, or null if unknown @@ -875,7 +876,9 @@ interface StarshipSelector { * @description Length of the starship, along the longest axis */ - length: (variables: { unit: unknown }) => Field<"length", [/* @todo */]>; + length: (variables: { + unit?: Variable<"unit"> | LengthUnit; + }) => Field<"length", [Argument<"unit", Variable<"unit"> | LengthUnit>]>; coordinates: () => Field<"coordinates">; } diff --git a/examples/apollo-client/index.ts b/examples/apollo-client/index.ts index deb1b43..3b4887e 100644 --- a/examples/apollo-client/index.ts +++ b/examples/apollo-client/index.ts @@ -1,7 +1,11 @@ import { ApolloClient, InMemoryCache } from "@apollo/client"; import { Result } from "../../src"; -import { query, IQuery } from "../../__tests__/starwars/starwars.api"; +import { + query, + IQuery, + LengthUnit, +} from "../../__tests__/starwars/starwars.api"; const client = new ApolloClient({ cache: new InMemoryCache() }); @@ -9,7 +13,7 @@ const example = query("Apollo Example", (t) => [ t.starship({ id: "foo" }, (t) => [ t.id(), t.name(), - t.length({ unit: "any" }), + t.length({ unit: LengthUnit.FOOT }), t.coordinates(), ]), ]); diff --git a/src/Codegen.ts b/src/Codegen.ts index 308e0ce..a908ddd 100644 --- a/src/Codegen.ts +++ b/src/Codegen.ts @@ -42,7 +42,6 @@ export class Codegen { import { NamedType, Argument, - Value, Field, InlineFragment, Operation, @@ -455,14 +454,14 @@ export class Codegen { ? toPrimitive(baseType) : baseType.name; - // @todo render arguments correctly return args.length > 0 ? `${jsDocComment}\n${name}: (variables: { ${args - .map((a) => `${a.name}: unknown`) - .join(", ")} }) => Field<"${name}", [/* @todo */]>` + .map(renderVariable) + .join(", ")} }) => Field<"${name}", [ ${args + .map(renderArgument) + .join(", ")} ]>` : `${jsDocComment}\n${name}: () => Field<"${name}">`; } else { - // @todo render arguments correctly // @todo restrict allowed Field types return args.length > 0 ? ` @@ -486,10 +485,6 @@ export class Codegen { private field(field: GraphQLField): string { const { name, args, type } = field; - const isList = - type instanceof GraphQLList || - (type instanceof GraphQLNonNull && type.ofType instanceof GraphQLList); - const isNonNull = type instanceof GraphQLNonNull; const baseType = getBaseOutputType(type); const jsDocComments = [ @@ -510,11 +505,6 @@ export class Codegen { baseType instanceof GraphQLScalarType || baseType instanceof GraphQLEnumType ) { - const fieldType = - baseType instanceof GraphQLScalarType - ? toPrimitive(baseType) - : baseType.name; - // @todo render arguments correctly return args.length > 0 ? jsDocComment.concat(`${name}: (variables) => new Field("${name}"),`) @@ -529,7 +519,6 @@ export class Codegen { : `new Argument("${arg.name}", variables.${arg.name})`; }; - // @todo render arguments correctly // @todo restrict allowed Field types return args.length > 0 ? `