public void CheckFieldsAreCorrect()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var type = new ConnectionType <StringType>();

            // assert
            INeedsInitialization init = type;

            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), type, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Collection(type.Fields.Where(t => !t.IsIntrospectionField),
                              t =>
            {
                Assert.Equal("pageInfo", t.Name);
                Assert.IsType <NonNullType>(t.Type);
                Assert.IsType <PageInfoType>(((NonNullType)t.Type).Type);
            },
                              t =>
            {
                Assert.Equal("edges", t.Name);
                Assert.IsType <ListType>(t.Type);
                Assert.IsType <NonNullType>(((ListType)t.Type).ElementType);
                Assert.IsType <EdgeType <StringType> >(
                    ((NonNullType)((ListType)t.Type).ElementType).Type);
            });
        }
        public void GenericInputObject_AddDirectives_NameArgs2()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            schemaContext.Directives.RegisterDirectiveType <FooDirectiveType>();

            // act
            var fooType = new InputObjectType <SimpleInput>(
                d => d.Directive(new NameString("foo"))
                .Field(f => f.Id)
                .Directive(new NameString("foo")));

            // assert
            schemaContext.Types.RegisterType(fooType);
            INeedsInitialization init = fooType;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);
            Assert.NotEmpty(fooType.Directives["foo"]);
            Assert.NotEmpty(fooType.Fields["id"].Directives["foo"]);
        }
Beispiel #3
0
        public void InterfaceType_AddDirectives_DirectiveType()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            schemaContext.Directives.RegisterDirectiveType <FooDirectiveType>();

            // act
            var fooType = new InterfaceType(
                d => d.Directive <FooDirective>()
                .Field("id")
                .Type <StringType>()
                .Directive <FooDirective>());

            // assert
            schemaContext.Types.RegisterType(fooType);
            INeedsInitialization init = fooType;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);
            Assert.NotEmpty(fooType.Directives["foo"]);
            Assert.NotEmpty(fooType.Fields["id"].Directives["foo"]);
        }
Beispiel #4
0
        public void DeclareUnion_MarkerInterfaceAndTypeSet()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            schemaContext.Types.RegisterType(new FooType());
            schemaContext.Types.RegisterType(new BarType());

            // act
            var fooType = new UnionType <IFooOrBar>(c => c.Type <BazType>());

            // assert
            schemaContext.Types.RegisterType(fooType);
            INeedsInitialization init = fooType;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);
            Assert.Collection(fooType.Types.Values,
                              t => Assert.Equal("Baz", t.Name),
                              t => Assert.Equal("Foo", t.Name),
                              t => Assert.Equal("Bar", t.Name));
        }
Beispiel #5
0
        public void UnionType_AddDirectives_DirectiveClassInstance()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            schemaContext.Directives.RegisterDirectiveType <FooDirectiveType>();

            // act
            var fooType = new UnionType(
                d => d.Directive(new FooDirective())
                .Type <FooType>()
                .Type <BarType>());

            // assert
            schemaContext.Types.RegisterType(fooType);
            INeedsInitialization init = fooType;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);
            Assert.NotEmpty(fooType.Directives["foo"]);
        }
Beispiel #6
0
        public void DeclareUnion_ByProvidingExplicitTypeSet()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var fooType = new UnionType(d => d
                                        .Type <FooType>()
                                        .Type <BarType>());

            // assert
            schemaContext.Types.RegisterType(fooType);
            INeedsInitialization init = fooType;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);
            Assert.Collection(fooType.Types.Values,
                              t => Assert.Equal("Foo", t.Name),
                              t => Assert.Equal("Bar", t.Name));
        }
Beispiel #7
0
 internal void RegisterForInitialization(
     INeedsInitialization dependency)
 {
     if (_status == TypeStatus.Created)
     {
         _dependencies.Add(dependency);
     }
 }
        public void CheckFieldsAreCorrect()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var type = new PageInfoType();

            // assert
            INeedsInitialization init = type;

            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), type, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Collection(type.Fields.Where(t => !t.IsIntrospectionField),
                              t =>
            {
                Assert.Equal("hasNextPage", t.Name);
                Assert.Equal(
                    "Indicates whether more edges exist following " +
                    "the set defined by the clients arguments.",
                    t.Description);
                Assert.IsType <NonNullType>(t.Type);
                Assert.IsType <BooleanType>(((NonNullType)t.Type).Type);
            },
                              t =>
            {
                Assert.Equal("hasPreviousPage", t.Name);
                Assert.Equal(
                    "Indicates whether more edges exist prior " +
                    "the set defined by the clients arguments.",
                    t.Description);
                Assert.IsType <NonNullType>(t.Type);
                Assert.IsType <BooleanType>(((NonNullType)t.Type).Type);
            },
                              t =>
            {
                Assert.Equal("startCursor", t.Name);
                Assert.IsType <StringType>(t.Type);
            },
                              t =>
            {
                Assert.Equal("endCursor", t.Name);
                Assert.IsType <StringType>(t.Type);
            });
        }
