Permalink
Browse files

Add HTTP Caching to Rails Server

  • Loading branch information...
kevinjalbert committed Jul 4, 2018
1 parent 0bf8d6b commit c3bcc3588012a9b4b22bd582c80de3e0dd208078
Showing with 5 additions and 1 deletion.
  1. +4 −1 rails-graphql/app/controllers/graphql_controller.rb
  2. +1 −0 rails-graphql/config/routes.rb
@@ -1,13 +1,16 @@
class GraphqlController < ApplicationController
def execute
expires_in(10.seconds, public: true)
variables = ensure_hash(params[:variables])
query = params[:query]
operation_name = params[:operationName]
if query.present?
result = RailsGraphqlSchema.execute(query, variables: variables, operation_name: operation_name)
else
signature = params.dig(:extensions, :persistedQuery, :sha256Hash)
extensions = JSON.parse(params[:extensions]) || {}
signature = extensions.dig("persistedQuery", "sha256Hash")
persisted_query = PersistedQuery.find_by!(signature: signature)
result = RailsGraphqlSchema.execute(persisted_query.query, variables: variables, operation_name: operation_name)
end
@@ -2,5 +2,6 @@
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
post "/graphql", to: "graphql#execute"
get "/graphql", to: "graphql#execute"
post "/graphql_persist", to: "graphql_persist#execute"
end

0 comments on commit c3bcc35

Please sign in to comment.