public void GetArgumentFromCustomDirective()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = Directive.FromDescription(
                directiveType,
                new DirectiveDefinition(
                    fooDirective,
                    _typeInspector.GetTypeRef(fooDirective.GetType())),
                new object());
            var barValue = directive.GetArgument <string>("bar");

            // assert
            Assert.Equal("123", barValue);
        }
        public void MapCustomDirectiveToDifferentType()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = Directive.FromDescription(
                directiveType,
                new DirectiveDefinition(
                    fooDirective,
                    _typeInspector.GetTypeRef(fooDirective.GetType())),
                new object());
            FooChild mappedObject = directive.ToObject <FooChild>();

            // assert
            Assert.Equal("123", mappedObject.Bar);
        }
예제 #3
0
        public void CreateRepeatableDirectiveType()
        {
            // arrange
            var source = "directive @foo(a:String) repeatable on QUERY";

            // act
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString(source)
                             .AddQueryType <DummyQuery>()
                             .Create();

            // assert
            DirectiveType type = schema.GetDirectiveType("foo");

            Assert.Equal("foo", type.Name);
            Assert.True(type.IsRepeatable);

            Assert.Collection(type.Locations,
                              t => Assert.Equal(DirectiveLocation.Query, t));

            Assert.Collection(type.Arguments,
                              t =>
            {
                Assert.Equal("a", t.Name);
                Assert.IsType <StringType>(t.Type);
            });
        }
예제 #4
0
        public void GetDirective()
        {
            /* Given */
            var directiveTypeName = DirectiveType.Include.Name;

            /* When */
            var directiveType = Schema.GetDirectiveType(directiveTypeName);

            /* Then */
            Assert.NotNull(directiveType);
            Assert.IsType <DirectiveType>(directiveType);
        }
        public void ConvertCustomDirectiveToDirectiveNode()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = Directive.FromDescription(
                directiveType,
                new DirectiveDefinition(
                    fooDirective,
                    _typeInspector.GetTypeRef(fooDirective.GetType())),
                new object());
            DirectiveNode directiveNode = directive.ToNode();

            // assert
            Assert.Equal(directiveType.Name, directiveNode.Name.Value);
            Assert.Collection(directiveNode.Arguments,
                              t =>
            {
                Assert.Equal("bar", t.Name.Value);
                Assert.Equal("123", ((StringValueNode)t.Value).Value);
            },
                              t =>
            {
                Assert.Equal("child", t.Name.Value);
                Assert.Collection(((ObjectValueNode)t.Value).Fields,
                                  x =>
                {
                    Assert.Equal("bar", x.Name.Value);
                    Assert.Equal("456",
                                 ((StringValueNode)x.Value).Value);
                });
            });
        }
예제 #6
0
        public void GetArgumentFromCustomDirective()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = new Directive(
                directiveType, fooDirective, new object());
            string barValue = directive.GetArgument <string>("bar");

            // assert
            Assert.Equal("123", barValue);
        }
예제 #7
0
        public void MapCustomDirectiveToDifferentType()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = new Directive(
                directiveType, fooDirective, new object());
            FooChild mappedObject = directive.ToObject <FooChild>();

            // assert
            Assert.Equal("123", mappedObject.Bar);
        }
예제 #8
0
        public void GetArgumentFromCustomDirectiveAndConvertIt()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = new Directive(
                directiveType, fooDirective, new object());
            FooChild2 barValue = directive.GetArgument <FooChild2>("child");

            // assert
            Assert.Equal("456", barValue.Bar);
        }
예제 #9
0
        public void Use2_ClassMiddleware_WithFactory()
        {
            // arrange
            // act
            ISchema schema = SchemaBuilder.New()
                             .AddQueryType(c => c
                                           .Name("Query")
                                           .Directive("foo")
                                           .Field("foo")
                                           .Type <StringType>()
                                           .Resolver("bar"))
                             .AddDirectiveType(new DirectiveType(d => d
                                                                 .Name("foo")
                                                                 .Location(DirectiveLocation.Object)
                                                                 .Use((sp, next) => new DirectiveMiddleware(next))))
                             .Create();

            // assert
            DirectiveType directive = schema.GetDirectiveType("foo");

            Assert.Collection(directive.MiddlewareComponents,
                              t => Assert.NotNull(t));
        }
예제 #10
0
        public void Use_DelegateMiddleware()
        {
            // arrange
            // act
            ISchema schema = SchemaBuilder.New()
                             .AddQueryType(c => c
                                           .Name("Query")
                                           .Directive("foo")
                                           .Field("foo")
                                           .Type <StringType>()
                                           .Resolver("bar"))
                             .AddDirectiveType(new DirectiveType <CustomDirective2>(d => d
                                                                                    .Name("foo")
                                                                                    .Location(DirectiveLocation.Object)
                                                                                    .Use(next => context => Task.CompletedTask)))
                             .Create();

            // assert
            DirectiveType directive = schema.GetDirectiveType("foo");

            Assert.Collection(directive.MiddlewareComponents,
                              t => Assert.NotNull(t));
        }
예제 #11
0
        public void AddDirectiveType_DirectiveTypeIsAdded_SchemaIsCreated()
        {
            // arrange
            var queryType = new ObjectType(t => t
                                           .Name("Query")
                                           .Field("foo")
                                           .Resolver("bar"));

            var directiveType = new DirectiveType(t => t
                                                  .Name("foo")
                                                  .Location(Types.DirectiveLocation.Field));

            // act
            ISchema schema = SchemaBuilder.New()
                             .AddType(queryType)
                             .AddDirectiveType(directiveType)
                             .Create();

            // assert
            DirectiveType type = schema.GetDirectiveType("foo");

            Assert.Equal(directiveType, type);
        }