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 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()); }
public IngredientType(Core.Data.IIngredientRepository ingredientRepository, IMapper mapper) { Name = "Ingredient"; Description = "An ingredient for creating a beer recipe."; Field(x => x.Id).Description("The Id of the ingredient."); Field(x => x.Name, nullable: true).Description("The name of the ingredient."); Field(x => x.BeerRecipeId, nullable: true).Description("The beer recipe id this ingredient is associated with."); Field(d => d.Quantity, nullable: true).Description("The quantity of the ingredient."); Field(d => d.QuantityUnit, nullable: true).Description("The unit type of the quantity. Ex. gram."); Field <ListGraphType <IngredientInterface> >( "ingredient", resolve: context => { var ingredient = ingredientRepository.GetIngredient(int.Parse(context.Source.Name)).Result; return(ingredient); } ); Interface <IngredientInterface>(); }