GraphQL\Language\Parser::parseValue PHP Method

parseValue() public static method

Throws GraphQLError if a syntax error is encountered. This is useful within tools that operate upon GraphQL Values directly and in isolation of complete GraphQL documents. Consider providing the results to the utility function: valueFromAST().
public static parseValue ( Source | string $source, array $options = [] ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | ListValueNode | ObjectValueNode | StringValueNode | VariableNode
$source Source | string
$options array
return GraphQL\Language\AST\BooleanValueNode | GraphQL\Language\AST\EnumValueNode | GraphQL\Language\AST\FloatValueNode | GraphQL\Language\AST\IntValueNode | GraphQL\Language\AST\ListValueNode | GraphQL\Language\AST\ObjectValueNode | GraphQL\Language\AST\StringValueNode | GraphQL\Language\AST\VariableNode
    public static function parseValue($source, array $options = [])
    {
        $sourceObj = $source instanceof Source ? $source : new Source($source);
        $parser = new Parser($sourceObj, $options);
        $parser->expect(Token::SOF);
        $value = $parser->parseValueLiteral(false);
        $parser->expect(Token::EOF);
        return $value;
    }

Usage Example

Esempio n. 1
0
 /**
  * @it parses list values
  */
 public function testParsesListValues()
 {
     $this->assertEquals(['kind' => NodeKind::LST, 'loc' => ['start' => 0, 'end' => 11], 'values' => [['kind' => NodeKind::INT, 'loc' => ['start' => 1, 'end' => 4], 'value' => '123'], ['kind' => NodeKind::STRING, 'loc' => ['start' => 5, 'end' => 10], 'value' => 'abc']]], $this->nodeToArray(Parser::parseValue('[123 "abc"]')));
 }
All Usage Examples Of GraphQL\Language\Parser::parseValue