Open reckter opened 1 year ago
enable in your graphql server, and it should work
I recently struggled with the same question!
@defer is a directive that must be declared in schema to be used. To be more precise, the server must handle this directive to defer some parts of the reponse. Relay addresses the subject in its latest video published here: https://relay.dev/docs/principles-and-architecture/videos/
At this moment, few graphql servers are able to manage this directive nativally. If you can enable it in your server, the directive will be declared automatically in the schema.
Resources:
A thanks @sibelius @michael-haberzettel ! Enabling in in our server (yoga), was pretty easy.
But I couldn't get it to actually work in the frontend with relay. No combination of meros, fetch-multipart-grahpql, relay-modern-middleware, seems to work for me :/
The furthest I got was that non-defer queries work normaly, but it seemed like defered queries (1) didn't correctly forward the first part of the response and (2) relay didn't understand the "incremental" property? (but even translating between the two didn't get me further, "no data in response" errors, almost everywhere).
Do you happen to have any more pointers? Or maybe even a working example you can point me to?
The video sadly is missing all the technical details to actually get it to work :/
I'm stuck with my graphql server that can't handle these directives... so I can't help you :cry:
@reckter did you ever get anywhere with this? Is it possible to use defer with Relay at the moment?
@jakobkhansen I gave up, when I discovered that one of our core backend technologies wouldn't work with delayed queries (neo4j-graphql). iirc I managed to get it to work in relay somehow, at least I remember seeing 2 responses comming back. I can't remember if that rendered correctly or not though. sorry.
Thought I'd share a demo of Relay using @defer
with an Apollo Router back-end: https://apollographql.github.io/graphql-testing-library/?path=/docs/example-relay--docs
My fetchQuery
implementation: https://github.com/apollographql/graphql-testing-library/blob/main/.storybook/stories/components/relay/relay-environment.ts
In the Documentation here https://relay.dev/docs/tutorial/queries-2/ , if you expand the "Deep dive: When to use a secondary query" (nice addition btw!), it mentions "deferred Fragments" and that they will be explained "later".
But I couldn't find any explanation on the topic anywhere else :/ There is a Glossary entry for
@defer
, but it does not explain anything really.The relay compiler also doesn't recognise
@defer
out of the box.What is the state of the deferred fragments feature?