Skip to content

Commit

Permalink
Add endpoint for GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
davydovanton committed Jul 27, 2017
1 parent 38b3716 commit 4099d23
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
1 change: 1 addition & 0 deletions apps/api/config/routes.rb
@@ -1 +1,2 @@
get '/graphql', to: 'graphql#index'
resources :contributors, only: %i[index show]
9 changes: 9 additions & 0 deletions apps/api/controllers/graphql/index.rb
@@ -0,0 +1,9 @@
module Api::Controllers::Graphql
class Index
include Api::Action

def call(params)
self.body = Graphql::Schema.execute(params[:query]).to_json
end
end
end
1 change: 0 additions & 1 deletion config.ru
Expand Up @@ -16,5 +16,4 @@ map '/sidekiq' do
run Sidekiq::Web
end


run Hanami.app
36 changes: 0 additions & 36 deletions lib/graphql/schema.rb
Expand Up @@ -3,39 +3,3 @@ module Graphql
query Types::Query
end
end

# query_all = <<-QUERY
# {
# contributors {
# id
# github
# full_name
# avatar_url
# }
# }
# QUERY
#
# Graphql::Schema.execute(query_all)
# # => [{"data"=>{"contributor"=>{"id"=>"101", "github"=>"jodosha", "full_name"=>nil, "avatar_url"=>"https://avatars2.githubusercontent.com/u/5089?v=3"}}}, ...]

# query_first = <<-QUERY
# {
# contributor(id: "301") {
# id
# github
# full_name
# avatar_url
#
# commits {
# url
#
# project {
# name
# }
# }
# }
# }
# QUERY
#
# Graphql::Schema.execute(query_first)
# => {"data"=>{"contributor"=>{"id"=>"301", "github"=>"janx", "full_name"=>nil, "avatar_url"=>"https://avatars3.githubusercontent.com/u/5958?v=3", "commits"=>[{"url"=>"https://github.com/hanami/view/commit/3e94750830a9905390dc823ff91f5ccd485d99ea"}]}}}
11 changes: 11 additions & 0 deletions spec/api/controllers/graphql/index_spec.rb
@@ -0,0 +1,11 @@
require_relative '../../../../apps/api/controllers/graphql/index'

RSpec.describe Api::Controllers::Graphql::Index do
let(:action) { described_class.new }
let(:params) { Hash[] }

it 'is successful' do
response = action.call(params)
expect(response[0]).to eq 200
end
end

0 comments on commit 4099d23

Please sign in to comment.