Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 10ee502

Browse files
committed
Implement insert mutation
Part of #142.
1 parent c0687f3 commit 10ee502

File tree

7 files changed

+731
-116
lines changed

7 files changed

+731
-116
lines changed

README.md

+61-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,67 @@ local compiled_query = graphql_lib.compile(query)
124124
local result = compiled_query:execute(variables)
125125
```
126126

127-
# GraphiQL
127+
### Mutations
128+
129+
Example with an object passed from a variable:
130+
131+
```
132+
mutation insert_user_and_order($user: user_collection_insert,
133+
$order: order_collection_insert) {
134+
user_collection(insert: $user) {
135+
user_id
136+
first_name
137+
last_name
138+
}
139+
order_collection(insert: $order) {
140+
order_id
141+
description
142+
in_stock
143+
}
144+
}
145+
```
146+
147+
Example with immediate argument for an object:
148+
149+
```
150+
mutation insert_user_and_order {
151+
user_collection(insert: {
152+
user_id: "user_id_new_1"
153+
first_name: "Peter"
154+
last_name: "Petrov"
155+
}) {
156+
user_id
157+
first_name
158+
last_name
159+
}
160+
order_collection(insert: {
161+
order_id: "order_id_new_1"
162+
user_id: "user_id_new_1"
163+
description: "Peter's order"
164+
price: 0.0
165+
discount: 0.0
166+
# in_stock: true should be set as default value
167+
}) {
168+
order_id
169+
description
170+
in_stock
171+
}
172+
}
173+
```
174+
175+
Consider the following details:
176+
177+
* `${collection_name}_insert` is the name of the type whose value intended to
178+
pass to the `insert` argument. This type / argument requires a user to set
179+
all fields of an inserting object.
180+
* Inserting cannot be used on connection fields, it is allowed only for
181+
top-level fields (named as well as collections).
182+
* It is forbidden to use `insert` argument with any other argument.
183+
* A mutation with insert argument always return the object that was just
184+
inserted.
185+
* Of course `insert` argument is forbidden in `query` requests.
186+
187+
## GraphiQL
128188
```
129189
local graphql = require('graphql').new({
130190
schemas = schemas,

0 commit comments

Comments
 (0)