-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Okay, 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?