Skip to content

WIP: Add ruby-graphql #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
.byebug_history
.idea/
public/
node_modules/
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ gem 'devise_token_auth'
gem 'cancan'
gem 'rolify'
gem 'pry'
gem 'graphql'
gem 'graphiql-rails', group: :development
gem 'batch-loader'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand All @@ -48,6 +51,3 @@ group :development do
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
108 changes: 58 additions & 50 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.0.2)
actionpack (= 5.0.2)
actioncable (5.0.6)
actionpack (= 5.0.6)
nio4r (>= 1.2, < 3.0)
websocket-driver (~> 0.6.1)
actionmailer (5.0.2)
actionpack (= 5.0.2)
actionview (= 5.0.2)
activejob (= 5.0.2)
actionmailer (5.0.6)
actionpack (= 5.0.6)
actionview (= 5.0.6)
activejob (= 5.0.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.0.2)
actionview (= 5.0.2)
activesupport (= 5.0.2)
actionpack (5.0.6)
actionview (= 5.0.6)
activesupport (= 5.0.6)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.0.2)
activesupport (= 5.0.2)
actionview (5.0.6)
activesupport (= 5.0.6)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.0.2)
activesupport (= 5.0.2)
activejob (5.0.6)
activesupport (= 5.0.6)
globalid (>= 0.3.6)
activemodel (5.0.2)
activesupport (= 5.0.2)
activerecord (5.0.2)
activemodel (= 5.0.2)
activesupport (= 5.0.2)
activemodel (5.0.6)
activesupport (= 5.0.6)
activerecord (5.0.6)
activemodel (= 5.0.6)
activesupport (= 5.0.6)
arel (~> 7.0)
activesupport (5.0.2)
activesupport (5.0.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (7.1.4)
batch-loader (1.0.3)
bcrypt (3.1.11)
builder (3.2.3)
byebug (9.0.6)
cancan (1.6.10)
coderay (1.1.1)
concurrent-ruby (1.0.5)
crass (1.0.2)
devise (4.2.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand All @@ -63,64 +65,68 @@ GEM
ffi (1.9.18)
foreman (0.82.0)
thor (~> 0.19.1)
globalid (0.3.7)
activesupport (>= 4.1.0)
i18n (0.8.1)
globalid (0.4.0)
activesupport (>= 4.2.0)
graphiql-rails (1.4.4)
rails
graphql (1.7.3)
i18n (0.8.6)
jsonapi-resources (0.9.0)
activerecord (>= 4.1)
concurrent-ruby
railties (>= 4.1)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
loofah (2.0.3)
loofah (2.1.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.6.4)
mail (2.6.6)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.1)
nio4r (2.0.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
mini_portile2 (2.3.0)
minitest (5.10.3)
nio4r (2.1.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
pg (0.20.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
puma (3.8.2)
rack (2.0.1)
rack (2.0.3)
rack-cors (0.4.1)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.2)
actioncable (= 5.0.2)
actionmailer (= 5.0.2)
actionpack (= 5.0.2)
actionview (= 5.0.2)
activejob (= 5.0.2)
activemodel (= 5.0.2)
activerecord (= 5.0.2)
activesupport (= 5.0.2)
bundler (>= 1.3.0, < 2.0)
railties (= 5.0.2)
rails (5.0.6)
actioncable (= 5.0.6)
actionmailer (= 5.0.6)
actionpack (= 5.0.6)
actionview (= 5.0.6)
activejob (= 5.0.6)
activemodel (= 5.0.6)
activerecord (= 5.0.6)
activesupport (= 5.0.6)
bundler (>= 1.3.0)
railties (= 5.0.6)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.2)
activesupport (>= 4.2.0, < 6.0)
nokogiri (~> 1.6)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.0.2)
actionpack (= 5.0.2)
activesupport (= 5.0.2)
railties (5.0.6)
actionpack (= 5.0.6)
activesupport (= 5.0.6)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.0.0)
rake (12.1.0)
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
Expand Down Expand Up @@ -153,7 +159,7 @@ GEM
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
Expand All @@ -171,12 +177,15 @@ PLATFORMS
ruby

DEPENDENCIES
batch-loader
byebug
cancan
devise_token_auth
factory_girl
faker
foreman
graphiql-rails
graphql
jsonapi-resources
listen (~> 3.0.5)
pg (~> 0.18)
Expand All @@ -188,7 +197,6 @@ DEPENDENCIES
rspec-rails
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data

BUNDLED WITH
1.14.6
137 changes: 137 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,140 @@ Demo user: [email protected] / Secret123
### Client

Add list, edit and form components in `client/src/components/` based on one of existing.

### [graphiql](http://localhost:3001/graphiql)

Categories

{
categories {
id
name
}
}

Categories with posts

{
categories(with_posts: true) {
id
name
posts {
id
title
category {
id
name
}
comments {
id
body
}
}
}
}

One category

{
category(id: 1) {
id
name
}
}

Create category

mutation {
createCategory(category: {name: "Graphql"}) {
id
name
errors
}
}

Update category

mutation {
updateCategory(category: {id: 1, name: "Graphql"}) {
id
name
errors
}
}

Delete category

mutation {
deleteCategory(id: 24) {
id
name
}
}

Posts

{
posts {
id
title
category {
id
name
}
}
}

One post

{
post(id: 1) {
id
title
category {
id
name
}
comments {
id
body
}
}
}

Create post

mutation {
createPost(post: {title: "Graphql", category_id: 1}) {
id
title
category {
id
name
}
errors
}
}

Update post

mutation {
updatePost(post: {id: 1, title: "Graphql", category_id: 1}) {
id
title
category {
id
name
}
errors
}
}

Delete post

mutation {
deletePost(id: 83) {
id
title
}
}
32 changes: 32 additions & 0 deletions app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class GraphqlController < ApplicationController
def execute
variables = ensure_hash(params[:variables])
query = params[:query]
context = {
# Query context goes here, for example:
# current_user: current_user,
}
result = RailsJsonApiServerSchema.execute(query, variables: variables, context: context)
render json: result
end

private

# Handle form data, JSON body, or a blank value
def ensure_hash(ambiguous_param)
case ambiguous_param
when String
if ambiguous_param.present?
ensure_hash(JSON.parse(ambiguous_param))
else
{}
end
when Hash, ActionController::Parameters
ambiguous_param
when nil
{}
else
raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
end
end
end
Empty file added app/graphql/mutations/.keep
Empty file.
Loading