Пример #1
0
        public TestGroupMutations(IHttpContextAccessor _httpContextAccessor)
        {
            Name = "testMutations";
            #region example

            /*
             *  mutation($input: TestRequestInput!)
             *  {
             *      testMutations
             *      {
             *          demoMutation(input: $input)
             *          {
             *              code
             *          }
             *      }
             *  }
             *
             *
             *  {
             *      "input":
             *      {
             *          "fake": "fake text",
             *          "fakeEnum": 100,
             *          "test": 1,
             *          "testOther": 2
             *      }
             *  }
             */
            #endregion
            FieldAsync <TestResponseType>(
                "demoMutation",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <TestRequestInputType> > {
                Name = "input"
            }),
                resolve: async context =>
            {
                using (var scope = _httpContextAccessor.CreateScope())
                {
                    //example of scopes authorization, if it is configured from startup.cs
                    //_httpContextAccessor.ValidateScopes("create");

                    //get dto; use GetArgumentExtension instead of native GetArgument, because solve some deserialization problems
                    TestRequest request = context.GetArgumentExtension <TestRequest>("input");

                    //validate model
                    _httpContextAccessor.Validate(request);

                    return(await scope.GetService <ITestService>().DemoMutation(request));
                }
            });
        }
        public TestGroupQueries(IHttpContextAccessor _httpContextAccessor)
        {
            Name = "testQueries";

            #region example

            /*
             * query($input: Int!)
             * {
             *  testQueries
             *  {
             *      demoQuery(input: $input)
             *      {
             *          code
             *      }
             *  }
             * }
             *
             *
             * {
             *  "input": 1
             * }
             */
            #endregion
            FieldAsync <TestResponseType>(
                "demoQuery",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "input"
            }),
                resolve: async context =>
            {
                using (var scope = _httpContextAccessor.CreateScope())
                {
                    //example of scopes authorization, if it is configured from startup.cs
                    //_httpContextAccessor.ValidateScopes("read");

                    return(await scope.GetService <ITestService>().DemoQuery(context.GetArgument <int>("input")));
                }
            });
        }