Type-graphql: How can I defined a two-dimension array?

Created on 13 Mar 2019  路  8Comments  路  Source: MichalLytek/type-graphql

Hey, everybody.
I want to get the value like [[1,2,3], [1,2,3]].
What should I do?

  @Field(() => [[Int]])
    key?: number[][];

It's not work!
It will report:

Cannot determine GraphQL output type for key

any advice is welcome.
Thank you!!!!

Community Enhancement Good First Issue

All 8 comments

Closing for a housekeeping purposes 馃敀

@19majkel94 I have the same problem, I can not find a solution, how to do it?

@Field(() => [[Int]]) configurationStart: number[][];

@Field(() => [[Int]]) configurationEnd: number[][];

Error: Cannot determine GraphQL output type for configurationStart

I really need it to be an array
Thank you :)

@Almesia It's not possible even in GraphQL spec:
https://github.com/graphql/graphql-spec/issues/423

@Almesia

hey man, my solution may be ugly, but it works.

import { GraphQLScalarType } from 'graphql';

export const NumberArrayScalar = new GraphQLScalarType({
    name: 'NumberArray',
    description: '',
    parseValue(value: number[]) {
        return value || [];
    },
    serialize(value: number[]) {
        return value || [];
    },
    parseLiteral(ast) {
        return ast || [];
    },
});

FYI 馃榿

Thank you 馃槃 That's all what i wanted

It actually is possible in the spec.

The example in that issue is with tuples in a list (ie. [[Int, Float]]) which is not allowed, but the spec does allow things such as the one here : [[Int]]. You can try it with the reference implementation and it should work.

I was able to generate something like this as an example:

image

@TDiazT

You are right 馃槈
It can be even N dimension array of the T type - I've checked the [[[Int!]!]!]!.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichalLytek picture MichalLytek  路  4Comments

MichalLytek picture MichalLytek  路  3Comments

Janushan picture Janushan  路  3Comments

Tybot204 picture Tybot204  路  3Comments

oliversalzburg picture oliversalzburg  路  3Comments