[英]How to wrap graphql.net endpoint response using asp.net core 2 middleware?
[英]How to generate dynamic path value for a graphql query response using GraphQL.NET?
我有以下響應的REST API( api / tax / v1 / countries )。 在下面的pngimagePath和svgimagePath屬性指向圖像類型端點( api / tax / v1 / country / Country1 / {FlagPNG或FlagSVG} )
在這種情況下,路徑是動態生成的。
{
"countries": [
{
"pngimagePath": "https://test.com/api/tax/v1/country/Country1/4/image/FlagPNG",
"svgimagePath": "https://test.com/api/tax/v1/country/Country1/405/image/FlagSVG",
"displayName": "Country1",
"displayNameShort": "Country1",
"providerName": "Testing",
"providerTerms": null,
"uuid": "1",
"name": "Country1",
"path": "Country1",
"completeResponse": true
},
{
"pngimagePath": "https://test.com/api/tax/v1/country/Country2/5/image/FlagPNG",
"svgimagePath": "https://test.com/api/tax/v1/country/Country2/406/image/FlagSVG",
"displayName": "Country2",
"displayNameShort": "Country2",
"providerName": "Testing one",
"providerTerms": null,
"uuid": "2",
"name": "Country2",
"path": "Country2",
"completeResponse": true
}
],
"authorised": false,
"userMessage": ""
}
// Code to generate the image path
var apiPath = _appSettings.Value.ApiPath + "country/";
result.Countries.AddRange(rawCountries.Select(country => new DTO.CountryDTO {
PNGImagePath = $"{apiPath}{Helper.ReplaceChars(country.DefaultDisplayName)}/{country.PngImageId}/image/{country.PngImageType}" , SVGImagePath = $"{apiPath}{Helper.ReplaceChars(country.DefaultDisplayName)}/{country.SvgImageId}/image/{country.SvgImageType}" , } ) ) ;
我想使用GraphQL.NET生成圖像路徑。
誰能幫我知道如何實現此功能
對於基於country
生成的pngimagePath
,您可以定義一個帶有resolve
的新字段,以生成pngimagePath
的值。
public class PlayerType : ObjectGraphType<Player>
{
public PlayerType(ISkaterStatisticRepository skaterStatisticRepository)
{
Field(x => x.Id);
Field(x => x.Name, true);
Field(x => x.BirthPlace);
Field(x => x.Height);
Field(x => x.WeightLbs);
Field<StringGraphType>("pngimagePath", resolve: context => $"{context.Source.Name} {context.Source.BirthDate} {context.Source.BirthPlace}");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.