Created
November 26, 2016 14:24
-
-
Save nickpoorman/41d431a9be23838a1d9bba5f5f83dfdb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# app/controllers/graphql_controller.rb | |
class GraphqlController < ApplicationController | |
def create | |
query_string = params[:query] | |
query_variables = ensure_hash(params[:variables]) | |
context = { current_user: current_user, pundit: self } | |
result = ApplicationSchema.execute(query_string, variables: query_variables, context: context) | |
render json: result | |
end | |
private | |
def ensure_hash(query_variables) | |
if query_variables.blank? || query_variables == 'null' | |
{} | |
elsif query_variables.is_a?(String) | |
JSON.parse(query_variables) | |
else | |
query_variables | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment