public BeerRecipeType(Core.Data.IBeerRecipeRepository beerRepository, Core.Data.IIngredientRepository ingredientRepository, IMapper mapper) { Name = "BeerRecipe"; Description = "A recipe that contains ingredients for making a beer."; Field(x => x.Id).Description("The Id of the beer recipe."); Field(x => x.Name, nullable: true).Description("The name of the beer recipe."); Field <ListGraphType <IngredientType> >("ingredients", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "id" }), resolve: context => ingredientRepository.Get(int.Parse(context.Source.Id)), description: "Ingredients associated to the recipe."); //Field<ListGraphType<IngredientInterface>>( // "ingredients", // resolve: context => // { // var ingredients = beerRepository.GetIngredients(int.Parse(context.Source.Id)).Result; // var mapped = mapper.Map<ICollection<Ingredient>>(ingredients); // return mapped; // } //); Field <ListGraphType <BeerRecipeInterface> >( "beerRecipe", resolve: context => { var beerRecipe = beerRepository.GetBeerRecipe(int.Parse(context.Source.Id)).Result; return(beerRecipe); } ); Interface <BeerRecipeInterface>(); }
public BeerRecipesMutation(Core.Data.IBeerRecipeRepository beerRecipeRepository) { Name = "Mutation"; Field <BeerRecipeType>( "createBeerRecipe", arguments: new QueryArguments( new QueryArgument <BeerRecipeInputType> { Name = "beerRecipe", Description = "The name of the beer recipe." } ), resolve: context => { var beerRecipe = context.GetArgument <Core.Models.BeerRecipe>("beerRecipe"); return(beerRecipeRepository.Add(beerRecipe)); }); }
public BeerRecipesQuery(Core.Data.IBeerRecipeRepository beerRepository, Core.Data.IIngredientRepository ingredientRepository, IMapper mapper) { Name = "Query"; Field <ListGraphType <BeerRecipeType> >( "beerRecipes", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "name", Description = "name of the beer recipe" } ), resolve: context => { var name = context.GetArgument <string>("name"); var beerRecipes = beerRepository.GetBeerRecipes(name).Result; var mapped = mapper.Map <ICollection <BeerRecipe> >(beerRecipes); return(mapped); } ); Field <ListGraphType <BeerRecipeType> >( "allBeerRecipes", resolve: context => beerRepository.GetAll()); Field <ListGraphType <IngredientType> >( "ingredients", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "name", Description = "name of the ingredient" } ), resolve: context => { var name = context.GetArgument <string>("name"); var ingredients = ingredientRepository.GetIngredients(name).Result; var mapped = mapper.Map <ICollection <Ingredient> >(ingredients); return(mapped); } ); Field <ListGraphType <IngredientType> >( "getAllIngredients", resolve: context => ingredientRepository.GetAll()); }