跳转到主要内容

GraphQL Atom Effects

The underlying GraphQL synchronization support is provided via atom effects. While GraphQL selectors are provided as a convenience to make them easier to use, you could also apply these effects directly to atoms. To use these, you'll need to either reference or register your Relay environment.

There are three atom effects that correspond with the three types of GraphQL operations:

graphQLQueryEffect()

This effect initializes an atom with the results of a GraphQL query. Data may potentially load incrementally with @defer or live queries. This effect will also automatically update the atom if you issue a local Relay commitMutation() call for the same part of the graph.

graphQLSubscriptionEffect()

If you also want to subscribe to mutations initiated remotely from the server, in addition to local changes, then you can implement a GraphQL subscription on the server and use this instead of a query.

graphQLMutatonEffect()

This effect allows an atom to act as a write-through cache. Any local mutations to the atom will be committed as a GraphQL mutation operation.