Guest User

Untitled

a guest
Aug 10th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using EatMore.API.Models.GraphQL;
  2. using GraphQL.Types;
  3. using Microsoft.EntityFrameworkCore;
  4. using System;
  5. using System.Linq;
  6.  
  7. namespace EatMore.API.Query
  8. {
  9. public class EatMoreQuery : ObjectGraphType
  10. {
  11. public EatMoreQuery(AppContext db)
  12. {
  13. Field<RestaurantType>(
  14. "restaurant",
  15. arguments: new QueryArguments(
  16. new QueryArgument<IdGraphType> { Name = "id", Description = "The ID of the restaurant." }),
  17. resolve: context =>
  18. {
  19. var id = context.GetArgument<Guid?>("id");
  20. var restaurant = db
  21. .Restaurants
  22. .Include("Menus.MenuItems")
  23. .FirstOrDefault(i => i.Id == id);
  24. return restaurant;
  25. });
  26.  
  27. Field<ListGraphType<RestaurantType>>(
  28. "restaurants",
  29. resolve: context =>
  30. {
  31. var restaurants = db.Restaurants.Include("Menus.MenuItems");
  32. return restaurants;
  33. });
  34. }
  35. }
  36. }
Add Comment
Please, Sign In to add comment