-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expected iterable, but did not find one for field Query.XXXX #10
Comments
I ran into a very similar issue. I would expect User.fetchAll() to work, though yes instead of an iterable GraphQL is getting a Promise (Promises are fine, as GraphQL will execute the .then on the promise). The way I got around this would be by doing the following:
Personally I think that this library should be resolving the collection into a list of things, but that might just be me @brysgo what do you think? |
@tmack8001 Thanks for replying! I don't think the promise itself is a problem, but your better insight into Bookshelf collections sizes down the problem to: resolve: () => User.fetchAll().then(collection => collection.models), So you actually don't have to do |
@tmack8001 - There are plenty of ways to make this library more convenient and I'm open to adding as many as possible. |
Of course, I am just starting to look at graphQL for a personal project I have been meaning to work on so as I get dirtier with it I will ping out with questions or requests. Do you think we should encapsulate this Collection -> Iterable within this library? If so, I can work on getting a PR together after diving into things. I've also been thinking about #5 a little bit, as I'm building pagination into my implementation returning a list. That we would also probably bake in for ease of use for adopters. |
I think encapsulating the collection is a great idea. As soon as you have something, put it up and I'll check it out. As for #5, I've been working with relay more so if you have any relay helpers you end up making I'd be happy to take a look also. |
Thinking about this further, how would one go about doing this. Since in the schema definition we aren't using any encapsulation with this library. We could add a helper around the relationship, but I don't see another way since the query type isn't related to graphql-bookshelf. |
Right, we would need to provide proxies to bookshelf classes that add functionality. Alternatively, we could wrap every resolve on a bookshelf type and check for collections that get returned. |
in feathersjs case, @prewk answer works well.
|
Hello! I'm trying to wire up a User model with two GraphQL query fields.
The type:
The schema:
I can query one user just fine with
{ user(id: 1) { id, email, role } }
.However, if I query the all users field
{ users { id, email, role } }
I get this error:User Error: expected iterable, but did not find one for field Query.users.
I guess it's complaining about
type: new GraphlQLList(userType)
as return type? It's expecting an iterable but gets a Bookshelf Collection, right?If I force it to return an array instead of a collection it works:
What am I doing wrong here?
The text was updated successfully, but these errors were encountered: