Skip to content

Support both string and array variables recieved #230

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
erangakm opened this issue Jan 16, 2018 · 5 comments
Closed

Support both string and array variables recieved #230

erangakm opened this issue Jan 16, 2018 · 5 comments

Comments

@erangakm
Copy link

erangakm commented Jan 16, 2018

Currently only arrays are supported.

When sent a request with arrays as variables I get the following error: body: { error: { message: 'Argument 1 passed to GraphQL\\Validator\\Rules\\QueryComplexity::setRawVariableValues() must be of the type array, string given, called in /portal/library/composer/webonyx/graphql-php/src/GraphQL.php on line 62 and defined' } } }.

Any reason why only arrays are allowed if this is intentional? If not it should support both formats.

@vladar
Copy link
Member

vladar commented Jan 16, 2018

Please post the reproducible example of the code which causes this.

@erangakm
Copy link
Author

@vladar Sorry, I just realised I wrote the bug report saying strings aren't supported, it should be corrected to arrays aren't supported. I've edited the post.

sending a request from a typescript app:

  public sendRequest = async (): Promise<object> =>
    callbackToPromise<httpRequest.RequestResponse>((cb) => {
      httpRequest.post(this.options, cb);
    }).then(this.handleResponses)

These are the contents of a this.options for a request when variables are set as an object array (working):

{ headers: {},
   method: 'POST',
   url: 'http://xxxxx.ngrok.io/api/v3/graphql',
   json:
    { query: '\n  mutation app {\n    application_login(token: "tok_123") {\n      query {\n        viewer {\n          uid\n        }\n      }\n    }\n  }\n',
      variables: { xxx: 567 } } }

These are the contents when the object array is JSON stringified (not working):

{ headers: {},
   method: 'POST',
   url: 'http://xxxxx.ngrok.io/api/v3/graphql',
   json:
    { query: '\n  mutation app {\n    application_login(token: "tok_123") {\n      query {\n        viewer {\n          uid\n        }\n      }\n    }\n  }\n',
      variables: '{"xxx":567}' } }

@vladar
Copy link
Member

vladar commented Jan 17, 2018

How do you run graphql-php? Using StandardServer or just GraphQL::executeQuery? I mostly need graphql-php related code to repro.

@vladar
Copy link
Member

vladar commented Feb 12, 2018

Closing due to inactivity, feel free to re-open with new data.

@vladar vladar closed this as completed Feb 12, 2018
@bitrix1
Copy link

bitrix1 commented Feb 22, 2018

Hi! I have this problem.
Compare:
Work (addon ChromeiQL generate query)
{"query":"{\n echo(message: "Hello World")\n}\n","variables":null,"operationName":null}

Error (addon GraphIQL Feen! generate query)
{"query":"{\n echo(message: "Hello World")\n}\n","variables":""}


Fatal error: Uncaught TypeError: Argument 1 passed to GraphQL\Validator\Rules\QueryComplexity::setRawVariableValues() must be of the type array, string given, called in /home/bitrix/www/files/graphql-php/vendor/webonyx/graphql-php/src/GraphQL.php on line 137 and defined in /home/bitrix/www/files/graphql-php/vendor/webonyx/graphql-php/src/Validator/Rules/QueryComplexity.php:61
Stack trace:
#0 /home/bitrix/www/files/graphql-php/vendor/webonyx/graphql-php/src/GraphQL.php(137): GraphQL\Validator\Rules\QueryComplexity->setRawVariableValues('')
#1 /home/bitrix/www/files/graphql-php/vendor/webonyx/graphql-php/src/GraphQL.php(86): GraphQL\GraphQL::promiseToExecute(Object(GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter), Object(GraphQL\Type\Schema), '{\n echo(messag...', Array, NULL, '', NULL, NULL, NULL)
#2 /home/bitrix/www/files/crypto/test.php(409): GraphQL\GraphQL::executeQuery(Object(GraphQL\Type\Schema), '{\n echo(messag...', Array, NULL, '')
#3 {main}
thrown in /home/bitrix/www/files/graphql-php/vendor/webonyx/graphql-php/src/Validator/Rules/QueryComplexity.php on line 61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants