gql
A Ruby implementation of Facebook's yet-to-be-released GraphQL specification, inspired by graphql-ruby, but with other/more/less features/bugs.
Installation
Add this line to your application's Gemfile:
gem 'gql'
And then execute:
$ bundle
Or install it yourself as:
$ gem install gql
Usage
TODO: Write usage instructions here
Example
Run bin/console for an interactive prompt (loaded with example models/data) and enter the following:
puts query(" user(<token>) {\n id,\n is_admin,\n full_name as name,\n created_at { year, month } as created_year_and_month,\n created_at.format(\"long\") as created,\n account {\n bank_name,\n iban,\n saldo as saldo_string,\n saldo {\n currency,\n cents /* silly block comment */\n }\n },\n albums.first(2) {\n count,\n edges {\n cursor,\n node {\n artist,\n title,\n songs.first(2) {\n edges {\n id,\n title.upcase as upcased_title,\n title.upcase.length as upcased_title_length\n }\n }\n }\n }\n }\n }\n\n <token> = \"ma\" // a variable\n").to_json
This should result in the following JSON (after prettyfication):
{
"id": "ma",
"is_admin": true,
"name": "Martin Andert",
"created_year_and_month": {
"year": 2010,
"month": 3
},
"created": "March 05, 2010 20:14",
"account": {
"bank_name": "Foo Bank",
"iban": "987654321",
"saldo_string": "100000.00 EUR",
"saldo": {
"currency": "EUR",
"cents": 10000000
}
},
"albums": {
"count": 2,
"edges": [
{
"cursor": 1,
"node": {
"artist": "Metallica",
"title": "Black Album",
"songs": {
"edges": [
{
"id": 1,
"upcased_title": "ENTER SANDMAN",
"upcased_title_length": 13
}, {
"id": 2,
"upcased_title": "SAD BUT TRUE",
"upcased_title_length": 12
}
]
}
}
}, {
"cursor": 2,
"node": {
"artist": "Nirvana",
"title": "Nevermind",
"songs": {
"edges": [
{
"id": 5,
"upcased_title": "SMELLS LIKE TEEN SPIRIT",
"upcased_title_length": 23
}, {
"id": 6,
"upcased_title": "COME AS YOU ARE",
"upcased_title_length": 15
}
]
}
}
}
]
}
}
Development
After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.
Contributing
- Fork it ( https://github.com/martinandert/gql/fork )
- Run
bin/setupto install dependencies. - Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate:
bin/rake test. - Create your feature branch (
git checkout -b my-new-feature) - Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or are fixing a bug, we need a test!
- Make the test pass.
- Commit your changes (
git commit -am 'add some feature') - Push to your fork (
git push origin my-new-feature) - Create a new Pull Request
License
Released under The MIT License.