Skip to content

Commit a152aa4

Browse files
committed
add documatation for new query_response_input_key_map enhancement
1 parent 428e647 commit a152aa4

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

docs/resources/mutation.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "graphql_mutation" "basic_mutation" {
2828
```
2929

3030
## Argument Reference
31-
* `mutation_variables` - (Required) A map of any variables that will be used in your create & update mutation. Each variable's value is interpreted as JSON when possible.
31+
* `mutation_variables` - (Required) A map of any variables that will be used in your create & update mutation. Each variable's value is interpreted as JSON when possible. In order for the provider to keep track of state with respect to inputs provided in `mutation_variables`, you should ensure that your `read_query` includes the property that holds the value for your mutation variable. The keys do not need to be the same, as the provider with automatically map the keys based on value. See `query_response_input_key_map` description for details on how this works.
3232
>NOTE: If a mutation variable is a number that must be interpreted as a string, it should be wrapped in quotations. For example `"marVar" = "\"123\""`.
3333
3434
* `read_query_variables` - (Optional) A map of any variables that will be used in the read query for the resource's lifecycle. Each variable's value is interpreted as JSON when possible.
@@ -55,6 +55,24 @@ resource "graphql_mutation" "basic_mutation" {
5555
* `query_response` - A computed json encoded http response object received from the query.
5656
- To use properties from this response, leverage Terraform's built in [jsondecode](https://www.terraform.io/docs/configuration/functions/jsondecode.html) function.
5757

58+
* `query_response_input_key_map` - A computed map between the values represented by mutation_variable inputs and query response object keys. The purpose of this comnputed map is for the provider to keep track of drift between a resource's server-state and its state representation in terraform. Its value is calculated by creating a map of key-value pairs such that the key is the key for a particular input of the `mutation_variables`, and the value is the key that represents the corresponding value in the `query_response`. For example, consider we have a query response with the following structure:
59+
```javascript
60+
"data": {
61+
"id": "123456"
62+
"user": {
63+
"id": "654321"
64+
}
65+
}
66+
```
67+
68+
Consider there is a mutation variable input of `userID = "654321"`. The computed `query_response_input_key_map` would be:
69+
```javascript
70+
{
71+
"userID": "data.user.id"
72+
}
73+
```
74+
Internally, the provider uses this map to check the state of given input properties against their value returned from server state via `query_response` during a read lifecycle.
75+
5876
* `computed_update_operation_variables` - A computed map that combines any computed variables with the `mutation_variables` input based on what is provided in the `compute_mutation_keys` input. This is also useful for outputing properties of the response object and using it on other resources.
5977

6078
* `computed_delete_operation_variables` - A computed map that combines any computed variables with the `delete_mutation_variables` input based on what is provided in the `compute_mutation_keys` input.

docsite/docs/resource_graphql_mutation.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ resource "graphql_mutation" "basic_mutation" {
3838
### mutation_variables
3939
- **Required**: true
4040
- **Type**: map(string)
41-
- **Description**: A map of any variables that will be used in your create & update mutation. Each variable's value is interpreted as JSON when possible.
41+
- **Description**: A map of any variables that will be used in your create & update mutation. Each variable's value is interpreted as JSON when possible. In order for the provider to keep track of state with respect to inputs provided in `mutation_variables`, you should ensure that your `read_query` includes the property that holds the value for your mutation variable. The keys do not need to be the same, as the provider with automatically map the keys based on value. See `query_response_input_key_map` description for details on how this works.
4242
>NOTE: If a mutation variable is a number that must be interpreted as a string, it should be wrapped in quotations. For example `"marVar" = "\"123\""`. Any variables that are not actually used in mutations will be ignored.
4343
4444
### read_query_variables
@@ -96,6 +96,26 @@ resource "graphql_mutation" "basic_mutation" {
9696
- **Type**: string (json encoded http response)
9797
- **Desciption**: A computed json encoded http response object received from the query.
9898
- To use properties from this response, leverage Terraform's built in [jsondecode](https://www.terraform.io/docs/configuration/functions/jsondecode.html) function.
99+
-
100+
### query_response_input_key_map
101+
- **Type**: map(string)
102+
- **Desciption**: A computed map between the values represented by mutation_variable inputs and query response object keys. The purpose of this comnputed map is for the provider to keep track of drift between a resource's server-state and its state representation in terraform. Its value is calculated by creating a map of key-value pairs such that the key is the key for a particular input of the `mutation_variables`, and the value is the key that represents the corresponding value in the `query_response`. For example, consider we have a query response with the following structure:
103+
```javascript
104+
"data": {
105+
"id": "123456"
106+
"user": {
107+
"id": "654321"
108+
}
109+
}
110+
```
111+
112+
Consider there is a mutation variable input of `userID = "654321"`. The computed `query_response_input_key_map` would be:
113+
```javascript
114+
{
115+
"userID": "data.user.id"
116+
}
117+
```
118+
Internally, the provider uses this map to check the state of given input properties against their value returned from server state via `query_response` during a read lifecycle.
99119

100120
### computed_update_operation_variables
101121
- **Type**: map(string)

0 commit comments

Comments
 (0)