Skip to content

Commit

Permalink
Add docs for preferFetchable argument
Browse files Browse the repository at this point in the history
Reviewed By: antoinebrault

Differential Revision: D58152287

fbshipit-source-id: 142e6685698ca6632744c3151d99851ad11338b1
  • Loading branch information
alunyov authored and facebook-github-bot committed Jun 4, 2024
1 parent 29d9e55 commit 4c5cd41
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion website/docs/api-reference/graphql/graphql-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ Notes:

With `usePaginationFragment`, Relay expects connection fields to be annotated with a `@connection` directive. For more detailed information and an example, check out the [docs on `usePaginationFragment`](../../guided-tour/list-data/rendering-connections).

## `@refetchable(queryName: String!, directives: [String])`
## `@refetchable(queryName: String!, directives: [String], preferFetchable: Boolean)`

With `useRefetchableFragment` and `usePaginationFragment`, Relay expects a `@refetchable` directive. The `@refetchable` directive can only be added to fragments that are "refetchable", that is, on fragments that are declared on `Viewer` or `Query` types, or on a type that implements `Node` (i.e. a type that has an id). The `@refetchable` directive will autogenerate a query with the specified `queryName`. This will also generate Flow types for the query, available to import from the generated file: `<queryName>.graphql.js`. For more detailed information and examples, check out the docs on [`useRefetchableFragment`](../use-refetchable-fragment/) or [`usePaginationFragment`](../use-pagination-fragment/).

Optionally, you can pass in a list of directives to add to the autogenerated query. For example, this can be used to add the `@relay_test_operation` directive for [testing](../../guides/testing-relay-components):

[Optional] `preferFetchable: Boolean`

This argument tells the Relay compiler to prefer generating `fetch_MyType(): MyType` queries for types that implement the `Node` interface. This is useful for schemas that have adopted the `@strong` and `@fetchable` server annotations for types. You can directly fetch concrete objects without needing to refine `Node` interface to a specific type.

```javascript
graphql`
fragment FriendsListComponent_user on User
Expand Down

0 comments on commit 4c5cd41

Please sign in to comment.