Skip to content

Commit 0c3432e

Browse files
committed
Initial implementation
1 parent 1b3d94c commit 0c3432e

File tree

96 files changed

+11745
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+11745
-2
lines changed

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
*.lo
2+
*.la
3+
.*.swp
4+
.deps
5+
.libs/
6+
include/
7+
tests/*.diff
8+
tests/*.exp
9+
tests/*.log
10+
tests/*.php
11+
tests/*.out
12+
tests/*.sh
13+
Makefile
14+
Makefile.fragments
15+
Makefile.global
16+
Makefile.objects
17+
acinclude.m4
18+
aclocal.m4
19+
autom4te.cache/
20+
build/
21+
config.guess
22+
config.h
23+
config.h.in
24+
config.log
25+
config.nice
26+
config.status
27+
config.sub
28+
configure
29+
configure.in
30+
install-sh
31+
libtool
32+
ltmain.sh
33+
missing
34+
mkinstalldirs
35+
modules/
36+
run-tests.php

.travis.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: php
2+
3+
sudo: required
4+
5+
addons:
6+
apt:
7+
sources:
8+
- ubuntu-toolchain-r-test
9+
packages:
10+
- g++-4.8
11+
12+
matrix:
13+
fast_finish: true
14+
include:
15+
- php: 5.3
16+
- php: 5.4
17+
- php: 5.5
18+
- php: 5.6
19+
- php: 7.0
20+
- php: nightly
21+
allow_failures:
22+
- php: nightly
23+
24+
before_script:
25+
- pushd deps/libgraphqlparser && CXX=g++-4.8 cmake . && make && sudo make install && popd
26+
- phpize && ./configure && make && make install
27+
- echo "extension = graphql.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
28+
- php -m
29+
30+
script: REPORT_EXIT_STATUS=1 php run-tests.php -q -p $(which php) --show-diff

LICENSE

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
MIT License
2-
31
Copyright (c) 2016 Diego Saint Esteben
42

53
Permission is hereby granted, free of charge, to any person obtaining a copy

README.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# libgraphqlparser PHP bindings
2+
3+
[![Build Status](https://travis-ci.org/dosten/graphql-parser-php.svg?branch=master)](https://travis-ci.org/dosten/graphql-parser-php)
4+
5+
A PHP extension wrapping the [libgraphqlparser](https://github.com/graphql/libgraphqlparser) library for parsing [GraphQL](http://graphql.org).
6+
7+
## Installation
8+
9+
### Installing libgraphqlparser
10+
11+
You need to install libgraphqlparser before attempting to compile this extension.
12+
13+
```
14+
$ cd deps/libgraphqlparser
15+
$ cmake .
16+
$ make
17+
$ make install
18+
```
19+
20+
### Compiling the extension
21+
22+
```
23+
$ phpize
24+
$ ./configure
25+
$ make
26+
$ make install
27+
```
28+
29+
### Installing the extension
30+
31+
`make install` copies `graphql.so` to an appropriate location, but you still
32+
need to enable the extension in the PHP config file. To do so, edit your
33+
`php.ini` with the following contents: `extension=graphql.so`
34+
35+
## Usage
36+
37+
```php
38+
<?php
39+
40+
use GraphQL\Parser;
41+
use GraphQL\Error\ParseError;
42+
43+
$parser = new Parser();
44+
45+
try {
46+
$ast = $parser->parse('query { name }');
47+
print_r($ast);
48+
} catch (ParseError $e) {
49+
echo sprintf('Parse error: %s', $e->getMessage());
50+
}
51+
```
52+
53+
The output will be:
54+
55+
```
56+
Array
57+
(
58+
[kind] => Document
59+
[loc] => Array
60+
(
61+
[start] => 1
62+
[end] => 15
63+
)
64+
65+
[definitions] => Array
66+
(
67+
[0] => Array
68+
(
69+
[kind] => OperationDefinition
70+
[loc] => Array
71+
(
72+
[start] => 1
73+
[end] => 15
74+
)
75+
76+
[operation] => query
77+
[name] =>
78+
[variableDefinitions] =>
79+
[directives] =>
80+
[selectionSet] => Array
81+
(
82+
[kind] => SelectionSet
83+
[loc] => Array
84+
(
85+
[start] => 7
86+
[end] => 15
87+
)
88+
89+
[selections] => Array
90+
(
91+
[0] => Array
92+
(
93+
[kind] => Field
94+
[loc] => Array
95+
(
96+
[start] => 9
97+
[end] => 13
98+
)
99+
100+
[alias] =>
101+
[name] => Array
102+
(
103+
[kind] => Name
104+
[loc] => Array
105+
(
106+
[start] => 9
107+
[end] => 13
108+
)
109+
110+
[value] => name
111+
)
112+
113+
[arguments] =>
114+
[directives] =>
115+
[selectionSet] =>
116+
)
117+
118+
)
119+
120+
)
121+
122+
)
123+
124+
)
125+
126+
)
127+
```
128+
129+
## License
130+
131+
This extension is licensed under the MIT License, see the LICENSE file for details.

config.m4

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
PHP_ARG_ENABLE(graphql, whether to enable graphql support, [--enable-graphql Enable graphql support])
2+
3+
if test "$PHP_GRAPHQL" != "no"; then
4+
PHP_REQUIRE_CXX()
5+
PHP_ADD_INCLUDE(/usr/local/include)
6+
7+
LIBNAME=graphqlparser
8+
LIBSYMBOL=graphql_parse_string
9+
10+
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
11+
[
12+
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, /usr/local/lib, GRAPHQL_SHARED_LIBADD)
13+
AC_DEFINE(HAVE_LIBGRAPHQLPARSER,1,[ ])
14+
],[
15+
AC_MSG_ERROR([wrong libxyz lib version or lib not found])
16+
],[
17+
-L/usr/local/lib -lm
18+
])
19+
20+
PHP_SUBST(GRAPHQL_SHARED_LIBADD)
21+
22+
PHP_NEW_EXTENSION(graphql, graphql.c, $ext_shared)
23+
fi

deps/libgraphqlparser/.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bison.tab.cpp
2+
bison.tab.hpp
3+
*.o
4+
parser.output
5+
dump_json_ast
6+
Ast.h
7+
Ast.cpp
8+
AstVisitor.h
9+
*.dSYM
10+
CMakeCache.txt
11+
CMakeFiles
12+
CMakeScripts
13+
Makefile
14+
cmake_install.cmake
15+
*.a
16+
*.dylib
17+
*.so
18+
GraphQLParser.py
19+
install_manifest.txt
20+
build/
21+
libgraphqlparser.pc

deps/libgraphqlparser/.travis.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
language: cpp
2+
3+
compiler:
4+
- clang
5+
- gcc
6+
7+
8+
addons:
9+
apt:
10+
packages:
11+
- valgrind
12+
13+
before_install:
14+
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
15+
- sudo apt-get update -qq
16+
# bison and flex are not installed in CI because
17+
# 1) the versions in Travis are too old, and
18+
# 2) up-to-date bison and flex output should be checked in.
19+
# Versions of g++ prior to 4.8 don't have very good C++11 support.
20+
- sudo apt-get install -y g++-4.8
21+
&& sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
22+
- wget https://codeload.github.com/google/googletest/zip/release-1.8.0
23+
&& cd test
24+
&& unzip ../release-1.8.0
25+
&& cd ..
26+
&& rm release-1.8.0
27+
28+
script: mkdir build && cd build && cmake .. -Dtest=ON && make && test/runTests && make memcheck

deps/libgraphqlparser/AstNode.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#pragma once
11+
12+
#include "location.hh"
13+
14+
namespace facebook {
15+
namespace graphql {
16+
namespace ast {
17+
18+
namespace visitor {
19+
class AstVisitor;
20+
}
21+
22+
class Node {
23+
yy::location location_;
24+
public:
25+
explicit Node(const yy::location &location)
26+
: location_(location) {}
27+
28+
virtual ~Node() {}
29+
30+
const yy::location &getLocation() const
31+
{ return location_; }
32+
33+
virtual void accept(visitor::AstVisitor *visitor) = 0;
34+
};
35+
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)