swarthout / feathers-apollo

Feathers and Apollo Server Sample Project
MIT License
176 stars 20 forks source link

Expected Iterable, but did not find one for field RootQuery.posts #8

Closed psi-4ward closed 8 years ago

psi-4ward commented 8 years ago

Hi!

First: THANKS! Its an amazing approach! But i ran into some Problems:

{posts(category:TECHNOLOGY) {
  _id
  title
  category
  summary
  content
  createdAt
}}

Result:

{
  "data": {
    "posts": null
  },
  "errors": [
    {
      "message": "Expected Iterable, but did not find one for field RootQuery.posts.",
      "locations": [
        {
          "line": 1,
          "column": 2
        }
      ]
    }
  ]
}

So it seems Apollo can not handle our result Object {total: 3, limit:0, data: [ ...

If i modify the resolver to only return the data Array it works:

      posts(root, {category}, context) {
        return Posts
          .find({query: { category }})
          .then(d => d.data);
      },

But the total, limit and skip Params are important to know about the data.

Edit

I used NeDB Data and not your mongoose models. Seems mongoose returns the plain array which works.

batjko commented 7 years ago

~I appreciate that you closed the issue because you solved the problem. But I'm not clear as to why we need to return an array, when we know there's only one object we want to return.~

~For example, I execute a mutation that adds an object to an array. I want to return just that new object. I get the error above if I return only the object, but it works fine if I wrap it in an array. Seems unnecessary to me.~

Never mind, my schema was still expecting to return a list, which I forgot to change.

Morriz commented 7 years ago

How is this solved? I also get this error when running the example code base and querying with a graphiql (middleware) client.

Morriz commented 7 years ago

Nevermind, I now merge {paginate:false} with every resolver query returning arrays.

Is there a way to get a new service object like app.services('myservice', true) so that we can set new defaults for it?

Morriz commented 7 years ago

Pffff...that would not be possible, as it would never match incoming requests