PHPackages                             hansott/graphql-language - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. hansott/graphql-language

Abandoned → [webonyx/graphql-php](/?search=webonyx%2Fgraphql-php)ArchivedLibrary[API Development](/categories/api)

hansott/graphql-language
========================

A GraphQL parser written in PHP

1.3.1(8y ago)751[1 PRs](https://github.com/hansott/graphql-language/pulls)MITPHP

Since Sep 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/hansott/graphql-language)[ Packagist](https://packagist.org/packages/hansott/graphql-language)[ Docs](https://github.com/hansott/graphql-language)[ RSS](/packages/hansott-graphql-language/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

GraphQL Language
================

[](#graphql-language)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bbc7e5986f22df277ad5a3a3e04416f85ee7e46883afd9037c2d1816bca0d909/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616e736f74742f6772617068716c2d6c616e67756167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hansott/graphql-language)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/91753a9871e32a612994ca5773312eba38281c4038b2cc10a3845481e31e5330/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f68616e736f74742f6772617068716c2d6c616e67756167652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/hansott/graphql-language)[![Coverage Status](https://camo.githubusercontent.com/052ecc51eb7cead1fc3cf12e5483628df6db39e3201ecaafb53b704ca0e85125/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f68616e736f74742f6772617068716c2d6c616e67756167652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hansott/graphql-language/code-structure)[![Quality Score](https://camo.githubusercontent.com/20b2eaa5ce2ca0f75f0fcc60707c6b022a08b90250b7a061651a589763587ff3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f68616e736f74742f6772617068716c2d6c616e67756167652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hansott/graphql-language)[![Total Downloads](https://camo.githubusercontent.com/7efbf84c5032e8560e43f26a39d56d314be908ea259a7e09797bdd11f191fcf3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616e736f74742f6772617068716c2d6c616e67756167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hansott/graphql-language)

A GraphQL parser written in PHP. The parser is able to parse the full [spec](https://facebook.github.io/graphql/). This package is compatible with PHP 5.3+. I'm still actively working on this project. Expect things to break. 🙈

This package is being developed together with a server package, which isn't public yet.

Install
-------

[](#install)

Via Composer

```
$ composer require hansott/graphql-language
```

Usage
-----

[](#usage)

### Parsing a query to a [HansOtt\\GraphQL\\Query\\Document](src/Query/Document.php)

[](#parsing-a-query-to-a-hansottgraphqlquerydocument)

```
use HansOtt\GraphQL\Query\ParseError;
use HansOtt\GraphQL\Query\SyntaxError;
use HansOtt\GraphQL\Query\ParserFactory;

$factory = new ParserFactory;
$parser = $factory->create();

$query = queries[] = $node;
        }
    }

    public function getQueries()
    {
        return $this->queries;
    }
}

$document = $parser->parse($query);
$finder = new VisitorQueryFinder;

$traverser = new Traverser($finder);
$traverser->traverse($document);
var_dump($finder->getQueries());

// Or if you need multiple visitors
// use HansOtt\GraphQL\Query\VisitorMany

$visitors = new VisitorMany([$finder, ...]);
$traverser = new Traverser($visitors);
$traverser->traverse($document);
var_dump($finder->getQueries());
```

### Parsing a schema declaration to a [HansOtt\\GraphQL\\Schema\\Schema](src/Schema/Schema.php)

[](#parsing-a-schema-declaration-to-a-hansottgraphqlschemaschema)

```
use HansOtt\GraphQL\Schema\ParseError;
use HansOtt\GraphQL\Schema\SyntaxError;
use HansOtt\GraphQL\Schema\ParserFactory;

$factory = new ParserFactory;
$parser = $factory->create();

$schema =
