parseMutationOp parses and stores set or delete operation string in Mutation.
(it *lex.ItemIterator, op string, mu *api.Mutation)
| 170 | |
| 171 | // parseMutationOp parses and stores set or delete operation string in Mutation. |
| 172 | func parseMutationOp(it *lex.ItemIterator, op string, mu *api.Mutation) error { |
| 173 | parse := false |
| 174 | for it.Next() { |
| 175 | item := it.Item() |
| 176 | if item.Typ == itemText { |
| 177 | continue |
| 178 | } |
| 179 | if item.Typ == itemLeftCurl { |
| 180 | if parse { |
| 181 | return it.Errorf("Too many left curls in set mutation.") |
| 182 | } |
| 183 | parse = true |
| 184 | } |
| 185 | if item.Typ == itemMutationOpContent { |
| 186 | if !parse { |
| 187 | return it.Errorf("Mutation syntax invalid.") |
| 188 | } |
| 189 | |
| 190 | switch op { |
| 191 | case "set": |
| 192 | mu.SetNquads = []byte(item.Val) |
| 193 | case "delete": |
| 194 | mu.DelNquads = []byte(item.Val) |
| 195 | case "schema": |
| 196 | return it.Errorf("Altering schema not supported through http client.") |
| 197 | case "dropall": |
| 198 | return it.Errorf("Dropall not supported through http client.") |
| 199 | default: |
| 200 | return it.Errorf("Invalid mutation operation.") |
| 201 | } |
| 202 | } |
| 203 | if item.Typ == itemRightCurl { |
| 204 | return nil |
| 205 | } |
| 206 | } |
| 207 | return it.Errorf("Invalid mutation formatting.") |
| 208 | } |
no test coverage detected