Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Last active October 10, 2017 18:29
Show Gist options
  • Select an option

  • Save mczachurski/b14fe7f078f98264d6d1ee1371a10ff0 to your computer and use it in GitHub Desktop.

Select an option

Save mczachurski/b14fe7f078f98264d6d1ee1371a10ff0 to your computer and use it in GitHub Desktop.
[Route("api/graphql")]
public class GraphQLController : Controller
{
private readonly GraphQLQuery _graphQLQuery;
private readonly IDocumentExecuter _documentExecuter;
private readonly ISchema _schema;
public GraphQLController(GraphQLQuery graphQLQuery, IDocumentExecuter documentExecuter, ISchema schema)
{
_graphQLQuery = graphQLQuery;
_documentExecuter = documentExecuter;
_schema = schema;
}
[HttpPost]
public async Task<IActionResult> Post([FromBody] GraphQLParameter query)
{
var executionOptions = new ExecutionOptions { Schema = _schema, Query = query.Query, UserContext = User };
var result = await _documentExecuter.ExecuteAsync(executionOptions).ConfigureAwait(false);
if (result.Errors?.Count > 0)
{
return BadRequest(result.Errors);
}
return Ok(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment