Exemplo n.º 1
0
    public string Render()
    {
        if (_graphiQLCSHtml == null)
        {
            using var manifestResourceStream = _options.IndexStream(_options);
            using var streamReader           = new StreamReader(manifestResourceStream);

            var headers = new Dictionary <string, object>
            {
                ["Accept"]       = "application/json",
                ["Content-Type"] = "application/json",
            };

            if (_options.Headers?.Count > 0)
            {
                foreach (var item in _options.Headers)
                {
                    headers[item.Key] = item.Value;
                }
            }

            var builder = new StringBuilder(streamReader.ReadToEnd())
                          .Replace("@Model.GraphQLEndPoint", _options.GraphQLEndPoint)
                          .Replace("@Model.SubscriptionsEndPoint", _options.SubscriptionsEndPoint)
                          .Replace("@Model.Headers", JsonSerializer.Serialize <object>(headers))
                          .Replace("@Model.HeaderEditorEnabled", _options.HeaderEditorEnabled ? "true" : "false")
                          .Replace("@Model.GraphiQLElement", _options.ExplorerExtensionEnabled ? "GraphiQLWithExtensions.GraphiQLWithExtensions" : "GraphiQL");

            _graphiQLCSHtml = _options.PostConfigure(_options, builder.ToString());
        }

        return(_graphiQLCSHtml);
    }