-
Notifications
You must be signed in to change notification settings - Fork 29
Relay
Vyacheslav Matyukhin edited this page Sep 14, 2023
·
4 revisions
For Squiggle Hub frontend, we use Relay.
Relay has a compiler. pnpm relay will generate all necessary files (in src/__generated__).
If you use VS Code, you can install Relay GraphQL extension to run the compiler in the background.
Note: sometimes (rarely) the compiler crashes or starts to consume 100% CPU. Restarting VS Code will help.
There's a common pattern that we use, based on issue-tracker-next-v13 official example:
-
page.tsxis an RSC (shouldn't have"use client"pragma) -
page.tsxloads the initial query withloadPageQuery -
page.tsxrenders the<SomeNamePage>component withquery={query}prop -
<SomeNamePage>component, defined in./SomeNamePage.tsx, loads the query result throughusePageQueryhook -
SomeNamePage.tsxis a client component (should have"use client"pragma)
Other components that are included by SomeNamePage.tsx and are rendered on the first load shouldn't do their own GraphQL queries, but should export GraphQL fragments instead, as recommended by the Relay documentation.
PR for this pattern: #2131.
Example: page.tsx, FrontPage.tsx.