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

Add defer and stream directives as extension #1134

Open
jasonkuhrt opened this issue Sep 26, 2024 · 5 comments
Open

Add defer and stream directives as extension #1134

jasonkuhrt opened this issue Sep 26, 2024 · 5 comments

Comments

@jasonkuhrt
Copy link
Member

jasonkuhrt commented Sep 26, 2024

Perceived Problem

Right now defer and stream are hardcoded types of directives. In fact though at least Yoga still does not support them out of the box citing their being experimental.

This is a problem for Graffle since it suggests these directives are available when they may not be.

https://the-guild.dev/graphql/yoga-server/docs/features/defer-stream

Defer and stream are forthcoming directives to be standardized in the coming year or two.

Make them available to Graffle users.

Ideas / Proposed Solution(s)

  • Make it possible to add directives via extensions
  • Make defer and stream extensions
  • Let users opt into them
  • These directives can only appear on inline and spread fragments, a further restriction to factor into the extension system
  • When these directives are used anyware in the selection set then:
    • static type return value must become asynchronous iterator
    • any labels used should be statically realized on the return type incrementally delivered items
    • runtime must also become an asynchronous iterator too of course
    • internal unpack hook needs to not assume json response
@jasonkuhrt jasonkuhrt changed the title Do not assume defer and stream Add defer and stream directives as extension Sep 27, 2024
@VinceBT-BG
Copy link

The proposals will be validated soon btw.
We are currently using graphql-request in my team and we cannot wait for this library to support at least @defer, this would be a game changer.

@jasonkuhrt
Copy link
Member Author

@VinceBT-BG thanks for sharing this feedback, it really helps me prioritize work if I know delivering something is going to immediately unblock/accelerate someone(s).

If you have any more feedback about what kind of API you'd like to see, easily with regards to the Document Builder, would be happy to hear it!

I'm thinking of using async iterators (which should then be easily convertible to observables), but haven't thought deeply about this yet.

@VinceBT-BG
Copy link

For defer it looks like other libraries use a "deep partial" format of the data, which lets the user decide how to handle it within its own framework (with memoization etc) and I think that's cool. Maybe it could be the same for stream as well since it's like a "partial version" of the queried array.
Here's an example of what a typed query with deferred complexField gives with gql.tada
Capture d’écran 2025-01-09 à 11 51 59

@jasonkuhrt
Copy link
Member Author

I'm confused though, results arrive over time, right? So how is an Array data structure modelling that?

@VinceBT-BG
Copy link

I'm sorry here my type was an array in my project when I modified to make the screenshot
You can see my example as a listComplexObjects query with its result being like an array of:
{ id: string, complexField?: { fieldA: boolean, fieldB: boolean, fieldC: boolean } }

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

No branches or pull requests

2 participants