| 103 | } |
| 104 | |
| 105 | func Example_insertInlineWithValidation() { |
| 106 | gql := `mutation |
| 107 | @constraint(variable: "email", format: "email", min: 1, max: 100) |
| 108 | @constraint(variable: "full_name", requiredIf: { id: 1007 } ) |
| 109 | @constraint(variable: "id", greaterThan:1006 ) |
| 110 | @constraint(variable: "id", lessThanOrEqualsField:id ) { |
| 111 | users(insert: { id: $id, email: $email, full_name: $full_name }) { |
| 112 | id |
| 113 | email |
| 114 | full_name |
| 115 | } |
| 116 | }` |
| 117 | |
| 118 | vars := json.RawMessage(`{ |
| 119 | "id": 1007, |
| 120 | "email": "not_an_email" |
| 121 | }`) |
| 122 | |
| 123 | conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true}) |
| 124 | gj, err := core.NewGraphJin(conf, db) |
| 125 | if err != nil { |
| 126 | panic(err) |
| 127 | } |
| 128 | defer gj.Close() |
| 129 | |
| 130 | ctx := context.WithValue(context.Background(), core.UserIDKey, 3) |
| 131 | res, err := gj.GraphQL(ctx, gql, vars, nil) |
| 132 | if err != nil { |
| 133 | fmt.Println(err) |
| 134 | for _, e := range res.Validation { |
| 135 | fmt.Println(e.Constraint, e.FieldName) |
| 136 | } |
| 137 | } else { |
| 138 | printJSON(res.Data) |
| 139 | } |
| 140 | // Ordered output: |
| 141 | // validation failed |
| 142 | // format email |
| 143 | // min email |
| 144 | // max email |
| 145 | // requiredIf full_name |
| 146 | } |
| 147 | |
| 148 | func Example_insertInlineBulk() { |
| 149 | gql := `mutation { |