public ColorQuery(IColorRepository colorRepository, ITranslationRepository translationRepository) { Field <TranslationType>( "translation", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "id", Description = "Category id" } ), resolve: context => translationRepository.GetTranslationAsync(context.GetArgument <int>("id")).Result ); Field <ColorType>( "color", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "id", Description = "Product id" } ), resolve: context => colorRepository.GetColorAsync(context.GetArgument <int>("id")).Result ); Field <ListGraphType <ColorType> >( "colors", resolve: context => colorRepository.ColorsAsync() ); }
public TranslationType(IColorRepository repo) { Field(x => x.Id).Description("Translation id."); Field(x => x.Language).Description("Language"); Field(x => x.Name, nullable: true).Description("Translation text."); Field <ColorType>( "color", resolve: context => repo.GetColorAsync(context.Source.ColorId).Result ); }
public async Task <IActionResult> GetColor([FromRoute] int id) { try { var color = await _colorRepository.GetColorAsync(id); if (color == null) { return(NotFound()); } var result = Mapper.Map <ColorDto>(color); return(Ok(result)); } catch (Exception e) { _logger.LogCritical($"GET {Route}/{id} - {e.GetType().Name} - {e.Message} - {e.StackTrace}"); return(StatusCode(500, "An error ocurred in server")); } }