0

I have REST API (api/tax/v1/countries) with the following response. In the below the pngimagePath and svgimagePath properties are pointing to the image type endpoints(api/tax/v1/country/Country1/{FlagPNG or FlagSVG})

The paths are generated dynamically in this case.

{
  "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}" ,  } ) ) ; 

I want to generate the image path using GraphQL.NET.

Can anyone help me to know how to implement this feature

2
  • What do you mean by generate image path? Does api/tax/v1/countries call GraphQL.NET? Have you used GraphQL.NET or you want to migrate web api to it? Commented Nov 28, 2018 at 2:14
  • I am in the process of migrating the existing REST APIs to GraphQL endpoint using GraphQL.NET. In the existing response as mentioned in my query there is "pngimagePath": "test.com/api/tax/v1/country/Country1/4/image/FlagPNG" and "svgimagePath": "test.com/api/tax/v1/country/Country1/405/image/FlagSVG". As part of the graphql response for this query I also need to expose these properties also. Can you please help me to know how to accomplish this implementation Commented Nov 28, 2018 at 7:02

1 Answer 1

1

For pngimagePath which is generated based on country, you could define a new field with resolve to generate the value for 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}");
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks much for your inputs :). It helped me a lot. I will implement it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.