Wrap graphql/libgraphqlparser in a PHP extension
PHP Extension for Parsing GraphQL Query Language and GraphQL Schema Language. Based off Facebooks own C parser implemention.
brew install php70
or brew install php71
)brew install libgraphqlparser
)
# modify INI_DIR in Makefile to be the path to your conf.d can be found using php-config --configure-options
make
make install
<?php
use AndHeiberg\GraphQL\Parser\Parser;
$parser = new Parser();
try {
$ast = $parser->parse('query { name }');
} catch (\Exception $e) {
echo sprintf('Parse error: %s', $e->getMessage());
}
Parser::parse()
will be a AndHeiberg\GraphQL\Parser\AST\Document
or a AndHeiberg\GraphQL\Parser\AST\SchemaDefinition
object. Have a look at the php stub files to get an understanding of the AST structure.
The files can also be dropped into your IDE to allow auto-complete.