public async Task <IActionResult> Post([FromBody] GraphQLQuery query) { var inputs = query.Variables.ToInputs(); var schema = new GraphQL.Types.Schema { Query = new CoreQueries(this.Mediator), Mutation = new CoreMutations(this.Mediator) }; var result = await new DocumentExecuter().ExecuteAsync(_ => { _.Schema = schema; _.Query = query.Query; _.OperationName = query.OperationName; _.Inputs = inputs; }); if (result.Errors?.Count > 0) { return(BadRequest()); } return(Ok(result)); }
public async Task <IActionResult> Post([FromBody] GraphQLQuery query) { if (query == null) { throw new ArgumentException(nameof(query)); } ; var inputs = query.Variables.ToInputs(); var schema = new GraphQL.Types.Schema() { Query = new Schema.Query(Db.Mongo) }; var result = await new DocumentExecuter().ExecuteAsync(_ => { _.Schema = schema; _.Query = query.Query; _.OperationName = query.OperationName; _.Inputs = inputs; }); if (result.Errors?.Count > 0) { return(BadRequest(result.Errors)); } return(Ok(result.Data)); }
public static void QueryOperationsSuccess(GraphQL.Types.Schema schema, string query, string expected, string variables = null, bool compareBoth = true) { var result2 = DocumentOperations.ExecuteOperationsAsync(schema, null, query, variables?.ToInputs()).Result; var writtenResult2 = JsonConvert.SerializeObject(result2.Data); var queryResult = CreateQueryResult(expected); var expectedResult = JsonConvert.SerializeObject(queryResult.Data); var errors = result2.Errors?.FirstOrDefault(); //for easy debugging var allTypes = schema.AllTypes; Assert.Null(errors?.Message); Assert.Equal(expectedResult, writtenResult2); }
public static void QuerySuccess(GraphQL.Types.Schema schema, string query, string expected) { var exec = new DocumentExecuter(new AntlrDocumentBuilder(), new DocumentValidator()); var result = exec.ExecuteAsync(schema, null, query, null).Result; var writer = new DocumentWriter(indent: true); var writtenResult = writer.Write(result.Data); var expectedResult = writer.Write(CreateQueryResult(expected).Data); var errors = result.Errors?.FirstOrDefault(); //for easy debugging var allTypes = schema.AllTypes; Assert.Null(errors?.Message); Assert.Equal(expectedResult, writtenResult); }
public async Task <object> ExecuteAsync(GraphQlQuery query) { var schema = new GraphQL.Types.Schema { Query = _customerQuery, DependencyResolver = _dependencyResolver }; var inputs = query.Variables; var result = await _documentExecuter.ExecuteAsync( _ => { _.Inputs = inputs; _.Schema = schema; _.Query = query.Query; _.OperationName = query.OperationName; }); return(result.Data); }
public static void QuerySuccess(GraphQL.Types.Schema schema, string query, string expected, string variables = null, bool compareBoth = true) { var exec = new DocumentExecuter(new GraphQLDocumentBuilder(), new DocumentValidator(), new ComplexityAnalyzer()); var result = exec.ExecuteAsync(schema, null, query, null, variables?.ToInputs()).Result; var result2 = DocumentOperations.ExecuteOperationsAsync(schema, null, query, variables?.ToInputs()).Result; var writtenResult = JsonConvert.SerializeObject(result.Data); var writtenResult2 = JsonConvert.SerializeObject(result2.Data); var queryResult = CreateQueryResult(expected); var expectedResult = JsonConvert.SerializeObject(queryResult.Data); var errors = result.Errors?.FirstOrDefault(); var errors2 = result2.Errors?.FirstOrDefault(); //for easy debugging var allTypes = schema.AllTypes; Assert.IsNull(errors?.Message); Assert.IsNull(errors2?.Message); Assert.AreEqual(expectedResult, writtenResult); Assert.AreEqual(expectedResult, writtenResult2); }
public SchemaWriter(GraphQL.Types.Schema schema) { executor = new DocumentExecuter(); _schema = schema; }
public GraphQLModel(IAppEntity app, IEnumerable <ISchemaEntity> schemas, SharedTypes typeFactory, ISemanticLog log) { this.log = log; schema = new Builder(app, typeFactory).BuildSchema(schemas); }
private sealed record CacheEntry(GraphQLSchema Model, string Hash, Instant Created);