Created
January 4, 2024 01:48
Xml retriever using GraphQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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