Skip to content

Commit 55b530f

Browse files
authored
feat: document enabled feature flag, and usage in secondary index section of data modeling page (aws-amplify#4801)
1 parent 6b01cdf commit 55b530f

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

src/components/FeatureFlags/feature-flags.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,18 @@
256256
"description": "Changes the behaviour of @index directive to auto-generate Queries for indexes if no 'queryField' is provided.",
257257
"type": "Feature",
258258
"valueType": "Boolean",
259-
"versionAdded": "8.5.x",
259+
"versionAdded": "8.5.0",
260260
"values": [
261261
{
262262
"value": "true",
263263
"description": "An empty 'queryField' will cause a Query to be auto-generated. Explicit null value will disable this functionality",
264-
"defaultNewProject": false,
264+
"defaultNewProject": true,
265265
"defaultExistingProject": false
266266
},
267267
{
268268
"value": "false",
269269
"description": "A Query will only be created if the 'queryField' is explicitly set",
270-
"defaultNewProject": true,
270+
"defaultNewProject": false,
271271
"defaultExistingProject": true
272272
}
273273
]

src/pages/cli/graphql/data-modeling.mdx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,36 @@ type Customer @model {
8787
id: ID!
8888
name: String!
8989
phoneNumber: String
90-
accountRepresentativeID: ID! @index(name: "byRepresentative", queryField: "customerByRepresentative")
90+
accountRepresentativeID: ID! @index
91+
}
92+
```
93+
94+
The example client query below allows you to query for "Customer" records based on their `accountRepresentativeID`:
95+
96+
```graphql
97+
query QueryCustomersForAccountRepresentative($accountRepresentativeID: ID!) {
98+
customersByAccountRepresentativeID(accountRepresentativeID: $accountRepresentativeID) {
99+
customers {
100+
items {
101+
id
102+
name
103+
phoneNumber
104+
}
105+
}
106+
}
91107
}
92108
```
93109

94-
The example client query below allows you to query for "Customer" based on their `accountRepresentativeID`:
110+
You can also overwrite the `queryField` or `name` to customize the GraphQL query name, or secondary index name respectively:
111+
112+
```graphql
113+
type Customer @model {
114+
id: ID!
115+
name: String!
116+
phoneNumber: String
117+
accountRepresentativeID: ID! @index(name: "byRepresentative", queryField: "customerByRepresentative")
118+
}
119+
```
95120

96121
```graphql
97122
query QueryCustomersForAccountRepresentative($representativeId: ID!) {
@@ -114,15 +139,14 @@ type Customer @model @auth(rules: [{ allow: public }]) {
114139
id: ID!
115140
name: String! @index(name: "byNameAndPhoneNumber", sortKeyFields: ["phoneNumber"], queryField: "customerByNameAndPhone")
116141
phoneNumber: String
117-
accountRepresentativeID: ID! @index(name: "byRepresentative", queryField: "customerByRepresentative")
118-
}
142+
accountRepresentativeID: ID! @index
119143
```
120144

121145
The example client query below allows you to query for "Customer" based on their `name` and filter based on `phoneNumber`:
122146

123147
```graphql
124148
query MyQuery {
125-
customerByNameAndPhone(phoneNumber: {beginsWith: "+1"}, name: "Rene") {
149+
customerByNameAndPhone(phoneNumber: { beginsWith: "+1" }, name: "Rene") {
126150
items {
127151
id
128152
name
@@ -594,6 +618,19 @@ type Address @model {
594618
}
595619
```
596620

621+
### Generate a secondary index without a GraphQL query
622+
623+
Because query creation against a secondary index is automatic, if you wish to define a secondary index that does not have a corresponding query in your API, set the `queryField` parameter to `null`.
624+
625+
```graphql
626+
type Customer @model {
627+
id: ID!
628+
name: String!
629+
phoneNumber: String
630+
accountRepresentativeID: ID! @index(queryField: null)
631+
}
632+
```
633+
597634
## How it works
598635
The `@model` directive will generate:
599636
- An Amazon DynamoDB table with PAY_PER_REQUEST billing mode enabled by default.

0 commit comments

Comments
 (0)