Prisma1: Cannot return list of objects from custom query

Created on 8 Sep 2017  路  4Comments  路  Source: prisma/prisma1

Issue by FredyC
_Sunday Aug 20, 2017 at 19:54 GMT_
_Originally opened as https://github.com/graphcool/api-bugs/issues/239_


What is the current behavior?
Trying to run a custom query that returns the list of objects ends up with following error:

The return value should include a 'data' field of type object

Please share the relevant part of your GraphQL schema and all functions, permissions or other project settings for easier reproduction

type ItemAccess {
  id: String!
  access: String!
}

extend type Query {
  access: [ItemAccess!]!
}
module.exports = function test() {
  return {
    data: [{
      id: 'foo',
      access: 'all',
    }],
  }
}

If applicable, share the query, mutation or subscription for reproduction

query {
  access { id }
}

What is the expected behavior?
Returning list of object is possible.

Most helpful comment

We now enabled this. Before no matter the list and required status that was defined, we handled the returnValue as optional non-list.

These are the formats we accept and handle now:

  • PayloadType -> non-list optional. Will accept {data: PayloadType}, {data: null} and soon {} as response.
  • PayloadType! -> non-list required. Will accept {data: PayloadType} as response.
    *[PayloadType!] -> list optional. Will accept {data: [PayloadType]}, {data: []}, {data: null} and soon {} as response.
    *[PayloadType!]! -> list required. Will accept {data: [PayloadType]} and {data: []} as response.

All 4 comments

The interface for errors is not as straightforward as the one for data. Should error be an object, or a list of objects?

We now enabled this. Before no matter the list and required status that was defined, we handled the returnValue as optional non-list.

These are the formats we accept and handle now:

  • PayloadType -> non-list optional. Will accept {data: PayloadType}, {data: null} and soon {} as response.
  • PayloadType! -> non-list required. Will accept {data: PayloadType} as response.
    *[PayloadType!] -> list optional. Will accept {data: [PayloadType]}, {data: []}, {data: null} and soon {} as response.
    *[PayloadType!]! -> list required. Will accept {data: [PayloadType]} and {data: []} as response.

In all cases, for returning an error, the error property needs to be used, no matter the payload type:

// for PayloadType, PayloadType!, [PayloadType!], [PayloadType!]!
return { error: "Something bad happened!" }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

akoenig picture akoenig  路  3Comments

MitkoTschimev picture MitkoTschimev  路  3Comments

Fi1osof picture Fi1osof  路  3Comments

tbrannam picture tbrannam  路  3Comments

schickling picture schickling  路  3Comments