public void ExecuteRule_EnsureCorrectErrorIsGenerated(string expectedRuleError, string queryText) { var server = new TestServerBuilder() .AddGraphType <PeopleMoverController>() .AddGraphType <AllowDirective>() .AddGraphType <RestrictDirective>() .Build(); // parse the query var document = server.CreateDocument(queryText); // inspect for error codes if (document.Messages.Count != 1) { var errors = document.Messages.Where( x => x.MetaData != null && x.MetaData.ContainsKey("Rule")) .Select(x => x.MetaData["Rule"]); string errorMessage = $"Expected 1 error ({expectedRuleError}) but recieved {document.Messages.Count}: '{string.Join(", ", errors)}'"; Assert.Fail(errorMessage); } var message = document.Messages[0]; Assert.IsNotNull(message.MetaData); Assert.IsTrue(message.MetaData.ContainsKey("Rule")); var ruleBroke = message.MetaData["Rule"]; Assert.AreEqual(expectedRuleError, ruleBroke.ToString()); }
public void SingleValueProvidedForAList_IsCoercible() { var server = new TestServerBuilder() .AddGraphType <InputCoersionValidatorController>() .Build(); // arg1 accepts [int] (an array of ints), single value should be coercable into a list // https://graphql.github.io/graphql-spec/June2018/#sec-Type-System.List var document = server.CreateDocument("query { singleScalarIntInput(arg1: 5) {name} }"); Assert.IsNotNull(document); Assert.AreEqual(0, document.Messages.Count); Assert.AreEqual(1, document.Operations.Count); var operation = document.Operations[string.Empty]; Assert.IsNotNull(operation); Assert.AreEqual(1, operation.FieldSelectionSet.Count); var field = operation.FieldSelectionSet[0]; Assert.AreEqual("singleScalarIntInput", field.Name.ToString()); Assert.AreEqual(1, field.Arguments.Count); // value will not be a list at this stage, thats later // rules should be enforced such that this is acceptable for a list var arg1 = field.Arguments["arg1"]; var scalarValue = arg1.Value as QueryScalarInputValue; Assert.IsNotNull(scalarValue); Assert.IsTrue(scalarValue.ValueNode is ScalarValueNode); Assert.AreEqual("5", scalarValue.Value.ToString()); }
private IGraphQueryDocument CreateDocument(string text, out ISchema schema) { var server = new TestServerBuilder() .AddGraphType <TestUserController>() .AddGraphType <FieldLevelDirective>() .Build(); schema = server.Schema; return(server.CreateDocument(text)); }