You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+3-40Lines changed: 3 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,7 +135,8 @@ If you want to return an error message, return an array with the message in the
135
135
]
136
136
])
137
137
```
138
-
Note that `ListOf` types are a special case, and support an additional `validateItem` callback for checking each item in their array. Its generated error type will have an array of suberror types, each with their own `path` field that you can query so you can know the exact address in the multidimensional array of each item that failed validation:
138
+
139
+
Generated `ListOf` error types also have a `path` field that you can query so you can know the exact address in the multidimensional array of each item that failed validation:
139
140
140
141
```php
141
142
//...
@@ -144,13 +145,7 @@ Note that `ListOf` types are a special case, and support an additional `validate
144
145
'args' => [
145
146
'phoneNumbers' => [
146
147
'type' => Type::listOf(Type::string()),
147
-
'validate' => function(array $phoneNumbers) {
148
-
if(!count($phoneNumbers)) {
149
-
return [1, "At least one phone number is required"];
return ['invalidPhoneNumber', 'That does not seem to be a valid phone number'];
210
-
}
211
-
return 0;
212
-
}
213
-
]
214
-
]
215
-
])
216
-
```
217
-
218
181
### Managing Created Types
219
182
This library will create new types as needed. If you are using some kind of type manager to store and retrieve types, you can integrate it by providing a `typeSetter` callback:
The simplest possible type of user input validation. Mutation expects an `authorId` arg, and will respond with a nicely formatted error code and message if an author by that id doesn't exist.
3
-
4
-
### Run locally
5
-
```
6
-
php -S localhost:8000 ./index.php
7
-
```
8
-
9
-
### Install ChromeiQL plug-in for Chrome
10
-
1. Install from [here](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=en)
11
-
2. Enter "http://localhost:8000" in the text field at the top and press the "Set Endpoint" button
12
-
3. Be sure to inspect the "Docs" flyout to get familiar with the dynamically-generated types
13
-
14
-
### Try mutation with valid input
15
-
```
16
-
mutation {
17
-
updateAuthor(authorId:1) {
18
-
suberrors {
19
-
authorId {
20
-
code
21
-
msg
22
-
}
23
-
}
24
-
result {
25
-
id
26
-
name
27
-
}
28
-
valid
29
-
}
30
-
}
31
-
```
32
-
33
-
### Try mutation with invalid input
34
-
```
35
-
mutation {
36
-
updateAuthor(authorId:999) {
37
-
suberrors {
38
-
authorId {
39
-
code
40
-
msg
41
-
}
42
-
}
43
-
result {
44
-
id
45
-
name
46
-
}
47
-
valid
48
-
}
49
-
}
1
+
# Simple scalar validation
2
+
The simplest possible type of user input validation. Mutation expects an `authorId` arg, and will respond with a nicely formatted error code and message if an author by that id doesn't exist.
3
+
4
+
### Run locally
5
+
```
6
+
php -S localhost:8000 ./index.php
7
+
```
8
+
9
+
### Install ChromeiQL plug-in for Chrome
10
+
1. Install from [here](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=en)
11
+
2. Enter "http://localhost:8000" in the text field at the top and press the "Set Endpoint" button
12
+
3. Be sure to inspect the "Docs" flyout to get familiar with the dynamically-generated types
0 commit comments