private static void AddDependencies(
            Types.IHasName typeContext,
            List <ISelectionNode> selections,
            IEnumerable <FieldDependency> dependencies)
        {
            foreach (var typeGroup in dependencies.GroupBy(t => t.TypeName))
            {
                var fields = new List <FieldNode>();

                foreach (NameString fieldName in typeGroup.Select(t => t.FieldName))
                {
                    fields.Add(CreateField(fieldName));
                }

                if (typeGroup.Key.Equals(typeContext.Name))
                {
                    selections.AddRange(fields);
                }
                else
                {
                    selections.Add(new InlineFragmentNode
                                   (
                                       null,
                                       new NamedTypeNode(null, new NameNode(typeGroup.Key)),
                                       Array.Empty <DirectiveNode>(),
                                       new SelectionSetNode(null, fields)
                                   ));
                }
            }
        }
Exemplo n.º 2
0
        private static void CollectDelegationDependencies(
            Context context,
            Types.IHasName type,
            IOutputField field)
        {
            IDirective?directive = field.Directives[DirectiveNames.Delegate]
                                   .FirstOrDefault();

            if (directive is not null)
            {
                CollectFieldNames(
                    directive.ToObject <DelegateDirective>(),
                    type,
                    context.Dependencies);
            }
        }
Exemplo n.º 3
0
        private static void CollectFieldNames(
            DelegateDirective directive,
            Types.IHasName type,
            ISet <FieldDependency> dependencies)
        {
            IImmutableStack <SelectionPathComponent> path =
                SelectionPathParser.Parse(directive.Path);

            foreach (SelectionPathComponent component in path)
            {
                foreach (string fieldName in component.Arguments
                         .Select(t => t.Value)
                         .OfType <ScopedVariableNode>()
                         .Where(t => ScopeNames.Fields.Equals(t.Scope.Value))
                         .Select(t => t.Name.Value))
                {
                    dependencies.Add(new FieldDependency(type.Name, fieldName));
                }
            }
        }