public void Can_Hide_Ignored_Field()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <Fields>()) as IObjectGraphType;

            type.ShouldNotHaveFieldWithName("ignoredField");
        }
        public void Can_Derive_Field_With_Overridden_Name()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <Fields>()) as IObjectGraphType;

            type.ShouldHaveFieldWithName("overriddenField");
        }
        public void Can_Derive_Input_Type_With_Fields()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <InputTypeWithFields>()) as InputObjectGraphType;

            type.ShouldHaveFields(2);
        }
Beispiel #4
0
        public void Can_Derive_Input_Type()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <InputType>());

            Assert.IsInstanceOfType(type, typeof(InputObjectGraphType));
        }
        public void Can_Derive_Output_Type_With_No_Fields()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <OutputTypeWithNoFields>()) as IObjectGraphType;

            type.ShouldHaveFields(0);
        }
        public void Can_Derive_Type_Implementing_Interface()
        {
            var typeResolver = new TypeResolver();
            var type         = Type <ObjectGraphType>(typeResolver.DeriveType <TypeImplementingInterfaces>());

            type.ShouldHaveFields(2);
            type.ShouldHaveFieldWithName("interfaceField");
            type.ShouldHaveFieldWithName("typeField");

            type.Interfaces.Count().ShouldEqual(1);
            type.Interfaces.ShouldContain(typeof(Extended.InterfaceGraphType <IInterface>));

            var iface = Type <IInterfaceGraphType>(typeResolver.DeriveType <IInterface>());

            iface.PossibleTypes.ShouldContain(nameof(TypeImplementingInterfaces));
        }
        public void Can_Derive_Type_With_Deprecation_Reason()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <TypeWithDeprecationReason>());

            type.DeprecationReason.ShouldEqual("Some Deprecation Reason");
        }
        public void Can_Derive_Type_Without_Deprecation_Reason()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <TypeWithoutDeprecationReason>());

            type.DeprecationReason.ShouldBeEmpty();
        }
        public void Can_Derive_Type_With_Overridden_Name()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <TypeWithOverriddenName>());

            type.Name.ShouldEqual("Foo");
        }
