Sanity check to ensure that GraphQL query is string

This commit is contained in:
Vladimir Razuvaev 2017-02-24 17:10:10 +07:00
parent 3f909e3e11
commit 34ca931533
2 changed files with 9 additions and 2 deletions

View File

@ -18,7 +18,7 @@ class GraphQL
{
/**
* @param Schema $schema
* @param $requestString
* @param string|DocumentNode $requestString
* @param mixed $rootValue
* @param array|null $variableValues
* @param string|null $operationName
@ -41,7 +41,7 @@ class GraphQL
/**
* @param Schema $schema
* @param $requestString
* @param string|DocumentNode $requestString
* @param null $rootValue
* @param null $variableValues
* @param null $operationName

View File

@ -1,6 +1,8 @@
<?php
namespace GraphQL\Language;
use GraphQL\Utils;
class Source
{
/**
@ -20,6 +22,11 @@ class Source
public function __construct($body, $name = null)
{
Utils::invariant(
is_string($body),
'GraphQL query body is expected to be string, but got ' . Utils::getVariableType($body)
);
$this->body = $body;
$this->length = mb_strlen($body, 'UTF-8');
$this->name = $name ?: 'GraphQL';