Last active
October 10, 2017 18:29
-
-
Save mczachurski/b14fe7f078f98264d6d1ee1371a10ff0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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