Skip to content

Instantly share code, notes, and snippets.

@navancommits
Created January 4, 2024 01:48
Xml retriever using GraphQL
public class CustomGraphQlSitemapXmlServiceHandler : CustomGraphQlLayoutBaseServiceHandler<XmlResult>
{
private readonly IGraphQLRequestBuilder _graphQLRequestBuilder;
private readonly IGraphQLClientFactory _graphQLClientFactory;
private readonly MvpSiteSettings _configuration;
private Task<List<XmlResult>> result;
public CustomGraphQlSitemapXmlServiceHandler(IConfiguration configuration, IGraphQLRequestBuilder graphQLRequestBuilder, IGraphQLClientFactory graphQLClientFactory)
{
_graphQLRequestBuilder = graphQLRequestBuilder;
_graphQLClientFactory = graphQLClientFactory;
_configuration = configuration.GetSection(MvpSiteSettings.Key).Get<MvpSiteSettings>();
}
public async override Task<List<XmlResult>> GetSitemap()
{
var client = _graphQLClientFactory.CreateGraphQlClient();
var query = Constants.GraphQlQueries.GetSitemapSearchQuery;
var variables = (object)new
{
itemId = _configuration.SitemapXmlItemId,
language = _configuration.DefaultLanguage
};
var request = _graphQLRequestBuilder.BuildRequest(query, variables);
var graphQlResponse = await client.SendQueryAsync<SitemapXmlData>(request);
return graphQlResponse.Data.Search.Results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment