Describe the Bug
I'm trying to create a custom scalar for a geojson position. A geojson position is a tuple of the form [longitute, latitude, eleveation?]. If I define the type (in Typescript) as such, when I use the scalar in an InputType, the type in the schema is always a list, regardless of the fact that I specify the field is not a list with @Field(() => Position).
So for example if I define an InputType Point,
type GeoJsonPosition = [number, number, elevation?]
const Position = new GraphQLScalarType(...)
@InputType()
export class Point {
@Field(() => Position)
coordinates: GeoJsonPosition
}
It appears in the schema as,
input Point {
coordinates: [Position!]!
}
To Reproduce
any[] or [...any]Expected Behavior
The type in the schema should not be a list. I'd expect the schema to look like this,
input Point {
coordinates: Position!
}
Environment (please complete the following information):
Additional Context
Here is a CodeSandbox that reproduces the problem: https://codesandbox.io/s/type-graphql-problem-lpof7
If I define the type (in Typescript) as such, when I use the scalar in an InputType, the type in the schema is always a list
That's the legacy behavior for explicit type in case of array, as TS cannot reflect string[], it's readed as Array.
So I allowed to pass the array item type, like:
@Field(() => String)
items: string[];
or
@Field(() => String, { isArray: true })
items: string[];
But then I switched to the array syntax, like @Field(() => [String]) and removed the isArray option but it's still infered from the TS type like in your case.
As a workaround, you can just write something like:
type TypeWorkaround<T> = T;
And then use it in your code:
@Field(() => Position)
coordinates: TypeWorkaround<GeoJsonPosition>;
I will try to remove the legacy reflection before the 1.0.0 release
Closing via b4afef4 馃敀