Skip to content
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

Impossibility to return a Deferred Array #187

Open
bmfs opened this issue Nov 26, 2019 · 3 comments
Open

Impossibility to return a Deferred Array #187

bmfs opened this issue Nov 26, 2019 · 3 comments
Labels
additional info needed Additional information is needed to proceed

Comments

@bmfs
Copy link

bmfs commented Nov 26, 2019

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.

@moufmouf
Copy link
Member

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?

@bmfs
Copy link
Author

bmfs commented Nov 27, 2019

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.

@oojacoboo
Copy link
Collaborator

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.

@oojacoboo oojacoboo added the additional info needed Additional information is needed to proceed label Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
additional info needed Additional information is needed to proceed
Projects
None yet
Development

No branches or pull requests

3 participants