Skip to content

Rewrite #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f9d0232
?
shmax Aug 20, 2024
544a491
Merge branch 'master' of github.com:shmax/graphql-php-validation-toolkit
shmax Aug 20, 2024
5094d43
Merge branch 'master' of github.com:shmax/graphql-php-validation-toolkit
shmax Aug 28, 2024
2f10a6c
Merge branch 'master' of github.com:shmax/graphql-php-validation-toolkit
shmax Sep 22, 2024
47a07b7
wip
shmax Sep 22, 2024
942f49e
files
shmax Sep 22, 2024
c778e5f
fix result name
shmax Sep 22, 2024
aaf91aa
fixes for basic tests
shmax Sep 22, 2024
0c3a5cf
fixes
shmax Sep 23, 2024
9689d67
cleanup
shmax Sep 23, 2024
50eaa8d
fixes around fields field
shmax Sep 23, 2024
21911aa
use custom namespace
shmax Sep 28, 2024
69aebe5
set up namespaces, simplify listof
shmax Sep 29, 2024
44ca6d3
add listoflistof test
shmax Sep 29, 2024
410b1f5
more simplification
shmax Sep 29, 2024
3719fb1
more simplification
shmax Sep 29, 2024
2f5f750
Start on validation
shmax Sep 30, 2024
7762690
resolvers for error code and message
shmax Sep 30, 2024
36c6a8f
rename stuff
shmax Sep 30, 2024
e5ca67f
start no nonnull
shmax Sep 30, 2024
0101068
fix tests
shmax Oct 13, 2024
bc6ba86
wip
shmax Oct 13, 2024
4574cd8
use more meta props
shmax Oct 14, 2024
bca0ddb
forward validation to errorType
shmax Oct 14, 2024
ffcca2f
fixes around enum type
shmax Oct 14, 2024
747783d
fix missing resolver
shmax Oct 14, 2024
a8e6087
start on listOf
shmax Oct 14, 2024
c57314d
rename path to __path
shmax Oct 14, 2024
ec73251
nre
shmax Oct 14, 2024
948bfa3
better list error aggregation
shmax Oct 14, 2024
3a1d487
comment
shmax Oct 14, 2024
d604e1f
more fixes
shmax Oct 14, 2024
a019f58
fix items exception
shmax Oct 14, 2024
d8780b8
stanning
shmax Oct 15, 2024
8800b67
update exception message
shmax Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@
},
"autoload": {
"psr-4": {
"GraphQL\\": "src/"
"GraphQlPhpValidationToolkit\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"GraphQL\\Tests\\": "tests/",
"GraphQL\\Benchmarks\\": "benchmarks/",
"GraphQL\\Examples\\Blog\\": "examples/01-blog/Blog/"
"GraphQlPhpValidationToolkit\\Tests\\": "tests/"
}
},
"scripts": {
Expand Down
24 changes: 14 additions & 10 deletions examples/01-basic-scalar-validation/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
# Simple scalar validation
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.

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.

### Run locally

```
php -S localhost:8000 ./index.php
```

### Install ChromeiQL plug-in for Chrome

1. Install from [here](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=en)
2. Enter "http://localhost:8000" in the text field at the top and press the "Set Endpoint" button
3. Be sure to inspect the "Docs" flyout to get familiar with the dynamically-generated types

### Try mutation with valid input

```
mutation {
deleteAuthor(id: 1) {
valid
result
__valid
__result
}
}
```

### Try mutation with invalid input

```
mutation {
deleteAuthor(id: 3) {
valid
result
suberrors {
id {
code
msg
}
__valid
__result
id {
__code
__msg
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/01-basic-scalar-validation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use GraphQL\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ValidatedFieldDefinition;
use GraphQL\Type\Schema;
use GraphQlPhpValidationToolkit\Type\UserErrorType\ValidatedFieldDefinition;

$authors = [
1 => [
Expand Down
32 changes: 17 additions & 15 deletions examples/02-custom-error-codes/README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
# Simple scalar validation
If you supply an `errorCodes` property on your `fields` or `args` definitions, then a custom, unique error code type will be created.

If you supply an `errorCodes` property on your `fields` or `args` definitions, then a custom, unique error code type
will be created.

### Run locally

```
php -S localhost:8000 ./index.php
```

### Install ChromeiQL plug-in for Chrome

1. Install from [here](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=en)
2. Enter "http://localhost:8000" in the text field at the top and press the "Set Endpoint" button
3. Be sure to inspect the "Docs" flyout to get familiar with the dynamically-generated types

### Try mutation with valid input

```
mutation {
deleteAuthor(id: 1) {
valid
result
suberrors {
id {
code
msg
}
__valid
__result
id {
__code
__msg
}
}
}
```

### Try mutation with invalid input

```
mutation {
deleteAuthor(id: 3) {
valid
result
suberrors {
id {
code
msg
}
__valid
__result
id {
__code
__msg
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/02-custom-error-codes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use GraphQL\Type\Definition\Description;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ValidatedFieldDefinition;
use GraphQL\Type\Schema;
use GraphQlPhpValidationToolkit\Type\UserErrorType\ValidatedFieldDefinition;

enum AuthorValidation {
enum AuthorValidation
{
#[Description(description: 'Author not found.')]

case UnknownAuthor;
case AuthorAlreadyDeleted;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ public function __construct()
'deleteAuthor' => new ValidatedFieldDefinition([
'name' => 'deleteAuthor',
'typeSetter' => function (Type $type) use ($types) {
if(!isset($types[$type->name])) {
if (!isset($types[$type->name])) {
$types[$type->name] = $type;
}
return $types[$type->name];
Expand Down
63 changes: 30 additions & 33 deletions examples/03-input-object-validation/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# Validation of InputObjects (or Objects)

You can add `validate` properties to the fields of nested Objects or InputObjects (and those fields can themselves be of complex types with their own fields, and so on). This library will sniff them out and recursively build up a result type with a similarly nested structure.
# Validation of InputObjects (or Objects)

You can add `validate` properties to the fields of nested Objects or InputObjects (and those fields can themselves be of
complex types with their own fields, and so on). This library will sniff them out and recursively build up a result type
with a similarly nested structure.

### Run locally

```
php -S localhost:8000 ./index.php
```

### Install ChromeiQL plug-in for Chrome

1. Install from [here](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=en)
2. Enter "http://localhost:8000" in the text field at the top and press the "Set Endpoint" button
3. Be sure to inspect the "Docs" flyout to get familiar with the dynamically-generated types

### Try mutation with valid input

```
mutation {
updateAuthor(
Expand All @@ -23,31 +27,28 @@ mutation {
age: 47
}
) {
result {
__result {
id
name
}
suberrors {
attributes {
code
msg
suberrors {
age {
code
msg
}
name {
code
msg
}
attributes {
__code
__msg
age {
__code
__msg
}
name {
__code
__msg
}
}
}
}
}
```

### Try mutation with invalid input

```
mutation {
updateAuthor(
Expand All @@ -57,24 +58,20 @@ mutation {
age: -3
}
) {
result {
__result {
id
name
}
suberrors {
attributes {
code
msg
suberrors {
age {
code
msg
}
name {
code
msg
}
}
attributes {
__code
__msg
age {
__code
__msg
}
name {
__code
__msg
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions examples/03-input-object-validation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ValidatedFieldDefinition;
use GraphQL\Type\Schema;
use GraphQlPhpValidationToolkit\Type\UserErrorType\ValidatedFieldDefinition;

enum NameErrors {
enum NameErrors
{
case NameTooLong;
case NameNotUnique;
}

enum AgeErrors {
enum AgeErrors
{
case Negative;
}

enum AuthorErrors {
enum AuthorErrors
{
case UnknownAuthor;
case DeceasedAuthor;
}
Expand Down Expand Up @@ -115,7 +118,7 @@ public function __construct()
'type' => Type::id(),
'errorCodes' => AuthorErrors::class,
'validate' => function (string $authorId) use ($authors) {
if (! isset($authors[$authorId])) {
if (!isset($authors[$authorId])) {
return [AuthorValidation::UnknownAuthor, 'We have no record of that author'];
}

Expand Down
54 changes: 26 additions & 28 deletions examples/04-list-of-scalar-validation/README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
# Validation of InputObjects (or Objects)

You can add validate lists of things. You can specify a `validate` callback on the `ListOf` field itself, and also specify a `validateItem` callback to be applied to each item in the list. Any errors returned on the list items will each have an `index` property so you will know exactly which items were invalid.
# Validation of InputObjects (or Objects)

You can validate lists of things. You can specify a `validate` callback on the `ListOf` field itself, ... TODO fill this
in. Any errors returned on the list items will each have an `index` property so you will know exactly which items were
invalid.

### Run locally

```
php -S localhost:8000 ./index.php
```

### Install ChromeiQL plug-in for Chrome

1. Install from [here](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=en)
2. Enter "http://localhost:8000" in the text field at the top and press the "Set Endpoint" button
3. Be sure to inspect the "Docs" flyout to get familiar with the dynamically-generated types


### Try mutation with valid input

```
mutation {
savePhoneNumbers(
phoneNumbers: [
"123-3456",
"867-5309"
]
) {
valid
suberrors {
phoneNumbers {
code
msg
path
savePhoneNumbers(phoneNumbers: ["123-3456", "867-5309"]) {
__valid
__code
__msg
phoneNumbers {
items {
__code
__msg
__path
}
}
}
}
```

### Try mutation with invalid input

```
mutation {
savePhoneNumbers(
phoneNumbers: [
"123-3456",
"xxx-3456"
]
) {
valid
suberrors {
phoneNumbers {
code
msg
path
savePhoneNumbers(phoneNumbers: ["123-3456", "xxx-5309"]) {
__valid
__code
__msg
phoneNumbers {
items {
__code
__msg
__path
}
}
}
Expand Down
Loading
Loading