Beispiel #9
0
        public void InferFieldsFromClrInterface()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            schemaContext.Types.RegisterType(new BooleanType());
            schemaContext.Types.RegisterType(new StringType());
            schemaContext.Types.RegisterType(new IntType());

            // act
            var fooType = new InterfaceType <IFoo>();

            schemaContext.Types.RegisterType(fooType);

            INeedsInitialization init = fooType;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);

            schemaContext.CompleteTypes();

            // assert
            Assert.Empty(errors);
            Assert.Collection(
                fooType.Fields.Where(t => !t.IsIntrospectionField),
                t =>
            {
                Assert.Equal("bar", t.Name);
                Assert.IsType <BooleanType>(
                    Assert.IsType <NonNullType>(t.Type).Type);
            },
                t =>
            {
                Assert.Equal("baz", t.Name);
                Assert.IsType <StringType>(t.Type);
            },
                t =>
            {
                Assert.Equal("qux", t.Name);
                Assert.IsType <IntType>(
                    Assert.IsType <NonNullType>(t.Type).Type);
                Assert.Collection(t.Arguments,
                                  a => Assert.Equal("a", a.Name));
            });
        }
        public void GenericObjectTypes()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var genericType           = new ObjectType <GenericFoo <string> >();
            INeedsInitialization init = genericType;

            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), genericType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();
            // assert
            Assert.Equal("GenericFooOfString", genericType.Name);
        }
        public void IntializeImpicitFieldWithImplicitResolver()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var fooType = new ObjectType <Foo>();
            INeedsInitialization init = fooType;

            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            // assert
            Assert.Empty(errors);
            Assert.NotNull(fooType.Fields.First().Resolver);
        }
        public void Initialize_IgnoreProperty_PropertyIsNotInSchemaType()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var fooType = new InputObjectType <SimpleInput>(
                d => d.Field(f => f.Id).Ignore());
            INeedsInitialization init = fooType;

            // assert
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);
            Assert.Collection(fooType.Fields,
                              t => Assert.Equal("name", t.Name));
        }
Beispiel #13
0
        public void IntializeExplicitFieldWithImplicitResolver()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var nodeInterface = new NodeType();

            // assert
            INeedsInitialization init = nodeInterface;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), nodeInterface, false);

            schemaContext.Types.RegisterType(nodeInterface);
            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);

            Assert.Equal(
                "Node",
                nodeInterface.Name);

            Assert.Equal(
                "The node interface is implemented by entities that have " +
                "a gloabl unique identifier.",
                nodeInterface.Description);

            Assert.Collection(nodeInterface.Fields,
                              t =>
            {
                Assert.Equal("id", t.Name);
                Assert.IsType <IdType>(
                    Assert.IsType <NonNullType>(t.Type).Type);
            });
        }
Beispiel #14
0
        public void ExplicitInterfaceFieldDeclaration()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            schemaContext.Types.RegisterType(new BooleanType());
            schemaContext.Types.RegisterType(new StringType());
            schemaContext.Types.RegisterType(new IntType());

            // act
            var fooType = new InterfaceType <IFoo>(t =>
                                                   t.BindFields(BindingBehavior.Explicit)
                                                   .Field(p => p.Bar));

            schemaContext.Types.RegisterType(fooType);

            INeedsInitialization init = fooType;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);

            schemaContext.CompleteTypes();

            // assert
            Assert.Empty(errors);
            Assert.Collection(
                fooType.Fields.Where(t => !t.IsIntrospectionField),
                t =>
            {
                Assert.Equal("bar", t.Name);
                Assert.IsType <BooleanType>(
                    Assert.IsType <NonNullType>(t.Type).Type);
            });
        }