Sha256: a6a3ee44317089e9c4b1e5442dfb256c9a473904821db61292c0901b2ab25fbe
Contents?: true
Size: 1.27 KB
Versions: 13
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true require 'rackup' require 'json' require 'graphql' require_relative '../../lib/graphql/stitching' require_relative '../../test/schemas/example' class StitchedApp def initialize file = File.open("#{__dir__}/graphiql.html") @graphiql = file.read file.close @client = GraphQL::Stitching::Client.new(locations: { products: { schema: Schemas::Example::Products, }, storefronts: { schema: Schemas::Example::Storefronts, executable: GraphQL::Stitching::HttpExecutable.new(url: "http://localhost:3001"), }, manufacturers: { schema: Schemas::Example::Manufacturers, executable: GraphQL::Stitching::HttpExecutable.new(url: "http://localhost:3002"), } }) end def call(env) req = Rack::Request.new(env) case req.path_info when /graphql/ params = JSON.parse(req.body.read) result = @client.execute( query: params["query"], variables: params["variables"], operation_name: params["operationName"], ) [200, {"content-type" => "application/json"}, [JSON.generate(result)]] else [200, {"content-type" => "text/html"}, [@graphiql]] end end end Rackup::Handler.default.run(StitchedApp.new, :Port => 3000)
Version data entries
13 entries across 13 versions & 1 rubygems