Skip to content

Commit

Permalink
Merge pull request #120 from artsy/submissions_index
Browse files Browse the repository at this point in the history
Adds graphiql to the dev server
  • Loading branch information
ashkan18 authored Nov 13, 2017
2 parents 346fc2e + efb2180 commit 378e439
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ gemini_gem_spec = { git: 'https://github.com/artsy/gemini_upload-rails.git', bra
gem 'gemini_upload-rails', gemini_gem_spec # for admins to upload images


gem 'graphql'
gem 'graphql' # A lovely API
gem 'graphiql-rails' # A lovely interface to the API

watt_gem_spec = { git: 'https://github.com/artsy/watt.git', branch: 'master' }
gem 'watt', watt_gem_spec # artsy bootstrap
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ GEM
futuroscope (0.1.11)
globalid (0.4.0)
activesupport (>= 4.2.0)
graphiql-rails (1.4.7)
rails
graphql (1.6.7)
haml (5.0.1)
temple (>= 0.8.0)
Expand Down Expand Up @@ -352,6 +354,7 @@ DEPENDENCIES
fabrication
foreman
gemini_upload-rails!
graphiql-rails
graphql
haml-rails
hyperclient
Expand Down
1 change: 0 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -c ${SIDEKIQ_CONCURRENCY:-5}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ easy as:
$ foreman start
```

See the Procfile for more.
See the Procfile to understand other services launched.

## API

When running in development, this API has a GraphiQL instance at http://localhost:5000/graphiql

## Creating a Submission

Expand Down
2 changes: 1 addition & 1 deletion app/graph/root_schema.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RootSchema = GraphQL::Schema.define do
query Queries::Root
query Types::QueryType
mutation Mutations::Root

max_depth 5
Expand Down
5 changes: 3 additions & 2 deletions app/graph/queries.rb → app/graph/types/query_type.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module Queries
Root = GraphQL::ObjectType.define do
module Types
QueryType = GraphQL::ObjectType.define do
name 'Query'
description 'Query root for this schema'
field :submission, types[Types::SubmissionType] do
description 'Find Submissions'
argument :ids, types[types.ID]
argument :id, types.ID

resolve ->(_object, args, _context) {
args[:ids] ? Submission.where(id: args[:ids]) : [Submission.find(args[:id])]
}
Expand Down
1 change: 1 addition & 0 deletions config/initializers/graphiql.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GraphiQL::Rails.config.headers['Authorization'] = ->(context) { "Bearer #{context.session[:access_token]}" }
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
post '/graphql', to: 'graphql#execute'
end

if Rails.env.development?
mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/api/graphql'
end

mount ArtsyAuth::Engine => '/'

require 'sidekiq/web'
Expand Down

0 comments on commit 378e439

Please sign in to comment.