public void Optimize(IPreparedOperation operation, ObjectType objectType)
 {
     Visit(
         new OptimizerContext(operation),
         operation.GetRootSelectionSet(),
         null);
 }
Beispiel #2
0
        public void Prepare_Inline_Fragment()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddStarWarsTypes()
                             .Create();

            DocumentNode document = Utf8GraphQLParser.Parse(
                @"{
                hero(episode: EMPIRE) {
                    name
                    ... on Droid {
                        primaryFunction
                    }
                    ... on Human {
                        homePlanet
                    }
                }
             }");

            OperationDefinitionNode operationDefinition =
                document.Definitions.OfType <OperationDefinitionNode>().Single();

            // act
            IPreparedOperation operation =
                OperationCompiler.Compile(
                    "a",
                    document,
                    operationDefinition,
                    schema,
                    schema.QueryType,
                    new(new DefaultTypeConverter()));

            // assert
            ISelection hero = operation.GetRootSelectionSet().Selections.Single();

            Assert.Equal("hero", hero.ResponseName);

            Assert.Collection(
                operation.GetSelectionSet(hero.SelectionSet !, schema.GetType <ObjectType>("Droid"))
                .Selections,
                selection => Assert.Equal("name", selection.ResponseName),
                selection => Assert.Equal("primaryFunction", selection.ResponseName));

            Assert.Collection(
                operation.GetSelectionSet(hero.SelectionSet, schema.GetType <ObjectType>("Human"))
                .Selections,
                selection => Assert.Equal("name", selection.ResponseName),
                selection => Assert.Equal("homePlanet", selection.ResponseName));

            operation.Print().MatchSnapshot();
        }