graphqlite
graphqlite copied to clipboard
Impossibility to return a Deferred Array
I'm making use of the webonyx/graphql-php Deferred type as I find them more intuitive to use than the prefetch option.
However I'm having trouble returning an Deferred type in a field which is supposed to be an array.
As a temporary solution, I'm returning an Array of Deferred, but I find this suboptimal, has the deferred value could resolve to null, and I would end up with null values in an array.
Is it possible to return a Deferred Array?
An example schema would be:
type Purchase {
id: ID!
item: [PurchaseItem]
}
type PurchaseItem {
product_id: String
quantity: Int
}
In this scenario, I want want to defer the resolution of Purchase.item.
Oh! It never occured to me that you could return a Deferred
in a GraphQLite field. Does it work? :)
Indeed, the "prefetch" option is supposed to be used in those cases (I always thought this was the only option and never realized you could do this with a Deferred
!)
Out of curiosity, what syntax would you like to use (in an ideal world) to declare an array of deferred?
Ah :) Yeap, It works great. At least never noticed a problem until now. The only problem I faced so far was with returning a Deferred for an array type. When outputting, validations expect the value to be iterable + it actually tries to iterate the deferred object.
In the ideal world I wouldn't need to do anything. Internally, it would check if it was a deferred and post pone the validation and any further work. Without much knowledge on how graphqlite works, my guess is that isn't so simple to implement , since Deferreds are only resolved at the graphql-php level.
Is this really something we should be considering as part of this lib? How would Deferred
objects be detected? AFAIK there aren't any native Deferred
interfaces.