Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 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
41c9930
add IDErrorType
shmax Oct 16, 2024
7a17a54
update docs
shmax Oct 18, 2024
ac89149
flesh-out tests a bit
shmax Oct 18, 2024
d89a6b8
support enum type
shmax Oct 18, 2024
b0d83f8
move to single hyphens
shmax Oct 18, 2024
b01c5f3
throw exception for enum error type with no validation
shmax Oct 18, 2024
5c8957a
remove redundant try/catch
shmax Oct 19, 2024
1c0d9d9
prefix items with _
shmax Oct 19, 2024
cfb661a
pass typesetter
shmax Oct 19, 2024
14481d8
handle nre
shmax Oct 19, 2024
ceeb1ec
handle wrapped type when validating InputObjectType
shmax Oct 19, 2024
6118dbd
fixes around inputobject validation
shmax Oct 19, 2024
a7bc321
rejigger validation a bit
shmax Oct 20, 2024
355464c
fix nre
shmax Oct 20, 2024
de59ca3
fix nre
shmax Oct 20, 2024
930663c
fix nre
shmax Oct 20, 2024
485d898
fix list of error handling
shmax Oct 20, 2024
75e6bc2
cleanup
shmax Oct 20, 2024
badafd5
remove coalesce
shmax Oct 20, 2024
05b1b28
fixes
shmax Oct 20, 2024
fe9dc9e
fix valid check
shmax Oct 20, 2024
5425e5f
fetch result properly
shmax Oct 20, 2024
4a2abaf
fix static usage
shmax Oct 20, 2024
446579b
fix tests
shmax Oct 20, 2024
612dba9
fix tests
shmax Oct 21, 2024
b85d69e
test list of enum, fix nre
shmax Oct 21, 2024
7438f5b
fix NRE, add test
shmax Oct 21, 2024
dd0e455
wip
shmax Oct 23, 2024
52afbaf
use local type setter
shmax Oct 25, 2024
4c77469
implement naming rules
shmax Oct 26, 2024
37a78f1
stanning
shmax Oct 27, 2024
e2468fc
rename type
shmax Oct 27, 2024
f567ceb
Revert "rename type"
shmax Oct 27, 2024
0cb54ff
remove dupe
shmax Oct 27, 2024
bd692e1
simplify types
shmax Oct 27, 2024
23761dd
always append ErrorCode to enums
shmax Oct 27, 2024
0f013f0
remove unused
shmax Oct 27, 2024
a0b7144
fix empty check
shmax Oct 27, 2024
d65c96d
throw exception for overly complex type
shmax Oct 28, 2024
76d5f55
cleanup
shmax Oct 28, 2024
4de97b2
file
shmax Oct 28, 2024
6a66ffb
use simple type
shmax Oct 28, 2024
ecfd084
implement validationMode
shmax Oct 29, 2024
2cd5eb4
stanning
shmax Oct 29, 2024
a801772
update docs
shmax Oct 30, 2024
db49dc9
don't use static errortype isntance for results
shmax Nov 2, 2024
e844f8f
static setTypeSetter
shmax Nov 2, 2024
cca39e9
Cleanup
shmax Nov 2, 2024
4c533ee
tweak coverage ci
shmax Nov 3, 2024
6e05c90
rename file
shmax Nov 3, 2024
d13b2b4
remove unused
shmax Nov 3, 2024
67ffeac
rename some stuff
shmax Nov 3, 2024
2620d30
update phpunit
shmax Nov 3, 2024
66f9ecb
tweak name
shmax Nov 3, 2024
dd6583c
try testdox
shmax Nov 3, 2024
c34aa9a
fix deprecation
shmax Nov 3, 2024
5b8af60
fix includes
shmax Nov 3, 2024
1e1ff3e
rename more stuff
shmax Nov 3, 2024
3a6f928
remove annotation
shmax Nov 3, 2024
26b1d91
more coverage, more renaming
shmax Nov 3, 2024
6c1d461
stanning
shmax Nov 4, 2024
689aab3
chance order
shmax Nov 4, 2024
88f9d30
don't pass name path to create
shmax Nov 4, 2024
8da4cb0
fix name generation
shmax Nov 4, 2024
cb132fa
fix self validation
shmax Nov 4, 2024
3c1db89
simplify default error result
shmax Dec 7, 2024
90bc821
null if not error
shmax Dec 8, 2024
0898833
short circuit on false result
shmax Apr 16, 2025
02ba0d8
implement short-circuiting, allow 'items' validation for non-scalar t…
shmax Apr 17, 2025
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
30 changes: 6 additions & 24 deletions .github/workflows/test.yml → .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Test
name: Tests w/ coverage

on:
pull_request:
branches:
- '**'
push:
branches:
- master
Expand Down Expand Up @@ -38,29 +40,9 @@ jobs:
export $ENV
vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Upload coverage file
uses: actions/upload-artifact@v3
with:
name: phpunit-${{ matrix.deps }}-${{ matrix.php-version }}.coverage
path: coverage.xml
upload_coverage:
name: Upload coverage to Codecov
runs-on: ubuntu-20.04
needs:
- phpunit

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Download coverage files
uses: actions/download-artifact@v3
with:
path: reports

- name: Upload to Codecov
uses: codecov/codecov-action@v3
with:
directory: reports
files: coverage.xml
flags: phpunit-${{ matrix.php-version }}
name: phpunit-${{ matrix.php-version }}
152 changes: 86 additions & 66 deletions README.md

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "shmax/graphql-php-validation-toolkit",
"description": "Do validation on fields and args for graphql queries and mutations, and dynamically generate user error types",
"type": "library",
"license": "MIT",
"homepage": "https://github.com/shmax/graphql-php-validation-toolkit",
"keywords": [
"name": "shmax/graphql-php-validation-toolkit",
"description": "Do validation on fields and args for graphql queries and mutations, and dynamically generate user error types",
"type": "library",
"license": "MIT",
"homepage": "https://github.com/shmax/graphql-php-validation-toolkit",
"keywords": [
"graphql",
"PHP",
"mutation",
Expand All @@ -23,7 +23,7 @@
"phpstan/phpstan-phpunit": "1.3.10",
"mll-lab/php-cs-fixer-config": "^5.0",
"phpstan/phpstan-strict-rules": "1.5.0",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^10",
"webonyx/graphql-php": "^v15.3.0"
},
"config": {
Expand All @@ -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\ErrorType\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\ErrorType\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\ErrorType\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
Loading
Loading