Skip to content

Commit

Permalink
Add wrong mutation type
Browse files Browse the repository at this point in the history
  • Loading branch information
cpunion committed Apr 4, 2017
1 parent c3c7fa1 commit e94dc76
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ gem 'jbuilder', '~> 2.5'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'graphql'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand All @@ -47,7 +48,10 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'graphiql-rails'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'graphiql-rails', group: :development
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ GEM
ffi (1.9.18)
globalid (0.3.7)
activesupport (>= 4.1.0)
graphiql-rails (1.4.1)
rails
graphql (1.5.5)
i18n (0.8.1)
jbuilder (2.6.3)
activesupport (>= 3.0.0, < 5.2)
Expand Down Expand Up @@ -156,6 +159,8 @@ PLATFORMS
DEPENDENCIES
byebug
coffee-rails (~> 4.2)
graphiql-rails
graphql
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
Expand Down
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 = ReproduceGraphqlHangSchema.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.
12 changes: 12 additions & 0 deletions app/graphql/mutations/create_post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Mutations::CreatePost = GraphQL::Relay::Mutation.define do
name "CreatePost"
# TODO: define return fields
# return_field :post, Types::PostType

# TODO: define arguments
# input_field :name, !types.String

resolve ->(obj, args, ctx) {
# TODO: define resolve function
}
end
4 changes: 4 additions & 0 deletions app/graphql/reproduce_graphql_hang_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ReproduceGraphqlHangSchema = GraphQL::Schema.define do
query(Types::QueryType)
mutation(Types::MutationType)
end
Empty file added app/graphql/types/.keep
Empty file.
5 changes: 5 additions & 0 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Types::MutationType = GraphQL::ObjectType.define do
name 'Mutation'

field :createPost, field: Mutations::CreatePost
end
13 changes: 13 additions & 0 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Types::QueryType = GraphQL::ObjectType.define do
name "Query"
# Add root-level fields here.
# They will be entry points for queries on your schema.

# TODO: remove me
field :testField, types.String do
description "An example field added by the generator"
resolve ->(obj, args, ctx) {
"Hello World!"
}
end
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Rails.application.routes.draw do
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
end

post "/graphql", to: "graphql#execute"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

0 comments on commit e94dc76

Please sign in to comment.