Пример #1
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
                                         );
 }
        public StarWarsMutation(StarWarsData data)
        {
            Name = "Mutation";

            Field <HumanType>(
                "createHuman",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <HumanInputType> > {
                Name = "human"
            }
                    ),

                resolve: context =>
            {
                if (context.GetArgument <Human>("human").Name == "mammad")
                {
                    context.Errors.Add(new ExecutionError("Mammad is not human, he is an angel."));
                    return(null);
                }
                var human = context.GetArgument <Human>("human");
                return(data.AddHuman(human));
            });
        }