@@ -54,8 +54,8 @@ |
||
54 | 54 | protected function _getType($config) { |
55 | 55 | $type = $config['type']; |
56 | 56 | if (is_callable($type)) { |
57 | - $type = $type(); |
|
58 | - } |
|
57 | + $type = $type(); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | if ($type instanceof WrappingType) { |
61 | 61 | $type = $type->getWrappedType(true); |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | |
38 | 38 | parent::__construct([ |
39 | 39 | 'type' => $lazy ? function() use($name, $config, $args) { |
40 | - return static::_create($name, $args, $config); |
|
41 | - } : static::_create($name, $args, $config), |
|
40 | + return static::_create($name, $args, $config); |
|
41 | + } : static::_create($name, $args, $config), |
|
42 | 42 | 'args' => $args, |
43 | 43 | 'name' => $name, |
44 | 44 | 'resolve' => function ($value, $args1, $context, $info) use ($config, $args) { |
@@ -63,33 +63,33 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | protected function _create($name, $args, $config) { |
66 | - return UserErrorsType::create([ |
|
67 | - 'errorCodes' => $config['errorCodes'] ?? null, |
|
68 | - 'isRoot' => true, |
|
69 | - 'fields' => [ |
|
70 | - $this->resultFieldName => [ |
|
71 | - 'type' => $config['type'], |
|
72 | - 'description' => 'The payload, if any', |
|
73 | - 'resolve' => static function ($value) { |
|
74 | - return $value['result'] ?? null; |
|
75 | - }, |
|
76 | - ], |
|
77 | - $this->validFieldName => [ |
|
78 | - 'type' => Type::nonNull(Type::boolean()), |
|
79 | - 'description' => 'Whether all validation passed. True for yes, false for no.', |
|
80 | - 'resolve' => static function ($value) { |
|
81 | - return $value['valid']; |
|
82 | - }, |
|
83 | - ], |
|
84 | - ], |
|
85 | - 'validate' => $config['validate'] ?? null, |
|
86 | - 'type' => new InputObjectType([ |
|
87 | - 'fields' => $args, |
|
88 | - 'name' => '', |
|
89 | - ]), |
|
90 | - 'typeSetter' => $config['typeSetter'] ?? null, |
|
91 | - ], [$name], false, ucfirst($name) . 'Result'); |
|
92 | - } |
|
66 | + return UserErrorsType::create([ |
|
67 | + 'errorCodes' => $config['errorCodes'] ?? null, |
|
68 | + 'isRoot' => true, |
|
69 | + 'fields' => [ |
|
70 | + $this->resultFieldName => [ |
|
71 | + 'type' => $config['type'], |
|
72 | + 'description' => 'The payload, if any', |
|
73 | + 'resolve' => static function ($value) { |
|
74 | + return $value['result'] ?? null; |
|
75 | + }, |
|
76 | + ], |
|
77 | + $this->validFieldName => [ |
|
78 | + 'type' => Type::nonNull(Type::boolean()), |
|
79 | + 'description' => 'Whether all validation passed. True for yes, false for no.', |
|
80 | + 'resolve' => static function ($value) { |
|
81 | + return $value['valid']; |
|
82 | + }, |
|
83 | + ], |
|
84 | + ], |
|
85 | + 'validate' => $config['validate'] ?? null, |
|
86 | + 'type' => new InputObjectType([ |
|
87 | + 'fields' => $args, |
|
88 | + 'name' => '', |
|
89 | + ]), |
|
90 | + 'typeSetter' => $config['typeSetter'] ?? null, |
|
91 | + ], [$name], false, ucfirst($name) . 'Result'); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | private function _noop($value) { |
95 | 95 | // this is just a no-op validation function to fallback to when no validation function is provided |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $lazy = !empty($config['lazy']) ?? false; |
37 | 37 | |
38 | 38 | parent::__construct([ |
39 | - 'type' => $lazy ? function() use($name, $config, $args) { |
|
39 | + 'type' => $lazy ? function () use($name, $config, $args) { |
|
40 | 40 | return static::_create($name, $args, $config); |
41 | 41 | } : static::_create($name, $args, $config), |
42 | 42 | 'args' => $args, |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | if ($arr === []) { |
105 | 105 | return false; |
106 | 106 | } |
107 | - return array_keys($arr) !== range(0, count($arr) - 1); |
|
107 | + return array_keys($arr) !== range(0, count($arr)-1); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | $path[count($path)-1] = $idx; |
121 | 121 | $newPath = $path; |
122 | 122 | $newPath[] = 0; |
123 | - $this->_validateItems($config, $subValue, $newPath, $validate ); |
|
123 | + $this->_validateItems($config, $subValue, $newPath, $validate); |
|
124 | 124 | } else { |
125 | - $path[count($path) - 1] = $idx; |
|
125 | + $path[count($path)-1] = $idx; |
|
126 | 126 | $err = $validate($subValue); |
127 | 127 | |
128 | - if(empty($err)) { |
|
128 | + if (empty($err)) { |
|
129 | 129 | $wrappedType = $config['type']->getWrappedType(true); |
130 | 130 | $err = $this->_validate([ |
131 | 131 | 'type' => $wrappedType |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | try { |
177 | 177 | $this->_validateItems($config, $value, [0], $config['validate'] ?? [$this, "_noop"]); |
178 | 178 | } catch (ValidateItemsError $e) { |
179 | - if(isset($e->error['suberrors'])) { |
|
179 | + if (isset($e->error['suberrors'])) { |
|
180 | 180 | $err = $e->error; |
181 | 181 | } |
182 | 182 | else { |
@@ -208,10 +208,10 @@ discard block |
||
208 | 208 | $fields = $type->getFields(); |
209 | 209 | if (is_array($value)) { |
210 | 210 | foreach ($value as $key => $subValue) { |
211 | - $config = $fields[$key]->config; |
|
211 | + $config = $fields[$key]->config; |
|
212 | 212 | $error = $this->_validate($config, $subValue); |
213 | 213 | |
214 | - if($error) { |
|
214 | + if ($error) { |
|
215 | 215 | $createSubErrors ? $res[UserErrorsType::SUBERRORS_NAME][$key] = $error : $res[$key] = $error; |
216 | 216 | } |
217 | 217 | } |