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

return data via hashes #7

Open
MARTIMM opened this issue Dec 10, 2017 · 2 comments
Open

return data via hashes #7

MARTIMM opened this issue Dec 10, 2017 · 2 comments

Comments

@MARTIMM
Copy link

MARTIMM commented Dec 10, 2017

I understand that json is the vehicle to transport data from a server. But when the data is retrieved locally, it could also be stored in a hash. This would also be nice when I want to use lazy arrays or other object types which cannot be transported using json.

@CurtTilmes
Copy link
Owner

I'm not quite sure what you're proposing here.

I originally made hashes to hold all the data. I added "GraphQL::Response" for a few reasons.

One, to comply with the GraphQL spec, the order of the returns must match the order of the items in the JSON. Personally I think that violates the spirit of JSON and hashes, but there it is.

If you ask for "{ a b }" it must return

{
    "a" : ...
    "b" : ...
}

It can't return 'b' then 'a'..

GraphQL::Response also awaits any promises it finds, so you can return Promises throughout your results if you are still calculating the actual result. Once all the execution occurs, it walks the graph again to construct the actual JSON, awaiting any promises. This allows multiple results to be calculated in parallel. I haven't done much with that yet, but that was the idea ;). If anything about the interface is awkward, feel free to propose alternatives.

@MARTIMM
Copy link
Author

MARTIMM commented Dec 13, 2017

hi Curt,
Thanks for your answer. I've read that too from the spec. But I thought that it would be easier to return the data still in their perl6 context, but yes it violates the spec. I can also read out your structure instead of calling to-json on it.
Regards,
Marcel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants