public void AddGraphTypeFields(MutationCore mutationCore)
        {
            mutationCore.FieldAsync <StringGraphType>(name: "blog",
                                                      description: null,
                                                      arguments: new QueryArguments(new QueryArgument <BlogMutationInput> {
                Name = "input"
            }),
                                                      resolve: async context =>
            {
                try
                {
                    var userContext = context.UserContext.As <GraphQLUserContext>();
                    var blog        = context.GetArgument <SimpleDocument <Blog> >("input");

                    blog.TenantId = await _blogStore.GetTenantIdAsync();
                    await _blogStore.InsertAsync(blog);
                    return(true);
                }
                catch (Exception e)
                {
                }
                return(false);
                //                    return await Task.Run(() => { return ""; });
            },
                                                      deprecationReason: null
                                                      );
        }
Esempio n. 2
0
 public void AddGraphTypeFields(MutationCore mutationCore)
 {
     mutationCore.FieldAsync <HumanType>(name: "createHuman",
                                         description: null,
                                         arguments: new QueryArguments(
                                             new QueryArgument <NonNullGraphType <HumanInputType> > {
         Name = "human"
     }
                                             ),
                                         resolve: async context =>
     {
         try
         {
             var userContext = context.UserContext.As <GraphQLUserContext>();
             var human       = context.GetArgument <Human>("human");
             return(_starWarsData.AddHuman(human));
         }
         catch (Exception e)
         {
         }
         return(false);
         //                    return await Task.Run(() => { return ""; });
     },
                                         deprecationReason: null
                                         );
 }
Esempio n. 3
0
        public void AddGraphTypeFields(MutationCore mutationCore)
        {
            mutationCore.FieldAsync <PublishStateResultType>(name: "publishState",
                                                             description: null,
                                                             arguments: new QueryArguments(new QueryArgument <PublishStateInputType> {
                Name = "input"
            }),
                                                             resolve: async context =>
            {
                // Authorization worked, but who is calling us
                var graphQLUserContext = context.UserContext as GraphQLUserContext;
                var principal          = graphQLUserContext.HttpContextAccessor.HttpContext.User;

                // Since this is a B2B api, there probably will not be a subject, hence no real user
                // What we have here is an organization, so we have to find out the clientId, and the client_namespace

                var authContext = principal.ToAuthContext();

                var requestedFields = (from item in context.SubFields
                                       select item.Key).ToList();

                var input = context.GetArgument <PublishStateModel>("input");

                var result = await _b2BPublisherStore.PublishStateAsync(
                    authContext, new Contracts.Models.RequestedFields
                {
                    Fields = requestedFields
                },
                    input);
                return(result);
            },
                                                             deprecationReason: null
                                                             );
        }
Esempio n. 4
0
 public void AddGraphTypeFields(MutationCore mutationCore)
 {
     /*(
      * mutationCore.FieldAsync<StringGraphType>(name: "someRandomMutation",
      *  description: null,
      *  arguments: new QueryArguments(new QueryArgument<StringGraphType> { Name = "id" }),
      *  resolve: async context =>
      *  {
      *      try
      *      {
      *          var userContext = context.UserContext.As<GraphQLUserContext>();
      *          var id = context.GetArgument<string>("id");
      *
      *          return true;
      *      }
      *      catch (Exception e)
      *      {
      *
      *      }
      *      return false;
      *      //                    return await Task.Run(() => { return ""; });
      *
      *  },
      *  deprecationReason: null
      * );
      */
 }
 public void AddGraphTypeFields(MutationCore mutationCore)
 {
     mutationCore.FieldAsync <CustomerType>(name: "upsertCustomer",
                                            description: null,
                                            arguments: new QueryArguments(new QueryArgument <NonNullGraphType <CustomerCreateInputType> > {
         Name = "input"
     }),
                                            resolve: async context =>
     {
         var input    = context.GetArgument <CustomerCreateInput>("input");
         var customer = new CustomerManagementStore.Model.Customer
         {
             Id              = input.Id,
             Name            = input.Name,
             Address         = input.Address,
             City            = input.City,
             EmailAddress    = input.EmailAddress,
             PostalCode      = input.PostalCode,
             TelephoneNumber = input.TelephoneNumber
         };
         var result = await _customerManagmentStore.UpsertCustomerAsync(customer);
         return(result);
     }
                                            );
 }
 public void AddGraphTypeFields(MutationCore mutationCore)
 {
     mutationCore.FieldAsync <BooleanGraphType>(name: "__placeHolder",
                                                description: "This is here so we have at least one mutation",
                                                resolve: async context => true,
                                                deprecationReason: null
                                                );
 }
Esempio n. 7
0
        public void AddGraphTypeFields(MutationCore mutationCore)
        {
            mutationCore.FieldAsync <DogType>(name: "mutateDog",
                                              description: null,
                                              arguments: new QueryArguments(new QueryArgument <NonNullGraphType <DogInputType> > {
                Name = "dog"
            }),
                                              resolve: async context =>
            {
                var dogInput = context.GetArgument <DogInput>("dog");

                _dogStore.Name = dogInput.Name;
                return(new Dog()
                {
                    Name = _dogStore.Name
                });
            }
                                              );
        }
 public void AddGraphTypeFields(MutationCore mutationCore)
 {
     mutationCore.FieldAsync <LoyaltyPointsTransferType>(name: "loyaltyPointsTransfer",
                                                         description: null,
                                                         arguments: new QueryArguments(new QueryArgument <LoyaltyPointsTransferMutationInput> {
         Name = "input"
     }),
                                                         resolve: async context =>
     {
         var loyaltyPointsTransfer = context.GetArgument <LoyaltyPointsTransfer>("input");
         var userContext           = context.UserContext.As <GraphQLUserContext>();
         var result = await _customerLoyaltyStore.TransferLoyaltyPointsAsync(
             loyaltyPointsTransfer.SenderId,
             loyaltyPointsTransfer.ReceiverId,
             loyaltyPointsTransfer.Points);
         return(result);
     },
                                                         deprecationReason: null
                                                         );
 }
Esempio n. 9
0
 public void AddGraphTypeFields(MutationCore mutationCore)
 {
     mutationCore.FieldAsync <CustomerResultType>(name: "customer",
                                                  description: null,
                                                  arguments: new QueryArguments(new QueryArgument <CustomerMutationInput> {
         Name = "input"
     }),
                                                  resolve: async context =>
     {
         var customer    = context.GetArgument <Customer>("input");
         var userContext = context.UserContext.As <GraphQLUserContext>();
         customer        = await _customerLoyaltyStore.DepositEarnedLoyaltyPointsAsync(customer.ID,
                                                                                       customer.LoyaltyPointBalance);
         return(new CustomerResult()
         {
             ID = customer.ID,
             LoyaltyPointBalance = customer.LoyaltyPointBalance
         });
     },
                                                  deprecationReason: null
                                                  );
 }
Esempio n. 10
0
        public void AddGraphTypeFields(MutationCore mutationCore)
        {
            mutationCore.FieldAsync <OrderType>(name: "createOrder",
                                                description: null,
                                                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <OrderCreateInputType> > {
                Name = "order"
            }),
                                                resolve: async context =>
            {
                var orderInput = context.GetArgument <OrderCreateInput>("order");

                var id    = Guid.NewGuid().ToString();
                var order = new Order(orderInput.Name, orderInput.Description, orderInput.Created, orderInput.CustomerId, id);
                return(await _orders.CreateAsync(order));
            }
                                                );
            mutationCore.FieldAsync <OrderType>(
                "startOrder",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "orderId"
            }),
                resolve: async context =>
            {
                var orderId = context.GetArgument <string>("orderId");
                return(await context.TryAsyncResolve(
                           async c => await _orders.StartAsync(orderId)));
            }
                );

            mutationCore.FieldAsync <OrderType>(
                "completeOrder",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "orderId"
            }),
                resolve: async context =>
            {
                var orderId = context.GetArgument <string>("orderId");
                return(await context.TryAsyncResolve(
                           async c => await _orders.CompleteAsync(orderId)));
            }
                );

            mutationCore.FieldAsync <OrderType>(
                "cancelOrder",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "orderId"
            }),
                resolve: async context =>
            {
                var orderId = context.GetArgument <string>("orderId");
                return(await context.TryAsyncResolve(
                           async c => await _orders.CancelAsync(orderId)));
            }
                );

            mutationCore.FieldAsync <OrderType>(
                "closeOrder",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "orderId"
            }),
                resolve: async context =>
            {
                var orderId = context.GetArgument <string>("orderId");
                return(await context.TryAsyncResolve(
                           async c => await _orders.CloseAsync(orderId)));
            }
                );
        }