public InventoryMutation(IMockDataSource mockDataSource) { Field <SellableItemType>(name: "createInventoryItem", description: "Create inventoryitems", arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <SellableItemInputType> >() { Name = "newItem" } ), resolve: fieldContext => { var newSellableItem = fieldContext.GetArgument <SellableItem>("newItem"); return(mockDataSource.AddSellableItem(newSellableItem)); }); Field <CustomCustomerType>(name: "createCustomCustomer", arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <CustomCustomerInputType> >() { Name = "newCustomer" } ), resolve: fieldContext => { var newCustomer = fieldContext.GetArgument <CustomCustomer>("newCustomer"); return(mockDataSource.AddCustomCustomerAsync(newCustomer)); }); Field <CustomOrderType>(name: "createCustomOrder", arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <CustomOrderInputType> >() { Name = "newOrder" } ), resolve: fieldContext => { var newOrder = fieldContext.GetArgument <CustomOrder>("newOrder"); return(mockDataSource.AddCustomOrderAsync(newOrder)); }); Field <CustomOrderSellableItemRelationType>(name: "addCustomOrderSellableItemRelation" , arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <CustomOrderSellableItemRelationInputType> >() { Name = "customOrderSellableItemRelation" , DefaultValue = "input the relation of customOrder and sellableItem" } ), resolve: fieldContext => { var newOrderAndSellableItemRelation = fieldContext.GetArgument <CustomOrderSellableItemRelation>("customOrderSellableItemRelation"); return(mockDataSource.AddCustomOrderSellableItemRelationAsync(newOrderAndSellableItemRelation)); } ); }
public CustomCustomerType(IMockDataSource mockDataSource) { Field(c => c.Name); Field(c => c.BillingAddress); /*!!!!请问此处的CustomOrderType泛型参数类型有何意义?*/ Field <ListGraphType <CustomOrderType>, IEnumerable <CustomOrder> >() .Name("CustomOrders") .ResolveAsync(fieldContext => { return(mockDataSource.GetOrdersByCustomCustomerIdAsync(fieldContext.Source.CustomerId)); }); }
public CustomOrderSellableItemRelationType(IMockDataSource mockDataSource) { Field(r => r.Barcode); Field <SellableItemType, SellableItem>() .Name("SellableItem") .Resolve(fieldContext => { return(mockDataSource.GetSellableItemByBarcode(fieldContext.Source.Barcode)); }); Field(r => r.Quantity); Field(r => r.OrderId); Field <CustomOrderType, CustomOrder>() .Name("CustomOrder") .ResolveAsync(fieldContext => { return(mockDataSource.GetCustomOrderByIdAsync(fieldContext.Source.OrderId)); }); }
public InventoryQuery(ApplicationDbContext applicationDbContext, IMockDataSource mockDataSource) { Field <SellableItemType>(name: "inventoryItem", description: "Search inventoryitems", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "barcode" }), resolve: fieldContext => { var strBarcodeArg = fieldContext.GetArgument <string>("barcode"); return(new MockDataSource(applicationDbContext).GetSellableItemByBarcode(strBarcodeArg)); }); /*查询示例(感觉GraphQL查询比较方便,可用Mutation增加数据但操作步骤多。) * query testGraphQLInNET($barcode: String!){ * inventoryItem (barcode: $barcode){ * sellingPrice * title * } * } * * mutation { * createInventoryItem(newItem: {title: "GPU", barcode: "112", sellingPrice: 3.55555}){ * title * barcode * } * } */ Field <ListGraphType <CustomCustomerType>, IEnumerable <CustomCustomer> >() .Name("AllCustomers") .ResolveAsync(fieldContext => { return(mockDataSource.GetCustomCustomersAsync()); }); Field <ListGraphType <CustomOrderType>, IEnumerable <CustomOrder> >() .Name("AllOrders") .ResolveAsync(fieldContext => { return(mockDataSource.GetCustomOrdersAsync()); }); }
public CustomOrderType(IMockDataSource mockDataSource) { Field(o => o.Tag); Field(o => o.CreateAt); /*!!!!请问此处的CustomCustomerType泛型参数类型有何意义?*/ Field <CustomCustomerType, CustomCustomer>() .Name("CustomCustomer") .ResolveAsync(fieldContext => { return(mockDataSource.GetCustomCustomerByIdAsync(fieldContext.Source.CustomerId)); }); Field <CustomOrderSellableItemRelationType, IEnumerable <CustomOrderSellableItemRelation> >() .Name("AllOrderSellableItemRelations") .ResolveAsync(fieldContext => { return(mockDataSource.GetCustomOrderSellableItemRelationByOrderIdAsync(fieldContext.Source.OrderId)); }); }