コード例 #1
0
        public void GetFieldDependencies()
        {
            // arrange
            ISchema schema = Schema.Create(
                FileResource.Open("Stitching.graphql"),
                c =>
            {
                c.RegisterType <DateTimeType>();
                c.RegisterDirective <DelegateDirectiveType>();
                c.Use(next => context => Task.CompletedTask);
            });

            DocumentNode query = Utf8GraphQLParser.Parse(
                FileResource.Open("StitchingQuery.graphql"));

            FieldNode selection = query.Definitions
                                  .OfType <OperationDefinitionNode>().Single()
                                  .SelectionSet.Selections
                                  .OfType <FieldNode>().Single();

            // act
            var fieldDependencyResolver         = new FieldDependencyResolver(schema);
            ISet <FieldDependency> dependencies = fieldDependencyResolver
                                                  .GetFieldDependencies(
                query,
                selection,
                schema.GetType <ObjectType>("Customer"));

            // assert
            Snapshot.Match(dependencies);
        }
コード例 #2
0
        protected override SelectionSetNode RewriteSelectionSet(
            SelectionSetNode node,
            Context context)
        {
            SelectionSetNode current = node;

            var selections = new List <ISelectionNode>(current.Selections);

            ISet <FieldDependency> dependencies =
                _dependencyResolver.GetFieldDependencies(
                    context.Document, current, context.TypeContext);

            RemoveDelegationFields(current, context, selections);
            AddDependencies(context.TypeContext, selections, dependencies);

            if (!selections.OfType <FieldNode>().Any(n => n.Name.Value == WellKnownFieldNames.TypeName))
            {
                selections.Add(CreateField(WellKnownFieldNames.TypeName));
            }

            current = current.WithSelections(selections);
            current = base.RewriteSelectionSet(current, context);
            current = OnRewriteSelectionSet(current, context);

            return(current);
        }