From c65d6efe55d341757431e44de30050e0dc280ea7 Mon Sep 17 00:00:00 2001 From: Daniel Lo Nigro Date: Thu, 9 Nov 2023 19:11:29 -0800 Subject: [PATCH] Document `directives` argument for `@refetchable` --- .../api-reference/graphql/graphql-directives.md | 16 +++++++++++++++- .../api-reference/graphql/graphql-directives.md | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/website/docs/api-reference/graphql/graphql-directives.md b/website/docs/api-reference/graphql/graphql-directives.md index 4d5dd12edb272..47dde7dd53a60 100644 --- a/website/docs/api-reference/graphql/graphql-directives.md +++ b/website/docs/api-reference/graphql/graphql-directives.md @@ -110,10 +110,24 @@ 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!)` +## `@refetchable(queryName: String!, directives: [String])` 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: `.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): + +```javascript +graphql` + fragment FriendsListComponent_user on User + @refetchable( + queryName: "FriendsListFetchQuery" + directives: ["@relay_test_operation"] + ) { + ... + } +` +``` + ## `@relay(plural: Boolean)` 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: diff --git a/website/versioned_docs/version-v16.0.0/api-reference/graphql/graphql-directives.md b/website/versioned_docs/version-v16.0.0/api-reference/graphql/graphql-directives.md index 4d5dd12edb272..47dde7dd53a60 100644 --- a/website/versioned_docs/version-v16.0.0/api-reference/graphql/graphql-directives.md +++ b/website/versioned_docs/version-v16.0.0/api-reference/graphql/graphql-directives.md @@ -110,10 +110,24 @@ 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!)` +## `@refetchable(queryName: String!, directives: [String])` 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: `.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): + +```javascript +graphql` + fragment FriendsListComponent_user on User + @refetchable( + queryName: "FriendsListFetchQuery" + directives: ["@relay_test_operation"] + ) { + ... + } +` +``` + ## `@relay(plural: Boolean)` 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: