Example #1
0
        public GraphQLQueries(OrderRepository orderRepository,
                              OrderItemRepository orderItemRepository)
        {

            #region Order

            Field<ListGraphType<OrderType>>(
               "orders",
               resolve: context => orderRepository.GetAll());

            Field<OrderType>(
                "order",
                arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>>
                { Name = "id" }),
                resolve: context =>
                {
                    var id = context.GetArgument<int>("id");
                    return orderRepository.GetOne(id);

                });


            #endregion


            #region OrderItems

            Field<ListGraphType<OrderItemType>>(
                "orderItems",
                resolve: context => orderItemRepository.GetAll());

            Field<OrderItemType>(
                "orderItemsForOrder",
                arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>>
                { Name = "id" }),
                resolve: context =>
                {
                    var id = context.GetArgument<int>("id");
                    return orderItemRepository.GetForOrder(id);

                });



            #endregion

        }