<%@ WebHandler Language="C#" Class="GraphQL" %> using System; using System.IO; using System.Web; using Newtonsoft.Json; using Newtonsoft.Json.Linq; public class GraphQL : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string body; using (var reader = new StreamReader(context.Request.InputStream)) { body = reader.ReadToEnd(); } var request = JObject.Parse(body); string query = request["query"]?.ToString(); string response = HandleQuery(query); context.Response.Write(response); } private string HandleQuery(string query) { if (query.Contains("users")) { var result = new { data = new { users = new[] { new { id = 1, name = "Max Mustermann", emails = new[] { new { address = "max.mustermann@example.com" }, new { address = "max.private@example.com" } } }, new { id = 2, name = "Erika Musterfrau", emails = new[] { new { address = "erika.musterfrau@example.com" } } }, new { id = 3, name = "John Doe", emails = new[] { new { address = "john.doe@example.com" }, new { address = "j.doe@company.com" }, new { address = "john.private@mail.com" } } } } } }; return JsonConvert.SerializeObject(result); } if (query.Contains("gba")) { var result = new { data = new { gba = new[] { new { name = "Grundbuchamt Thurgau", canton = "TG", street = "Testweg 2", postal_code = "8750", city = "Weinfelden", cuntry = "CH" }, new { name = "Grundbuchamt Z\u00FCrich", canton = "ZH", street = "Schipfe 12", postal_code = "8001", city = "Z\u00FCrich", cuntry = "CH" }, new { name = "Grundbuchamt Hintertr\u00FCmlkon", canton = "AG", street = "Waldweg 1", postal_code = "5000", city = "Aarau", cuntry = "CH" }, } } }; return JsonConvert.SerializeObject(result); } return JsonConvert.SerializeObject(new { errors = new[] { new { message = "Unknown mock query" } } }); } public bool IsReusable => false; }