34 lines
734 B
Crystal
34 lines
734 B
Crystal
require "toro"
|
|
require "json"
|
|
|
|
module Backend
|
|
module API
|
|
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
|
|
end
|