У меня есть существующий REST API, разработанный с использованием ASP.NET Web API2 (.Net Framework 4.6.2) со следующей базой кода:
// CountriesController.cs
public class CountriesController: BaseApiController {
private readonly ICountryService _countryService;
private readonly ICommonService _commonService;
private readonly IImageService _imageService;
public CountriesController(ICountryService countryService, ICommonService commonService, IImageService imageService) {
countryService = countryService;
commonService = commonService;
imageService = imageService;
}
// GET api/<controller>
[Route("countries")]
public IHttpActionResult Get() {
var resp = _countryService.GetAllCountries(locale);
return Ok(resp);
}
}
// CountryService.cs
public class CountryService: ICountryService {
private readonly ICommonService _commonService;
public CountryService(ICommonService commonService) {
_commonService = commonService;
}
public CountryResult GetAllCountries(string locale) {
CountryResult result = new CountryResult();
// Code to return the countryresult object
return result;
}
}
// Models
public class CountryResult: APIResult {
public CountryResult() {
Countries = new List < CountryDTO > ();
}
public List < CountryDTO > Countries {
get;
set;
}
}
public class CountryDTO {
[JsonProperty("pngimagePath")]
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string PNGImagePath {
get;
set;
}
[JsonProperty("svgimagePath")]
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string SVGImagePath {
get;
set;
}
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string DisplayName {
get;
set;
}
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string DisplayNameShort {
get;
set;
}
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string ProviderName {
get;
set;
}
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string ProviderTerms {
get;
set;
}
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string Uuid {
get;
set;
}
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string Name {
get;
set;
}
[RegularExpression(Constants.GeneralStringRegularExpression)]
public string Path {
get;
set;
}
public bool CompleteResponse {
get;
set;
}
}
public class APIResult {
public Locale Locale {
get;
set;
}
[JsonProperty("authorised")]
public bool Authorized {
get;
set;
}
public string UserMessage {
get;
set;
}
}
public class Locale {
public string LocalisationIdentifier {
get;
set;
}
public bool Enabled {
get;
set;
}
public string Language {
get;
set;
}
public string country {
get;
set;
}
public string Description {
get;
set;
}
public string Uuid {
get;
set;
}
public string Name {
get;
set;
}
public string Path {
get;
set;
}
public bool RightToLeft {
get;
set;
}
public bool CompleteResponse {
get;
set;
}
public string ScriptDirection {
get {
return RightToLeft ? "rtl" : "ltr";
}
}
public Locale() {}
}
Ответ API REST:
апи / налог / v1 / страны
{
"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
}
],
"locale": {
"localisationIdentifier": "en",
"enabled": true,
"language": "en",
"country": "",
"description": "English",
"uuid": "37",
"name": "English",
"path": "/locales/en",
"rightToLeft": false,
"completeResponse": true,
"scriptDirection": "ltr"
},
"authorised": false,
"userMessage": ""
}
Я хочу спроектировать модели, необходимые для типов graphql, на основе описанной выше настройки, сохранив ответ конечной точки grahpql таким же, как и существующий ответ API REST.
Может ли кто-нибудь помочь мне предоставить свои материалы для лучшего проектирования моделей graphql для этого сценария?