Exemple #1
0
        public void BindResolverCollectionToObjectTypeImplicitly()
        {
            // arrange
            SchemaContext schemaContext = new SchemaContext();

            StringType stringType = new StringType();
            ObjectType dummyType  = new ObjectType(new ObjectTypeConfig
            {
                Name   = "TestObjectA",
                Fields = new[]
                {
                    new Field(new FieldConfig
                    {
                        Name = "a", Type =
                            t => stringType
                    }),
                    new Field(new FieldConfig
                    {
                        Name = "b",
                        Type = t => stringType
                    })
                }
            });

            schemaContext.Types.RegisterType(stringType);
            schemaContext.Types.RegisterType(dummyType);

            // act
            SchemaConfiguration configuration = new SchemaConfiguration();

            configuration.BindResolver <TestResolverCollectionA>().To <TestObjectA>();

            bool hasErrors = configuration.RegisterTypes(schemaContext).Any();

            configuration.RegisterResolvers(schemaContext);
            hasErrors = schemaContext.CompleteTypes().Any() || hasErrors;

            // assert
            Assert.False(hasErrors);
            Assert.NotNull(schemaContext.Resolvers.GetResolver("TestObjectA", "a"));
            Assert.NotNull(schemaContext.Resolvers.GetResolver("TestObjectA", "b"));
            Assert.Null(schemaContext.Resolvers.GetResolver("Dummy", "x"));
        }
Exemple #2
0
 private static void RegisterIntrospectionTypes(
     SchemaContext schemaContext)
 {
     schemaContext.Types.RegisterType(
         new TypeReference(typeof(__Directive)));
     schemaContext.Types.RegisterType(
         new TypeReference(typeof(__DirectiveLocation)));
     schemaContext.Types.RegisterType(
         new TypeReference(typeof(__EnumValue)));
     schemaContext.Types.RegisterType(
         new TypeReference(typeof(__Field)));
     schemaContext.Types.RegisterType(
         new TypeReference(typeof(__InputValue)));
     schemaContext.Types.RegisterType(
         new TypeReference(typeof(__Schema)));
     schemaContext.Types.RegisterType(
         new TypeReference(typeof(__Type)));
     schemaContext.Types.RegisterType(
         new TypeReference(typeof(__TypeKind)));
 }
        public void BindResolverCollectionToObjectTypeExplicitly()
        {
            // arrange
            var resolverContext = new Mock <IResolverContext>(
                MockBehavior.Strict);

            resolverContext.Setup(t => t.Parent <TestObjectA>())
            .Returns(new TestObjectA());
            resolverContext.Setup(t => t.Resolver <TestResolverCollectionA>())
            .Returns(new TestResolverCollectionA());
            resolverContext.Setup(t => t.Argument <string>("a")).Returns("foo");
            resolverContext.Setup(t => t.RequestAborted)
            .Returns(CancellationToken.None);

            var schemaContext = new SchemaContext();

            var dummyType = new ObjectType(d =>
            {
                d.Name("TestObjectA");
                d.Field("a").Type <StringType>()
                .Argument("a", a => a.Type <StringType>());
                d.Field("b").Type <StringType>();
            });

            schemaContext.Types.RegisterType(dummyType);

            // act
            var configuration = new SchemaConfiguration(
                schemaContext.RegisterServiceProvider,
                schemaContext.Types,
                schemaContext.Resolvers,
                schemaContext.Directives);

            configuration
            .BindResolver <TestResolverCollectionA>(BindingBehavior.Explicit)
            .To <TestObjectA>()
            .Resolve(t => t.A)
            .With(t => t.GetA(default, default));
        public void BindResolverCollectionToObjectTypeImplicitly()
        {
            // arrange
            SchemaContext schemaContext = new SchemaContext();

            ObjectType dummyType = new ObjectType(d =>
            {
                d.Name("TestObjectA");
                d.Field("a").Type <StringType>();
                d.Field("b").Type <StringType>();
            });

            schemaContext.Types.RegisterType(dummyType);

            // act
            SchemaConfiguration configuration = new SchemaConfiguration(
                schemaContext.RegisterServiceProvider,
                schemaContext.Types,
                schemaContext.Resolvers,
                schemaContext.Directives);

            configuration.BindResolver <TestResolverCollectionA>()
            .To <TestObjectA>();

            TypeFinalizer typeFinalizer = new TypeFinalizer(configuration);

            typeFinalizer.FinalizeTypes(schemaContext, null);
            bool hasErrors = typeFinalizer.Errors.Any();

            // assert
            Assert.False(hasErrors);
            Assert.NotNull(schemaContext.Resolvers
                           .GetResolver("TestObjectA", "a"));
            Assert.NotNull(schemaContext.Resolvers
                           .GetResolver("TestObjectA", "b"));
            Assert.Null(schemaContext.Resolvers.GetResolver("Dummy", "x"));
        }
Exemple #5
0
 private static void RegisterDirectives(
     SchemaContext schemaContext)
 {
     schemaContext.Directives.RegisterDirective(new SkipDirective());
     schemaContext.Directives.RegisterDirective(new IncludeDirective());
 }