Prisma 1 Forum

Returning an array from a SE

It seems possible to define a function in the SE SDL that returns an array, but I can’t find any way to actually return an array of values from the function.


type AdditionPayload {
  sum: Int!

extend type Query {
  add(a: Int! b: Int!): [AdditionPayload!]!

Various (non-working) return statements:

return [{data: { sum: 1}},{data: { sum: 2}}] // Internal server error
return {data: [{sum: 1}, {sum: 2}]} // The return value should include a 'data' field of type object
1 Like

I had a try and couldn’t find a solution to this.

It feels to me like your second non working example is how it should work - the system would just need to allow arrays as well as objects for the data field.

It is definitely something that should be supported in order to be able to write schema extension queries that behave similarly to the built in allX queries

1 Like

Currently, if I need to wrap an API that returns an array, the only workaround is to use one return type field with the [Json] type, so I loose any strong typing. So it’s really not a viable workaround at all.

It’s blocking for any SE query that returns an array.

That’s a great feature request, thanks for that @agartha :+1:

1 Like

Update: this is now implemented!

1 Like