Skip to content

Add example defer to demo#131

Open
eddeee888 wants to merge 1 commit into
masterfrom
defer-for-bestie
Open

Add example defer to demo#131
eddeee888 wants to merge 1 commit into
masterfrom
defer-for-bestie

Conversation

@eddeee888

@eddeee888 eddeee888 commented Oct 28, 2025

Copy link
Copy Markdown
Owner

This is an example of how Yoga supports @defer:

  • Book:2 is a very slow book
  • So we wrap @defer when resolving books. It is ONLY slow when it's loading 2. Here's the query:
  query BookDetails($bookId: ID!) {
    book(id: $bookId) {
      ... on BookResultOk {
        result {
          id
          isbn
          ... on Book @defer { # since we are loading `Book:3`, the previous book will be slow, making `Previous` link slow to appear
            previousBookInSeries {
              id
            }
          }
          ... on Book @defer {
            nextBookInSeries {
              id
            }
          }
        }
      }
      ... on ResultError {
        error
      }
    }
  }

Demo

Case 1: Slow when loading Book:2

Screen.Recording.2025-10-29.at.12.13.51.am.mov

Case 2: Fast when NOT loading Book:2

Screen.Recording.2025-10-29.at.12.19.59.am.mov

Note: previous and next books come back at different time so the links appear at different time

Case 3: Wrapping both previousBookInSeries and nextBookInSeries in one defer so they appear together

Screen.Recording.2025-10-29.at.12.22.55.am.mov
... on Book @defer {
  previousBookInSeries {
    id
  }
  nextBookInSeries {
    id
  }
}

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.

1 participant