-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |