06
The compiler does the work before your app runs
relay-compiler reads every graphql tag in the project, validates it against schema.graphql, and writes an artifact per fragment and operation: a precomputed runtime AST, TypeScript types, and (here) a persisted query id. Pick any artifact this app generated.Kind
refetchable
Artifact size
6.0 KB
Operation text
465 B
What the browser sends
45 B + vars
1 · You write
generated from @refetchableThe compiler wrote this one entirely: it comes from a @refetchable directive on a fragment, with no source literal.
2 · Types you import
PaginationListRefetchQuery.graphql.tsexport type PaginationListRefetchQuery$variables = {
count?: number | null | undefined;
cursor?: string | null | undefined;
};
export type PaginationListRefetchQuery$data = {
readonly " $fragmentSpreads": FragmentRefs<"PaginationList_query">;
};
export type PaginationListRefetchQuery = {
response: PaginationListRefetchQuery$data;
variables: PaginationListRefetchQuery$variables;
};3 · Operation text, persisted at build time
md5 7e2366849d2bc0460340279b52f4cb2dFragments from every component are inlined into one document. It lives in persisted_queries.json on the server; the client only knows the hash.
query PaginationListRefetchQuery(
$count: Int = 3
$cursor: String
) {
...PaginationList_query_1G22uz
}
fragment PaginationList_query_1G22uz on Query {
feed(first: $count, after: $cursor) {
totalCount
edges {
cursor
node {
id
title
likeCount
author {
name
avatarColor
id
}
__typename
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
4 · Runtime artifact
imported in place of the graphql`` tagA preprocessed AST, so there's no GraphQL parsing in the browser. The reader part tells useFragment what to read; the normalization part tells the store how to write.
/**
* @generated SignedSource<<a89f316fd011427fb7a761c5ef6b7b0e>>
* @relayHash 7e2366849d2bc0460340279b52f4cb2d
* @lightSyntaxTransform
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
// @relayRequestID 7e2366849d2bc0460340279b52f4cb2d
import { ConcreteRequest } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type PaginationListRefetchQuery$variables = {
count?: number | null | undefined;
cursor?: string | null | undefined;
};
export type PaginationListRefetchQuery$data = {
readonly " $fragmentSpreads": FragmentRefs<"PaginationList_query">;
};
export type PaginationListRefetchQuery = {
response: PaginationListRefetchQuery$data;
variables: PaginationListRefetchQuery$variables;
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": 3,
"kind": "LocalArgument",
"name": "count"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "cursor"
}
],
v1 = [
{
"kind": "Variable",
"name": "after",
"variableName": "cursor"
},
{
"kind": "Variable",
"name": "first",
"variableName": "count"
}
],
v2 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
};
return {
"fragment": {
"argumentDefinitions": (v0/*:: as any*/),
"kind": "Fragment",
"metadata": null,
"name": "PaginationListRefetchQuery",
"selections": [
{
"args": [
{
"kind": "Variable",
"name": "count",
"variableName": "count"
},
{
"kind": "Variable",
"name": "cursor",
"variableName": "cursor"
}
],
"kind": "FragmentSpread",
"name": "PaginationList_query"
}
],
"type": "Query",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*:: as any*/),
"kind": "Operation",
"name": "PaginationListRefetchQuery",
"selections": [
{
"alias": null,
"args": (v1/*:: as any*/),
"concreteType": "PostConnection",
"kind": "LinkedField",
"name": "feed",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "totalCount",
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "PostEdge",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "cursor",
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "Post",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
(v2/*:: as any*/),
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "title",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "likeCount",
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "User",
"kind": "LinkedField",
"name": "author",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "avatarColor",
"storageKey": null
},
(v2/*:: as any*/)
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__typename",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "PageInfo",
"kind": "LinkedField",
"name": "pageInfo",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "endCursor",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "hasNextPage",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": (v1/*:: as any*/),
"filters": null,
"handle": "connection",
"key": "PaginationList_feed",
"kind": "LinkedHandle",
"name": "feed"
}
]
},
"params": {
"id": "7e2366849d2bc0460340279b52f4cb2d",
"metadata": {},
"name": "PaginationListRefetchQuery",
"operationKind": "query",
"text": null
}
};
})();
(node as any).hash = "378ed8fa004ed0b884b1551a96cea8c1";
export default node;
- why it mattersA typo in a field name fails the build, not the user's session. Every fragment is checked against the schema on every save.
- why it mattersTypes come from the fragment rather than the whole schema, so a component's
datatype has exactly the fields it asked for. - why it mattersPersisted queries ship for free: smaller requests, cacheable GETs, and a server that can refuse any query it didn't compile.