Example #1
0
            private static DocumentNode MergeSchemas(
                StitchingBuilder builder,
                IDictionary <NameString, DocumentNode> schemas)
            {
                var merger = new SchemaMerger();

                foreach (NameString name in schemas.Keys)
                {
                    merger.AddSchema(name, schemas[name]);
                }

                foreach (MergeTypeRuleFactory handler in builder._mergeRules)
                {
                    merger.AddMergeRule(handler);
                }

                foreach (IDocumentRewriter rewriter in builder._docRewriters)
                {
                    merger.AddDocumentRewriter(rewriter);
                }

                foreach (ITypeRewriter rewriter in builder._typeRewriters)
                {
                    merger.AddTypeRewriter(rewriter);
                }

                return(merger.Merge());
            }
        private static DocumentNode MergeSchemas(
            IDescriptorContext context,
            IDictionary <NameString, DocumentNode> schemas)
        {
            var merger = new SchemaMerger();

            foreach (NameString name in schemas.Keys)
            {
                merger.AddSchema(name, schemas[name]);
            }

            foreach (MergeTypeRuleFactory handler in context.GetTypeMergeRules())
            {
                merger.AddTypeMergeRule(handler);
            }

            foreach (MergeDirectiveRuleFactory handler in context.GetDirectiveMergeRules())
            {
                merger.AddDirectiveMergeRule(handler);
            }

            foreach (IDocumentRewriter rewriter in context.GetDocumentRewriter())
            {
                merger.AddDocumentRewriter(rewriter);
            }

            foreach (ITypeRewriter rewriter in context.GetTypeRewriter())
            {
                merger.AddTypeRewriter(rewriter);
            }

            return(merger.Merge());
        }
Example #3
0
        public void AddSchemaFromFile()
        {
            // arrange
            IHttpClientFactory clientFactory = CreateRemoteSchemas();
            var builder = new MockStitchingBuilder();

            // act
            builder.AddSchemaFromFile("contract",
                                      IOPath.Combine("__resources__", "Contract.graphql"))
            .AddSchemaFromFile("customer",
                               IOPath.Combine("__resources__", "Customer.graphql"));

            // assert
            var services = new DictionaryServiceProvider(
                typeof(IHttpClientFactory),
                clientFactory);
            var merger = new SchemaMerger();

            foreach (KeyValuePair <NameString, LoadSchemaDocument> item in
                     builder.Schemas)
            {
                merger.AddSchema(item.Key, item.Value.Invoke(services));
            }

            SchemaSyntaxSerializer.Serialize(merger.Merge()).MatchSnapshot();
        }
Example #4
0
        public void AddSchema_2()
        {
            // arrange
            Schema customerSchema = Schema.Create(
                CustomerSchemaFactory.ConfigureSchema);

            Schema contractSchema = Schema.Create(
                ContractSchemaFactory.ConfigureSchema);

            var builder = new MockStitchingBuilder();

            // act
            builder.AddSchema("customer", customerSchema)
            .AddSchema("contract", contractSchema);

            // assert
            var services = new EmptyServiceProvider();
            var merger   = new SchemaMerger();

            foreach (KeyValuePair <NameString, ExecutorFactory> item in
                     builder.Executors)
            {
                ISchema schema = item.Value.Invoke(services).Schema;
                merger.AddSchema(item.Key,
                                 SchemaSerializer.SerializeSchema(schema));
            }

            SchemaSyntaxSerializer.Serialize(merger.Merge()).MatchSnapshot();
        }
Example #5
0
        private DocumentNode MergeSchema()
        {
            if (_schemas.Count == 1)
            {
                return(_schemas.First().Value);
            }

            SchemaMerger merger = SchemaMerger.New();

            foreach (KeyValuePair <string, DocumentNode> schema in _schemas)
            {
                merger.AddSchema(schema.Key, schema.Value);
            }

            return(merger.Merge());
        }
Example #6
0
        public void AddSchemaFromString()
        {
            // arrange
            var builder = new MockStitchingBuilder();

            // act
            builder.AddSchemaFromString("contract",
                                        FileResource.Open("Contract.graphql"))
            .AddSchemaFromString("customer",
                                 FileResource.Open("Customer.graphql"));

            // assert
            var services = new EmptyServiceProvider();
            var merger   = new SchemaMerger();

            foreach (KeyValuePair <NameString, LoadSchemaDocument> item in
                     builder.Schemas)
            {
                merger.AddSchema(item.Key, item.Value.Invoke(services));
            }

            SchemaSyntaxSerializer.Serialize(merger.Merge()).MatchSnapshot();
        }