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);
            });
        }
示例#2
0
 private void RegisterDirectiveDependencies(ISchemaContext schemaContext)
 {
     foreach (INeedsInitialization directive in schemaContext.Directives
              .GetDirectiveTypes().Cast <INeedsInitialization>())
     {
         var initializationContext =
             new TypeInitializationContext(schemaContext,
                                           e => _errors.Add(e));
         directive.RegisterDependencies(initializationContext);
     }
 }
示例#3
0
 private void CompleteDirectives(
     List <SchemaError> errors)
 {
     foreach (INeedsInitialization directive in
              _directiveRegistry.GetDirectiveTypes()
              .Cast <INeedsInitialization>())
     {
         var initializationContext = new TypeInitializationContext(
             this, e => errors.Add(e));
         directive.CompleteType(initializationContext);
     }
 }
示例#4
0
        private void RegisterDirectiveDependencies(ISchemaContext schemaContext)
        {
            foreach (DirectiveType directive in schemaContext.Directives
                     .GetDirectiveTypes())
            {
                var initializationContext = new TypeInitializationContext(
                    schemaContext, e => _errors.Add(e), directive, false);

                ((INeedsInitialization)directive)
                .RegisterDependencies(initializationContext);
            }
        }
示例#5
0
 private void CompleteDirectives(
     ICollection <SchemaError> errors)
 {
     foreach (DirectiveType directive in
              _directiveRegistry.GetDirectiveTypes())
     {
         var initializationContext = new TypeInitializationContext(
             this, e => errors.Add(e), directive, false);
         ((INeedsInitialization)directive)
         .CompleteType(initializationContext);
     }
 }
示例#6
0
        public IEnumerable <SchemaError> CompleteDirectives()
        {
            List <SchemaError> errors = new List <SchemaError>();

            foreach (INeedsInitialization directive in _directiveRegistry.GetDirectives()
                     .Cast <INeedsInitialization>())
            {
                var initializationContext = new TypeInitializationContext(
                    this, e => errors.Add(e));
                directive.CompleteType(initializationContext);
            }
            return(errors);
        }
        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);
            });
        }
示例#8
0
 private void CompleteTypes(
     IEnumerable <INamedType> types,
     HashSet <INamedType> processed,
     List <SchemaError> errors)
 {
     foreach (INamedType namedType in types)
     {
         if (processed.Add(namedType) &&
             namedType is INeedsInitialization init)
         {
             var initializationContext = new TypeInitializationContext(
                 this, e => errors.Add(e), namedType, false);
             init.CompleteType(initializationContext);
         }
     }
 }
示例#9
0
        // TODO : rename
        private void RegisterTypeDependencies(
            ISchemaContext schemaContext,
            INamedType type,
            string queryTypeName)
        {
            if (type is INeedsInitialization initializer)
            {
                bool isQueryType = string.Equals(queryTypeName,
                                                 type.Name, StringComparison.Ordinal);

                var initializationContext =
                    new TypeInitializationContext(schemaContext,
                                                  e => _errors.Add(e), type, isQueryType);

                initializer.RegisterDependencies(initializationContext);
            }
        }
示例#10
0
        public IEnumerable <SchemaError> CompleteTypes()
        {
            // compile resolvers
            _resolverRegistry.BuildResolvers();

            // complete types
            List <SchemaError> errors = new List <SchemaError>();

            foreach (INamedType namedType in _typeRegistry.GetTypes())
            {
                if (namedType is INeedsInitialization init)
                {
                    var initializationContext = new TypeInitializationContext(
                        this, e => errors.Add(e), namedType, false);
                    init.CompleteType(initializationContext);
                }
            }
            return(errors);
        }
示例#11
0
        internal static TypeResult <T> CreateType <T>(
            Func <ISchemaContext, T> factory)
            where T : class, INamedType, INeedsInitialization
        {
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            var type = factory(schemaContext);

            schemaContext.Types.RegisterType(type);

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

            type.RegisterDependencies(initializationContext);

            schemaContext.CompleteTypes();

            return(new TypeResult <T>(type, errors));
        }