项目作者: andheiberg

项目描述 :
Wrap graphql/libgraphqlparser in a PHP extension
高级语言: PHP
项目地址: git://github.com/andheiberg/graphql-parser-php-extension.git
创建时间: 2017-02-15T09:31:05Z
项目社区:https://github.com/andheiberg/graphql-parser-php-extension

开源协议:Other

下载


graphql-parser

PHP Extension for Parsing GraphQL Query Language and GraphQL Schema Language. Based off Facebooks own C parser implemention.

Requirements

Installation

  1. # modify INI_DIR in Makefile to be the path to your conf.d can be found using php-config --configure-options
  2. make
  3. make install

Usage

  1. <?php
  2. use AndHeiberg\GraphQL\Parser\Parser;
  3. $parser = new Parser();
  4. try {
  5. $ast = $parser->parse('query { name }');
  6. } catch (\Exception $e) {
  7. echo sprintf('Parse error: %s', $e->getMessage());
  8. }

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.

TODO:

  • Remove modify INI_DIR step from installation
  • Use custom exceptions instead of \Exception
  • Generate PHP classes in the extension and convert the AST to PHP classes instead of array
  • Generate PHP stubs for AST that can be used by IDEs
  • Create build script to fetch latest ast.ast from libgraphqlparser