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

@defer support #2624

Closed
wants to merge 6 commits into from
Closed

@defer support #2624

wants to merge 6 commits into from

Conversation

fiatjaf
Copy link
Contributor

@fiatjaf fiatjaf commented Apr 22, 2023

This implements @defer support according to https://github.com/graphql/graphql-wg/blob/66a80c7e7ff5d881a7de515eec991ca3150c829b/rfcs/DeferStream.md

There are no tests and there may be some bugs yet, but I'm just opening this to ask if this change is desired and/or if the code quality is too bad to be considered -- before I put more time polishing it and writing tests.

(Don't look at the first commit, please, just look at the final result.)

There is a demo app at https://github.com/fiatjaf/gqlgen-defer-demo, you can try it live on https://defer.fiatjaf.com/debug/. Only the fields availability, here and there are concurrent, so they're the only ones that can be deferred (the others will just return in the normal response regardless). Try the query

query {
  fruits {
    name
    color
    availability {
      ... on Availability @defer {
        there
      }
      here
    }
  }
}
screencast.mp4

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

@babymum7
Copy link

babymum7 commented May 16, 2023

Hi, Is you still working on this?

@fiatjaf
Copy link
Contributor Author

fiatjaf commented May 16, 2023

I'm waiting for feedback from the maintainers. Meanwhile I'm using this myself.

@StevenACoffman
Copy link
Collaborator

Sorry, I thought you were still working on it as it doesn't pass existing tests. I would love to have the defer feature supported, but it needs more work (e.g. passes existing tests) before I would feel comfortable merging it.

Linting the generated code is a good way to find problems in the templates that sometimes are hard to see.

@fiatjaf
Copy link
Contributor Author

fiatjaf commented May 18, 2023

Sorry, my time has expired, I don't know when I'll be able to come back to this. Hopefully soon, but if someone else wants to do it instead of me, please do it.

I do get very confused about the amount of examples and test code that exist in the repository. It's hard to understand what each thing is doing.

One question: do we need this to work with HTTP? I had forgotten about that possibility, was only thinking about websockets and SSE.

And also with mutation and subscription? My code is only working for query, I had forgotten about this too.

@UnAfraid
Copy link
Contributor

I made a patch that should fix most of the tests, only one left, but i am not sure how to fix that one.
https://gist.github.com/UnAfraid/35d119480d2f18d9ec43172bc699105b
go generate ./... after applying the patch

@fiatjaf
Copy link
Contributor Author

fiatjaf commented May 19, 2023

I am still confused about the role of root_.gotpl: #2621

@UnAfraid
Copy link
Contributor

I am not sure about it, but its used in a test

@StevenACoffman
Copy link
Collaborator

@UnAfraid I don't think your patch actually causes the tests to pass? I applied it locally, committed it, and pushed it to a branch (and then I ran go mod tidy: https://github.com/99designs/gqlgen/compare/defer_patched?expand=1

Try this:

go generate ./...; cd _examples; go generate ./...; cd ..; go test ./...; cd _examples; go generate ./...

@UnAfraid
Copy link
Contributor

UnAfraid commented May 19, 2023

@StevenACoffman here i've made a branch with my changes applied and also latest master changes
https://github.com/99designs/gqlgen/compare/master...UnAfraid:gqlgen:defer?expand=1
There is only one failing test which i am not sure how to address: TestLayouts
I managed to fix all tests

@StevenACoffman
Copy link
Collaborator

Closed in favor of #2642

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

Successfully merging this pull request may close these issues.

4 participants