Skip to content

Commit 34ca931

Browse files
committed
Sanity check to ensure that GraphQL query is string
1 parent 3f909e3 commit 34ca931

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/GraphQL.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GraphQL
1818
{
1919
/**
2020
* @param Schema $schema
21-
* @param $requestString
21+
* @param string|DocumentNode $requestString
2222
* @param mixed $rootValue
2323
* @param array|null $variableValues
2424
* @param string|null $operationName
@@ -41,7 +41,7 @@ public static function execute(Schema $schema, $requestString, $rootValue = null
4141

4242
/**
4343
* @param Schema $schema
44-
* @param $requestString
44+
* @param string|DocumentNode $requestString
4545
* @param null $rootValue
4646
* @param null $variableValues
4747
* @param null $operationName

src/Language/Source.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace GraphQL\Language;
33

4+
use GraphQL\Utils;
5+
46
class Source
57
{
68
/**
@@ -20,6 +22,11 @@ class Source
2022

2123
public function __construct($body, $name = null)
2224
{
25+
Utils::invariant(
26+
is_string($body),
27+
'GraphQL query body is expected to be string, but got ' . Utils::getVariableType($body)
28+
);
29+
2330
$this->body = $body;
2431
$this->length = mb_strlen($body, 'UTF-8');
2532
$this->name = $name ?: 'GraphQL';

0 commit comments

Comments
 (0)