mentorenwahl/docker/backend/src/mw/server.cr
2022-01-08 13:29:22 +01:00

32 lines
666 B
Crystal

require "toro"
require "json"
module MW
class Server < Toro::Router
private struct GraphQLData
include JSON::Serializable
property query : String
property variables : Hash(String, JSON::Any)?
property operation_name : String?
end
def routes
on "graphql" do
post do
content_type "application/json"
data = GraphQLData.from_json(context.request.body.not_nil!.gets.not_nil!)
write Schema::SCHEMA.execute(
data.query,
data.variables,
data.operation_name,
Context.new(context.request)
)
end
end
end
end
end