https://facebook.github.io/relay/graphql/objectidentification.htm is very clear around what Node
is and how it behaves, but it doesn't specify which objects must implement it, or what the consequences are if your object doesn't implement it. Is there a set of features that don't work? Are such objects completely ignored? Not all objects in the existing spec (e.g. pageInfo
) implement it, so it's clearly not universally required, but pageInfo
is somewhat of a special case.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Another way of thinking about the Node
interface is that objects that implement it are refetchable. Refetchability effectively means that an object has an ID that I can use to identify the object and retrieve it; by convention, these IDs will usually be opaque, but will contain type information and an identifier within that type (eg. a Base-64 encoding of a string like "Account:1234").
Relay will leverage refetchability in two ways:
- Under a process known as "diffing", if you already have some data for an object identified by ID
QWNjb3VudDoxMjM0
(say, thename
andaddress
fields), and you then navigate to a view where we show some additional fields (location
,createdAt
) then Relay can make a minimal query that "refetches" the node but only requests the missing fields. - Relatedly, Relay will diff connections and will make use of the
Node
interface to fill in missing data on those (example: through some combination of navigation you might have full information for some items in a view, but need to fill inlocation
for some items within the range, or you might modify an item in a connection via a mutation). So, in basic pagination, Relay will often end up making afirst
+after
query to extend a connection, but if you inspect its network traffic in a real app you will also see that it makesnode
queries for items within connections.
So yes, you're right that pageInfo
doesn't implement Node
, and it wouldn't really make sense for it to do so.