Exemple #1
0
        public void InvalidScope()
        {
            // arrange
            var schema = Schema.Create(
                "type Query { foo(a: String = \"bar\") : String }",
                c =>
            {
                c.UseNullResolver();
                c.Options.StrictValidation = false;
            });

            var context = new Mock <IMiddlewareContext>();

            context.SetupGet(t => t.Field).Returns(
                schema.GetType <ObjectType>("Query").Fields["foo"]);
            context.Setup(t => t.Argument <object>(It.IsAny <string>()))
            .Returns("Baz");

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("foo"),
                new NameNode("b"));

            // act
            var    resolver = new ArgumentScopedVariableResolver();
            Action a        = () => resolver.Resolve(context.Object, scopedVariable,
                                                     new NamedTypeNode(new NameNode("abc")));

            // assert
            Assert.Equal("variable",
                         Assert.Throws <ArgumentException>(a).ParamName);
        }
Exemple #2
0
        public void ContextIsNull()
        {
            // arrange
            var schema = Schema.Create(
                "type Query { foo(a: String = \"bar\") : String }",
                c =>
            {
                c.UseNullResolver();
                c.Options.StrictValidation = false;
            });

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("arguments"),
                new NameNode("b"));

            // act
            var    resolver = new ArgumentScopedVariableResolver();
            Action a        = () => resolver.Resolve(null, scopedVariable,
                                                     new NamedTypeNode(new NameNode("abc")));

            // assert
            Assert.Equal("context",
                         Assert.Throws <ArgumentNullException>(a).ParamName);
        }
        public void InvalidScope()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String }")
                             .Use(_ => _)
                             .ModifyOptions(o => o.StrictValidation = false)
                             .Create();

            ObjectField field = schema.GetType <ObjectType>("Query").Fields["foo"];

            var selection = new Mock <IFieldSelection>(MockBehavior.Strict);

            selection.SetupGet(t => t.Field).Returns(field);

            var context = new Mock <IResolverContext>(MockBehavior.Strict);

            context.SetupGet(t => t.Selection).Returns(selection.Object);
            context.Setup(t => t.ArgumentValue <object>(It.IsAny <NameString>())).Returns("Baz");

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("foo"),
                new NameNode("b"));

            // act
            var    resolver = new ArgumentScopedVariableResolver();
            Action a        = () => resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Equal("variable", Assert.Throws <ArgumentException>(a).ParamName);
        }
Exemple #4
0
        public void CreateVariableValue()
        {
            // arrange
            var schema = Schema.Create(
                "type Query { foo(a: String = \"bar\") : String }",
                c =>
            {
                c.UseNullResolver();
                c.Options.StrictValidation = false;
            });

            var         context = new Mock <IResolverContext>(MockBehavior.Strict);
            ObjectField field   = schema.GetType <ObjectType>("Query").Fields["foo"];

            context.SetupGet(t => t.Field).Returns(field);
            context.Setup(t => t.Argument <IValueNode>("a")).Returns(new StringValueNode("baz"));

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("arguments"),
                new NameNode("a"));

            // act
            var           resolver = new ArgumentScopedVariableResolver();
            VariableValue value    = resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Equal("bar", Assert.IsType <StringValueNode>(value.DefaultValue).Value);
            Assert.Equal("arguments_a", value.Name);
            Assert.Equal("String", Assert.IsType <NamedTypeNode>(value.Type).Name.Value);
            Assert.Equal("baz", value.Value.Value);
        }
        public void ArgumentDoesNotExist()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String }")
                             .Use(_ => _)
                             .ModifyOptions(o => o.StrictValidation = false)
                             .Create();

            var selection = new Mock <IFieldSelection>(MockBehavior.Strict);

            selection.SetupGet(t => t.Field).Returns(
                schema.GetType <ObjectType>("Query").Fields["foo"]);

            var context = new Mock <IResolverContext>(MockBehavior.Strict);

            context.SetupGet(t => t.Selection).Returns(selection.Object);

            context.Setup(t => t.ArgumentValue <object>(It.IsAny <NameString>()))
            .Returns("Baz");
            context.Setup(t => t.Selection.SyntaxNode)
            .Returns(new FieldNode(
                         null,
                         new NameNode("foo"),
                         null,
                         Array.Empty <DirectiveNode>(),
                         Array.Empty <ArgumentNode>(),
                         null));
            context.Setup(t => t.Path).Returns(Path.New("foo"));

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("arguments"),
                new NameNode("b"));

            // act
            var    resolver = new ArgumentScopedVariableResolver();
            Action a        = () => resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Collection(
                Assert.Throws <GraphQLException>(a).Errors,
                t => Assert.Equal(ErrorCodes.Stitching.ArgumentNotDefined, t.Code));
        }
Exemple #6
0
        public void ArgumentDoesNotExist()
        {
            // arrange
            var schema = Schema.Create(
                "type Query { foo(a: String = \"bar\") : String }",
                c =>
            {
                c.UseNullResolver();
                c.Options.StrictValidation = false;
            });

            var context = new Mock <IMiddlewareContext>();

            context.SetupGet(t => t.Field).Returns(
                schema.GetType <ObjectType>("Query").Fields["foo"]);
            context.Setup(t => t.Argument <object>(It.IsAny <NameString>()))
            .Returns("Baz");
            context.Setup(t => t.FieldSelection)
            .Returns(new FieldNode(
                         null,
                         new NameNode("foo"),
                         null,
                         Array.Empty <DirectiveNode>(),
                         Array.Empty <ArgumentNode>(),
                         null));
            context.Setup(t => t.Path).Returns(Path.New("foo"));

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("arguments"),
                new NameNode("b"));

            // act
            var    resolver = new ArgumentScopedVariableResolver();
            Action a        = () => resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Collection(
                Assert.Throws <QueryException>(a).Errors,
                t => Assert.Equal(ErrorCodes.ArgumentNotDefined, t.Code));
        }
        public void CreateVariableValue()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String }")
                             .Use(_ => _)
                             .ModifyOptions(o => o.StrictValidation = false)
                             .Create();

            ObjectField field = schema.GetType <ObjectType>("Query").Fields["foo"];

            var selection = new Mock <IFieldSelection>(MockBehavior.Strict);

            selection.SetupGet(t => t.Field).Returns(field);

            var context = new Mock <IResolverContext>(MockBehavior.Strict);

            context.SetupGet(t => t.Selection).Returns(selection.Object);
            context.Setup(t => t.ArgumentLiteral <IValueNode>("a"))
            .Returns(new StringValueNode("baz"));

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("arguments"),
                new NameNode("a"));

            // act
            var resolver = new ArgumentScopedVariableResolver();
            ScopedVariableValue value = resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Equal("bar", Assert.IsType <StringValueNode>(value.DefaultValue).Value);
            Assert.Equal("__arguments_a", value.Name);
            Assert.Equal("String", Assert.IsType <NamedTypeNode>(value.Type).Name.Value);
            Assert.Equal("baz", value.Value !.Value);
        }