<commit_before># graphql

[![Build Status](https://travis-ci.org/rmosolgo/graphql-ruby.svg?branch=master)](https://travis-ci.org/rmosolgo/graphql-ruby)
[![Gem Version](https://badge.fury.io/rb/graphql.svg)](https://rubygems.org/gems/graphql)
[![Code Climate](https://codeclimate.com/github/rmosolgo/graphql-ruby/badges/gpa.svg)](https://codeclimate.com/github/rmosolgo/graphql-ruby)
[![Test Coverage](https://codeclimate.com/github/rmosolgo/graphql-ruby/badges/coverage.svg)](https://codeclimate.com/github/rmosolgo/graphql-ruby)
[![built with love](https://cloud.githubusercontent.com/assets/2231765/6766607/d07992c6-cfc9-11e4-813f-d9240714dd50.png)](http://rmosolgo.github.io/react-badges/)

## Overview

- Install the gem:

  ```ruby
  # Gemfile
  gem 'graphql'
  ```

- Build a schema:
  - See the [test schema](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/support/dummy_app.rb) for an example GraphQL schema in Ruby.
  - See [`graphql-ruby-demo`](https://github.com/rmosolgo/graphql-ruby-demo) for an example schema on Rails

- Execute queries:
  - See [query_spec.rb](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/graph_ql/query_spec.rb) for an example of query execution.
  - See [`queries_controller.rb`](https://github.com/rmosolgo/graphql-ruby-demo/blob/master/app/controllers/queries_controller.rb) for a Rails example
  - Try it on [heroku](http://graphql-ruby-demo.herokuapp.com)

## To Do:

- Validations:<commit_msg>docs(readme) add sample code<commit_after># graphql

[![Build Status](https://travis-ci.org/rmosolgo/graphql-ruby.svg?branch=master)](https://travis-ci.org/rmosolgo/graphql-ruby)
[![Gem Version](https://badge.fury.io/rb/graphql.svg)](https://rubygems.org/gems/graphql)
[![Code Climate](https://codeclimate.com/github/rmosolgo/graphql-ruby/badges/gpa.svg)](https://codeclimate.com/github/rmosolgo/graphql-ruby)
[![Test Coverage](https://codeclimate.com/github/rmosolgo/graphql-ruby/badges/coverage.svg)](https://codeclimate.com/github/rmosolgo/graphql-ruby)
[![built with love](https://cloud.githubusercontent.com/assets/2231765/6766607/d07992c6-cfc9-11e4-813f-d9240714dd50.png)](http://rmosolgo.github.io/react-badges/)

## Overview

- __Install the gem__:

  ```ruby
  # Gemfile
  gem 'graphql'
  ```

  ```
  $ bundle install
  ```

- __Declare types & build a schema__:

  ```ruby
  # Declare a type...
  PostType = GraphQL::ObjectType.new do |t, types, field|
    t.name "Post"
    t.description "A blog post"
    t.fields({
      id:       field.build(type: !types.Int)
      title:    field.build(type: !types.String),
      body:     field.build(type: !types.String),
      comments: field.build(type: types[!CommentType])
    })
  end

  # ...and a query root
  QueryType = GraphQL::ObjectType.new do |t, types, field, arg|
    t.name "Query"
    t.description "The query root of this schema"
    t.fields({
      post: GraphQL::Field.new do |f|
        f.arguments(id: arg.build(type: !types.Int))
        f.resolve -> (object, args, context) {
          Post.find(args["id"])
        }
      end
    })
  end

  # Then create your schema
  Schema = GraphQL::Schema.new(query: QueryType, mutation: nil)
  ```

  See also:
    - the [test schema](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/support/dummy_app.rb)
    - [`graphql-ruby-demo`](https://github.com/rmosolgo/graphql-ruby-demo) for an example schema on Rails

- __Execute queries__:

  ```ruby
  query = GraphQL::Query.new(Schema, query_string)
  result_hash = query.result
  # {
  #   "data" => {
  #     "post" => {
  #        "id" => 1,
  #        "title" => "GraphQL is nice"
  #     }
  #   }
  # }
  ```

  See also:
  - [query_spec.rb](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/graph_ql/query_spec.rb) for an example of query execution.
  -  [`queries_controller.rb`](https://github.com/rmosolgo/graphql-ruby-demo/blob/master/app/controllers/queries_controller.rb) for a Rails example
  - Try it on [heroku](http://graphql-ruby-demo.herokuapp.com)

## To Do:

- Validations:
{'fraction_non_alphanumeric': 0.17174721189591077, 'fraction_numerical': 0.01809169764560099, 'mean_word_length': 3.6767091541135573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 26, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3970550', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1493, 'n_words': 219}