Beispiel #10
0
        private void DeriveMetaData()
        {
            var type = TypeRepresentation;

            if (type == typeof(ResolveEventStreamContext) || type == typeof(ResolveFieldContext))
            {
                return;
            }

            if (type.IsGenericType(typeof(Task <>)))
            {
                IsTask = true;
                type   = type.TypeParameter();
            }

            if (type.IsGenericType(typeof(IObservable <>)))
            {
                type = type.TypeParameter();
            }

            if (type.IsGenericType(typeof(Nullable <>)))
            {
                IsNullable  = true;
                type        = type.TypeParameter();
                IsPrimitive = type.IsPrimitiveGraphType();
            }
            else if (type.IsGenericType(typeof(NonNull <>)))
            {
                IsNullable  = false;
                type        = type.TypeParameter();
                IsPrimitive = type.IsPrimitiveGraphType();
            }
            else
            {
                IsNullable  = !type.IsValueType;
                IsPrimitive = type.IsPrimitiveGraphType();
            }

            if (type.IsEnumerableGraphType())
            {
                IsListType    = true;
                IsArrayType   = type.IsArray;
                IsPrimitive   = true;
                TypeParameter = TypeResolver.DeriveType(type.TypeParameter());
            }
            else
            {
                IsListType = false;
            }

            var typeRegistration = TypeResolver.LookupType(type);

            IsRegisteredType  = typeRegistration != null;
            IsOutputType      = true;
            IsInputType       = IsPrimitive || type.IsValueType || (typeRegistration?.IsScalar ?? false);
            IsInterfaceType   = !IsListType && type.IsInterface;
            IsEnumerationType = type.IsEnum;
            Name = typeRegistration?.Name ?? type.Name;
        }
        public void Can_Derive_Normal_Field()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <Fields>()) as IObjectGraphType;
            var field        = type.ShouldHaveFieldWithName("normalField");

            field.Arguments.Count.ShouldEqual(0);
        }
        public void Can_Derive_Field_Type_When_Unwrapped()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <Fields>()) as IObjectGraphType;
            var field        = type.ShouldHaveFieldWithName("stringField");

            field.Type.ShouldEqual(typeof(StringGraphType));
        }
        public void Can_Derive_Type_With_Description()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <TypeWithDescription>());

            type.Name.ShouldEqual(nameof(TypeWithDescription));
            type.Description.ShouldEqual("Some Description");
        }
        public void Can_Derive_Field_With_Deprecation_Reason()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <Fields>()) as IObjectGraphType;
            var field        = type.ShouldHaveFieldWithName("fieldWithDeprecationReason");

            field.DeprecationReason.ShouldEqual("Some Deprecation Reason");
        }
        public void Can_Derive_Interface()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <IInterface>()) as IComplexGraphType;

            Assert.IsInstanceOfType(type, typeof(IInterfaceGraphType));
            type.ShouldHaveFields(1);
            type.ShouldHaveFieldWithName("interfaceField");
        }
        public void Can_Derive_Field_With_Arguments()
        {
            var typeResolver = new TypeResolver();
            var type         = Type(typeResolver.DeriveType <Fields>()) as IObjectGraphType;
            var field        = type.ShouldHaveFieldWithName("fieldWithArguments");

            field.Type.ShouldEqual(typeof(NonNullGraphType <IntGraphType>));
            field.Arguments.Count.ShouldEqual(2);
            field.ShouldHaveArgument("a");
            field.ShouldHaveArgument("b");
        }
        public void Can_Derive_Schema_Without_Query()
        {
            var typeResolver = new TypeResolver();
            var schema = Schema(new GraphSchemaInfo
            {
                Mutation = typeResolver.DeriveType<SimpleMutationType>(),
            });

            schema.ShouldHaveQueries(0);
            schema.ShouldHaveMutations(1);
            schema.Mutation.Name.ShouldEqual(nameof(SimpleMutationType));
            schema.ShouldHaveSubscriptons(0);
        }
        public void Can_Derive_Type_Implementing_Multiple_Interfaces()
        {
            var typeResolver = new TypeResolver();
            var type         = Type <ObjectGraphType>(typeResolver.DeriveType <TypeImplementingTwoInterfaces>());

            type.ShouldHaveFields(2);
            type.ShouldHaveFieldWithName("field1");
            type.ShouldHaveFieldWithName("field2");

            type.Interfaces.Count().ShouldEqual(2);
            type.Interfaces.ShouldContain(typeof(Extended.InterfaceGraphType <IInterface1>));
            type.Interfaces.ShouldContain(typeof(Extended.InterfaceGraphType <IInterface2>));

            var iface1 = Type <IInterfaceGraphType>(typeResolver.DeriveType <IInterface1>());

            iface1.PossibleTypes.ShouldContain(nameof(TypeImplementingTwoInterfaces));
            iface1.Name.ShouldEqual("IInterface1");

            var iface2 = Type <IInterfaceGraphType>(typeResolver.DeriveType <IInterface2>());

            iface2.PossibleTypes.ShouldContain(nameof(TypeImplementingTwoInterfaces));
            iface2.Name.ShouldEqual("IInterface2");
        }
Beispiel #19
0
        protected GraphTypeInfo TypeInfo <TType>()
        {
            var typeResolver = new TypeResolver();

            return(typeResolver.DeriveType <TType>());
        }
        private IGraphType GetGraphType(GraphTypeAdapter typeAdapter, TypeResolver typeResolver, TypeInfo typeInfo)
        {
            var graphTypeInfo = typeResolver.DeriveType(typeInfo);

            return(typeAdapter.DeriveType(graphTypeInfo));
        }