Broken promise behaviour when types used in list have async field resolve functions.
See original GitHub issueOkay, I’m still digging into this, and trying to simplify my examples, but it looks like something funky is going on with field resolve behaviour when promises are returned.
Here’s example code which demonstrates the behaviour (as well as the results) https://gist.github.com/latentflip/f1c9520ac0d83b5237fc note how in the results, projectPromises differs from projectResults.
Okay, to explain further, the basic setup I have is:
type Org {
id: String
projects: [Project]
}
type Project {
id: String
versions: ProjectVersion
}
type ProjectVersion {
id: String
}
and my root query just returns one org, so the query I’m executing is:
query Foo {
org {
id,
projects {
versions
}
}
}
which should return the org, all it’s projects, and all their versions.
However, it seems if my projects.versions
resolve function returns a promise, instead of immediately returning an array, something breaks. To demonstrate, in the actual code linked above, I’ve got a ProjectReturnType which just returns an array for it’s versions and a ProjectPromiseType which returns the same array, but wrapped in a Promise.resolve()
. The latter seems to break the projectPromises
in the response completely, and it just returns {}
.
As I understand it, a resolve function returning a value, or a resolve function returning a promise of that same value, should be exactly equivalent, right?
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (6 by maintainers)
Having almost same problem. I try to use type of “Customer” which fetch some data from SQL and some from MongoDb.
All fields comes from SQL besides “quiz”, resolve method for “quiz” return Mongoose promise which then return array of object. But on this query:
I get:
Any solution so far?
Thank YOU for playing with it in such an early state and investigating. I may not have found this issue otherwise.