示例#1
0
        public void Can_Ignore_Unwanted_Types()
        {
            // Ignore specific types from the 'Unwanted' namespace.

            var schema = new SchemaConstructor <ISchema, IGraphType>(new GraphTypeAdapter())
                         .IgnoreTypes((Type t, MemberInfo m) => {
                // Ignore based on the type:
                if (t == typeof(Unwanted.QueryType3))
                {
                    return(true);
                }
                // Ignore based on name of the method:
                if (m != null && m.Name == "UpdateSomethingIgnored")
                {
                    return(true);
                }
                return(false);
            })
                         .Build(
                typeof(SchemaType1),
                typeof(SchemaType2),
                typeof(Unwanted.SchemaType3)
                );

            schema.ShouldHaveQueries(3);
            schema.ShouldHaveMutations(1);
            schema.Query.ShouldHaveFieldWithName("foo");
            schema.Query.ShouldHaveFieldWithName("bar");
            schema.Query.ShouldHaveFieldWithName("baz");
            schema.Query.ShouldNotHaveFieldWithName("bazIgnored");
            schema.Mutation.ShouldHaveFieldWithName("updateSomething");
            schema.Mutation.ShouldNotHaveFieldWithName("updateSomethingIgnored");
        }
示例#2
0
        public void Can_Ignore_Types_From_Unwanted_Namespaces()
        {
            var schema = new SchemaConstructor <ISchema, IGraphType>(new GraphTypeAdapter()).Build(
                typeof(SchemaType1),
                typeof(SchemaType2),
                typeof(Unwanted.SchemaType3)
                );

            schema.ShouldHaveQueries(4);
            schema.ShouldHaveMutations(2);
            schema.Query.ShouldHaveFieldWithName("foo");
            schema.Query.ShouldHaveFieldWithName("bar");
            schema.Query.ShouldHaveFieldWithName("baz");
            schema.Query.ShouldHaveFieldWithName("bazIgnored");
            schema.Mutation.ShouldHaveFieldWithName("updateSomething");
            schema.Mutation.ShouldHaveFieldWithName("updateSomethingIgnored");



            // Ignore all types from the 'Unwanted' namespace.

            var unwantedNamespaces = new[] {
                "GraphQL.Conventions.Tests.Builders.U",
                "GraphQL.Conventions.Tests.Builders.Un",
                "GraphQL.Conventions.Tests.Builders.Unw",
                "GraphQL.Conventions.Tests.Builders.Unwan",
                "GraphQL.Conventions.Tests.Builders.Unwant",
                "GraphQL.Conventions.Tests.Builders.Unwante",
                "GraphQL.Conventions.Tests.Builders.Unwanted"
            };

            foreach (var namespaceStartFragment in unwantedNamespaces)
            {
                schema = new SchemaConstructor <ISchema, IGraphType>(new GraphTypeAdapter())
                         .IgnoreTypesFromNamespacesStartingWith(namespaceStartFragment)
                         .Build(
                    typeof(SchemaType1),
                    typeof(SchemaType2),
                    typeof(Unwanted.SchemaType3)
                    );

                schema.ShouldHaveQueries(3);
                schema.ShouldHaveMutations(1);
                schema.Query.ShouldHaveFieldWithName("foo");
                schema.Query.ShouldHaveFieldWithName("bar");
                schema.Query.ShouldHaveFieldWithName("baz");
                schema.Query.ShouldNotHaveFieldWithName("bazIgnored");
                schema.Mutation.ShouldHaveFieldWithName("updateSomething");
                schema.Mutation.ShouldNotHaveFieldWithName("updateSomethingIgnored");
            }
        }