| 146 | } |
| 147 | |
| 148 | func Example_insertInlineBulk() { |
| 149 | gql := `mutation { |
| 150 | users(insert: [ |
| 151 | {id: $id1, email: $email1, full_name: $full_name1}, |
| 152 | {id: $id2, email: $email2, full_name: $full_name2}], order_by: {id: desc}) { |
| 153 | id |
| 154 | email |
| 155 | } |
| 156 | }` |
| 157 | |
| 158 | vars := json.RawMessage(`{ |
| 159 | "id1": 1008, |
| 160 | "email1": "one@test.com", |
| 161 | "full_name1": "John One", |
| 162 | "id2": 1009, |
| 163 | "email2": "two@test.com", |
| 164 | "full_name2": "John Two" |
| 165 | }`) |
| 166 | |
| 167 | conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true}) |
| 168 | gj, err := core.NewGraphJin(conf, db) |
| 169 | if err != nil { |
| 170 | panic(err) |
| 171 | } |
| 172 | defer gj.Close() |
| 173 | |
| 174 | ctx := context.WithValue(context.Background(), core.UserIDKey, 3) |
| 175 | res, err := gj.GraphQL(ctx, gql, vars, nil) |
| 176 | if err != nil { |
| 177 | fmt.Println(err) |
| 178 | } else { |
| 179 | printJSON(res.Data) |
| 180 | } |
| 181 | // Output: {"users":[{"email":"two@test.com","id":1009},{"email":"one@test.com","id":1008}]} |
| 182 | } |
| 183 | |
| 184 | func Example_insertWithPresets() { |
| 185 | gql := `mutation { |