Skip to content
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

Allow \stdClass for input types #535

Merged
merged 2 commits into from
Aug 14, 2019
Merged

Conversation

adam1658
Copy link
Contributor

Allow \stdClass in GraphQL\Util\Value::coerceValue. \stdClass will be cast to an associative array, and the coerced value will still be an associative array.

Useful for when you want to parse incoming variables JSON with \stdClass (for example, if you have custom scalars that have this requirement, but cannot distinguish between scalars and inputs at the variables level).

Note that the variables map is still required to be an associative array - one way that users can parse variables JSON in this way is to parse in \stdClass mode, then cast the map to an array:

$variables = (array)json_decode('{"a": {}, "b": []}', false);
var_dump($variables);
/* array(2) {
  ["a"]=>
  object(stdClass)#1 (0) {
  }
  ["b"]=>
  array(0) {
  }
}
*/

Fixes #534.

Please let me know if the implementation, tests or docs changes are incorrect or lacking.

Thanks,
Adam

@vladar vladar merged commit 1773943 into webonyx:master Aug 14, 2019
@vladar
Copy link
Member

vladar commented Aug 14, 2019

Cool! Thanks for such a complete PR with docs, tests, etc. It's a rare thing %)

@adam1658
Copy link
Contributor Author

Hi @vladar, when do you expect the next release to be published? I'd love to start making use of this feature.

@vladar
Copy link
Member

vladar commented Aug 23, 2019

@adam1658 Just published v0.13.7. Check it out

@adam1658
Copy link
Contributor Author

Legend! Thanks so much

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

Successfully merging this pull request may close these issues.

support \stdClass for input types
2 participants