Skip to content

Commit 8392b68

Browse files
Daniel15facebook-github-bot
authored andcommitted
Document directives argument for @refetchable (#4520)
Summary: Title says it all 😃 Pull Request resolved: #4520 Reviewed By: monicatang Differential Revision: D52876765 Pulled By: captbaritone fbshipit-source-id: 8401d80ff2b18fe74ba5c157e6530430aa42f58e
1 parent 95b4694 commit 8392b68

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

website/docs/api-reference/graphql/graphql-directives.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,24 @@ Notes:
110110

111111
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).
112112

113-
## `@refetchable(queryName: String!)`
113+
## `@refetchable(queryName: String!, directives: [String])`
114114

115115
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/).
116116

117+
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):
118+
119+
```javascript
120+
graphql`
121+
fragment FriendsListComponent_user on User
122+
@refetchable(
123+
queryName: "FriendsListFetchQuery"
124+
directives: ["@relay_test_operation"]
125+
) {
126+
...
127+
}
128+
`
129+
```
130+
117131
## `@relay(plural: Boolean)`
118132

119133
When defining a fragment for use with a Fragment container, you can use the `@relay(plural: true)` directive to indicate that container expects the prop for that fragment to be a list of items instead of a single item. A query or parent that spreads a `@relay(plural: true)` fragment should do so within a plural field (ie a field backed by a [GraphQL list](http://graphql.org/learn/schema/#lists-and-non-null). For example:

website/versioned_docs/version-v16.0.0/api-reference/graphql/graphql-directives.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,24 @@ Notes:
110110

111111
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).
112112

113-
## `@refetchable(queryName: String!)`
113+
## `@refetchable(queryName: String!, directives: [String])`
114114

115115
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/).
116116

117+
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):
118+
119+
```javascript
120+
graphql`
121+
fragment FriendsListComponent_user on User
122+
@refetchable(
123+
queryName: "FriendsListFetchQuery"
124+
directives: ["@relay_test_operation"]
125+
) {
126+
...
127+
}
128+
`
129+
```
130+
117131
## `@relay(plural: Boolean)`
118132

119133
When defining a fragment for use with a Fragment container, you can use the `@relay(plural: true)` directive to indicate that container expects the prop for that fragment to be a list of items instead of a single item. A query or parent that spreads a `@relay(plural: true)` fragment should do so within a plural field (ie a field backed by a [GraphQL list](http://graphql.org/learn/schema/#lists-and-non-null). For example:

0 commit comments

Comments
 (0)