@@ -87,11 +87,36 @@ type Customer @model {
87
87
id : ID !
88
88
name : String !
89
89
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
+ }
91
107
}
92
108
```
93
109
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
+ ```
95
120
96
121
```graphql
97
122
query QueryCustomersForAccountRepresentative ($representativeId : ID ! ) {
@@ -114,15 +139,14 @@ type Customer @model @auth(rules: [{ allow: public }]) {
114
139
id : ID !
115
140
name : String ! @index (name : " byNameAndPhoneNumber" , sortKeyFields : ["phoneNumber" ], queryField : " customerByNameAndPhone" )
116
141
phoneNumber : String
117
- accountRepresentativeID : ID ! @index (name : " byRepresentative" , queryField : " customerByRepresentative" )
118
- }
142
+ accountRepresentativeID : ID ! @index
119
143
```
120
144
121
145
The example client query below allows you to query for "Customer" based on their `name ` and filter based on `phoneNumber `:
122
146
123
147
```graphql
124
148
query MyQuery {
125
- customerByNameAndPhone (phoneNumber : {beginsWith : " +1" }, name : " Rene" ) {
149
+ customerByNameAndPhone (phoneNumber : { beginsWith : "+1" }, name : "Rene" ) {
126
150
items {
127
151
id
128
152
name
@@ -594,6 +618,19 @@ type Address @model {
594
618
}
595
619
```
596
620
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
+
597
634
## How it works
598
635
The `@model ` directive will generate :
599
636
- An Amazon DynamoDB table with PAY_PER_REQUEST billing mode enabled by default .
0 commit comments