We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi Glen, There is possibility of sending empty requests to Graphql server implemented using GraphQL.NET and asp.net core 2.
I tried to implement it using asp.net core 2 action filter but it seems not to be working.
// Startup.cs public void ConfigureServices(IServiceCollection services) { //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddMvc(options => { options.Filters.Add(typeof (CheckModelForNullAttribute)); options.Filters.Add(typeof (ValidateModelStateAttribute)); } ).SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } // GraphQLController.cs [Route("[controller]")] public class GraphQLController : Controller { private readonly IDocumentExecuter _documentExecuter; private readonly ISchema _schema; public GraphQLController(ISchema schema, IDocumentExecuter documentExecuter) { _schema = schema; _documentExecuter = documentExecuter; } [HttpPost] public async Task<IActionResult> Post([FromBody] GraphQLQuery query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } var inputs = query.Variables.ToInputs(); var executionOptions = new ExecutionOptions{Schema = _schema, Query = query.Query, Inputs = inputs, UserContext = Request.Headers, //UserContext = new GraphQLUserContext { Headers = Request.Headers } }; var result = await _documentExecuter.ExecuteAsync(executionOptions).ConfigureAwait(false); if (result.Errors?.Count > 0) { return BadRequest(result); } return Ok(result); } } // CheckModelForNullAttribute.cs public class CheckModelForNullAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { if (context.ActionArguments.Any(c => c.Value == null)) { context.Result = new BadRequestObjectResult(context.ModelState); } } } // ValidateModelStateAttribute.cs public class ValidateModelStateAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { if (!context.ModelState.IsValid) { context.Result = new BadRequestObjectResult(context.ModelState); } } }
Can you please help me to fix this issue?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi Glen,
There is possibility of sending empty requests to Graphql server implemented using GraphQL.NET and asp.net core 2.
I tried to implement it using asp.net core 2 action filter but it seems not to be working.
Can you please help me to fix this issue?
The text was updated successfully, but these errors were encountered: