Comments (12)
Can you provide the full stacktrace?
from graphql.
[12-Jan-2020 10:00:26 UTC] PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /Users/leo/Sites/PoPAPIWP/vendor/youshido/graphql/src/Execution/Request.php on line 66
[12-Jan-2020 10:00:26 UTC] PHP Fatal error: Uncaught Error: Call to a member function hasDefaultValue() on null in /Users/leo/Sites/PoPAPIWP/vendor/youshido/graphql/src/Execution/Request.php:69
Stack trace:
#0 /Users/leo/GitRepos/GitHub/Libraries/getpop/api-graphql-query/src/Schema/GraphQLQueryConvertor.php(255): Youshido\GraphQL\Execution\Request->__construct(Array, NULL)
#1 /Users/leo/GitRepos/GitHub/Libraries/getpop/api-graphql-query/src/Schema/GraphQLQueryConvertor.php(40): PoP\GraphQLAPIQuery\Schema\GraphQLQueryConvertor->parseAndCreateRequest('# query {\n# _...', NULL)
#2 /Users/leo/GitRepos/GitHub/Libraries/getpop/api-graphql-request/src/Hooks/VarsHooks.php(60): PoP\GraphQLAPIQuery\Schema\GraphQLQueryConvertor->convertFromGraphQLToFieldQuery('# query {\n# _...', NULL)
#3 /Users/leo/GitRepos/GitHub/Libraries/getpop/api-graphql-request/src/Hooks/VarsHooks.php(30): PoP\GraphQLAPIRequest\Hooks\VarsHooks->processURLParamVars(Array)
#4 /Users/leo/Sites/PoPAPIWP/wp/wp-includes/class-wp-hook.php(288): PoP\GraphQLAPIRequest\Hooks\VarsHooks->addURLPar in /Users/leo/Sites/PoPAPIWP/vendor/youshido/graphql/src/Execution/Request.php on line 69
My code, from which the error happens, is this line:
$request = new Request($parsedData, $variables);
from this code in my library (not Youshido):
protected function parseAndCreateRequest($payload, $variables = []): Request
{
if (empty($payload)) {
throw new InvalidArgumentException($this->translationAPI->__('Must provide an operation.'));
}
$parser = new Parser();
$parsedData = $parser->parse($payload);
$request = new Request($parsedData, $variables);
// If the validation fails, it will throw an exception
(new RequestValidator())->validate($request);
// Return the request
return $request;
}
from graphql.
Try setting the default value of $variables
to null
instead of []
.
from graphql.
I just did, it still fails, same exception
from graphql.
Please notice that if you pass a variables dictionary including the variable date
it doesn't throw an exception. It only does when variable date
is not present in the dictionary (and not defined in the operation name)
from graphql.
I have to try reproducing on my own, it should fail with a better error, like "Variable $date not submitted".
from graphql.
Currently it fails with a better error when either the variable is defined in the operation name but not in the variables, or the other way around. Only when both are missing it throws an exception.
I believe it should be straightforward to reproduce, since there's nothing special in my code.
from graphql.
I fixed it in #239. It will still error out of course, but the exception will come from the request validator instead of the parser.
from graphql.
This problem can be fixed by checking in Execution/Request.php
, function __construct
, that the variable that produces the exception is not null
.
Currently:
$variable = $ref->getVariable();
if ($variable->hasDefaultValue()) {
Fix:
$variable = $ref->getVariable();
if (!is_null($variable) && $variable->hasDefaultValue()) {
If it is null
, then the ensuing error message "Variable %s hasn't been submitted"
is good enough (at least for the time being). Would you agree? Should I submit a PR? (I need to fix it, since this problem is happening in my PROD)
from graphql.
Ops, I closed by mistake.
This branch in my fork handles this solution a bit better:
https://github.com/getpop/graphql-parser/tree/fix-exception-when-no-args-declared
from graphql.
Feel free to make a PR. I don't remember what the issue was with my previous attempt anymore, I got a feeling it's not as easy to fix as it sounds like. Maybe your solution works better though.
from graphql.
My solution is simple, because it notices that, if the variable was not defined in the operation, then this line will return null
:
$variable = $ref->getVariable();
Maybe this could be handled more elegantly, but this solution, at least, avoids the RuntimeException
that was breaking my server.
I'm submitting the PR now
from graphql.
Related Issues (20)
- thrown an error when type name already exists HOT 2
- Troubleshooting needs to mention php-mbstring HOT 1
- Possible incorrect parsing of some scalar values HOT 2
- Are you looking for help in maintaining this library? HOT 5
- counting queries in payload HOT 1
- Scoping errors to the offending query when batching queries HOT 2
- Public Static Function getPropertyValue() when var in entity starts with "is" HOT 1
- How to pass ListType as argument ? HOT 1
- Tag new version HOT 2
- Improve debugging process HOT 1
- ResolvableObjectTrait should gracefully return null for all nullable types, not just scalar ones HOT 1
- Add support for error extensions
- Update Scrutinizer CI integration after organization name change HOT 2
- Not compatible with symfony 4.4 HOT 2
- ASTField query, not its subqueries HOT 1
- Operation type directive is overriding directives defined in ancestor fields HOT 5
- Can extract the Parser as a standalone package? HOT 2
- Parsing arrays of ENUMs doesn't work
- Errors when using with PHP 8.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql.