Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Cannot return list of objects from custom query #435

Closed
schickling opened this issue Sep 8, 2017 · 4 comments
Closed

Cannot return list of objects from custom query #435

schickling opened this issue Sep 8, 2017 · 4 comments
Assignees
Milestone

Comments

@schickling
Copy link
Member

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.

@marktani
Copy link
Contributor

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

@marktani
Copy link
Contributor

@marktani marktani modified the milestones: 1.4, 1.5 Sep 22, 2017
@do4gr
Copy link
Member

do4gr commented Sep 30, 2017

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.

@do4gr do4gr closed this as completed Sep 30, 2017
@marktani
Copy link
Contributor

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!" }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants