From ab333d6627ae780990ceb750bb99136994487e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Miedes=20Garc=C3=A9s?= Date: Wed, 28 Sep 2016 12:47:07 +0200 Subject: [PATCH] Created controller and route to answer GraphQL queries --- app/controllers/graphql_controller.rb | 11 +++++++++++ config/routes.rb | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 app/controllers/graphql_controller.rb diff --git a/app/controllers/graphql_controller.rb b/app/controllers/graphql_controller.rb new file mode 100644 index 000000000..11accf52a --- /dev/null +++ b/app/controllers/graphql_controller.rb @@ -0,0 +1,11 @@ +class GraphqlController < ApplicationController + + def query + #puts "I'm the GraphqlController inside the #query action!!" + + render json: ConsulSchema.execute( + params[:query], + variables: params[:variables] || {} + ) + end +end diff --git a/config/routes.rb b/config/routes.rb index df1a7c6fb..b86cb0c30 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -262,6 +262,11 @@ Rails.application.routes.draw do end end + # GraphQL + mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/queries" + post '/queries', to: 'graphql#query' + + if Rails.env.development? mount LetterOpenerWeb::Engine, at: "/letter_opener" end