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.
The interface for errors is not as straightforward as the one for data. Should error be an object, or a list of objects?
See https://github.com/graphcool/graphcool/issues/318#issuecomment-322230474 and https://www.graph.cool/forum/t/returning-an-array-from-a-se/763 for more discussions.
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!" }
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.