Exemplo n.º 1
0
 private void ResolveFragmentDefinition(GraphQLFragmentDefinition graphQLFragmentDefinition)
 {
     if (!this.fragments.ContainsKey(graphQLFragmentDefinition.Name.Value))
     {
         this.fragments.Add(graphQLFragmentDefinition.Name.Value, graphQLFragmentDefinition);
     }
 }
Exemplo n.º 2
0
 private static FragmentDefinition Fragment(GraphQLFragmentDefinition source)
 {
     return(new FragmentDefinition(Name(source.Name), NamedType(source.TypeCondition !), SelectionSet(source.SelectionSet))
     {
         SourceLocation = Convert(source.Location),
         CommentNode = Comment(source.Comment),
         Directives = Directives(source.Directives)
     });
        public override GraphQLFragmentDefinition BeginVisitFragmentDefinition(GraphQLFragmentDefinition node)
        {
            var fragmentType = this.SchemaRepository.GetSchemaOutputTypeByName(node.TypeCondition.Name.Value);

            this.typeStack.Push(fragmentType);

            return(base.BeginVisitFragmentDefinition(node));
        }
Exemplo n.º 4
0
        public override GraphQLFragmentDefinition BeginVisitFragmentDefinition(GraphQLFragmentDefinition node)
        {
            if (!this.visitedFragments.Any(e => e == node.Name.Value))
            {
                this.DetectCycleRecursive(node);
            }

            return(node);
        }
Exemplo n.º 5
0
        private string PrintFragmentDefinition(GraphQLFragmentDefinition node)
        {
            var name          = PrintName(node.Name);
            var typeCondition = PrintNamedType(node.TypeCondition);
            var directives    = node.Directives?.Select(PrintDirective);
            var selectionSet  = PrintSelectionSet(node.SelectionSet);

            return($"fragment {name} on {typeCondition} {Wrap(string.Empty, Join(directives, " "), " ")}{selectionSet}");
        }
        public FragmentDefinition Fragment(GraphQLFragmentDefinition source)
        {
            var frag = new FragmentDefinition(Name(source.Name)).WithLocation(source, _body);

            frag.Type         = NamedType(source.TypeCondition);
            frag.SelectionSet = SelectionSet(source.SelectionSet);
            frag.Directives   = Directives(source.Directives);
            return(frag);
        }
Exemplo n.º 7
0
        protected override async ValueTask VisitFragmentDefinitionAsync(GraphQLFragmentDefinition fragmentDefinition, AnalysisContext context)
        {
            if (!context.FragmentMapAlreadyBuilt)
            {
                context.FragmentMap[fragmentDefinition.FragmentName.Name.StringValue] = context.CurrentFragmentComplexity = new FragmentComplexity();

                await base.VisitFragmentDefinitionAsync(fragmentDefinition, context).ConfigureAwait(false);

                context.CurrentFragmentComplexity = null !;
            }
        }
        public override GraphQLFragmentDefinition BeginVisitFragmentDefinition(GraphQLFragmentDefinition node)
        {
            var type = this.schemaRepository.GetSchemaInputTypeByName(node.TypeCondition.Name.Value);

            if (type != null)
            {
                var errorMessage = this.ComposeFragmentOnNonCompositeErrorMessage(node.Name.Value, type);
                this.Errors.Add(new GraphQLException(errorMessage, new[] { node.TypeCondition }));
            }

            return(base.BeginVisitFragmentDefinition(node));
        }
Exemplo n.º 9
0
        public virtual GraphQLFragmentDefinition BeginVisitFragmentDefinition(GraphQLFragmentDefinition node)
        {
            BeginVisitNode(node.TypeCondition);
            BeginVisitNode(node.Name);

            if (node.SelectionSet != null)
            {
                BeginVisitNode(node.SelectionSet);
            }

            return(node);
        }
Exemplo n.º 10
0
        private void DetectCycleRecursive(GraphQLFragmentDefinition node)
        {
            var fragmentName = node.Name.Value;

            this.visitedFragments.Add(fragmentName);

            var spreadNodes = this.GetFragmentSpreads(node.SelectionSet);

            if (!spreadNodes.Any())
            {
                return;
            }

            this.spreadPathIndexByName.Add(fragmentName, this.spreadPath.Count());

            foreach (var spreadNode in spreadNodes)
            {
                var spreadName = spreadNode.Name.Value;
                var cycleIndex = this.spreadPathIndexByName.ContainsKey(spreadName)
                    ? this.spreadPathIndexByName[spreadName]
                    : null as int?;

                if (!cycleIndex.HasValue)
                {
                    this.spreadPath.Push(spreadNode);
                    if (!this.visitedFragments.Contains(spreadName))
                    {
                        var spreadFragment = this.GetFragment(spreadName);

                        if (spreadFragment != null)
                        {
                            this.DetectCycleRecursive(spreadFragment);
                        }
                    }

                    this.spreadPath.Pop();
                }
                else
                {
                    var cyclePath = this.spreadPath
                                    .Reverse()
                                    .Skip(cycleIndex.Value);

                    this.Errors.Add(new GraphQLException(
                                        this.GetErrorMessage(
                                            spreadName,
                                            cyclePath.Select(e => e.Name.Value)),
                                        cyclePath.Append(spreadNode)));
                }
            }

            this.spreadPathIndexByName.Remove(fragmentName);
        }
        private void GetReferencedFieldsAndFragmentNames(
            GraphQLFragmentDefinition fragment,
            Dictionary <string, ICollection <NodeAndDefinitions> > fieldMap2,
            List <string> fragmentNames2)
        {
            var type = this.SchemaRepository.GetSchemaOutputTypeByName(
                fragment.TypeCondition.Name.Value);

            this.GetFieldsAndFragmentNames(
                fragment.SelectionSet,
                fieldMap2,
                fragmentNames2,
                type);
        }
        public override GraphQLFragmentDefinition BeginVisitFragmentDefinition(GraphQLFragmentDefinition node)
        {
            var fragmentName = node.Name.Value;

            if (this.knownFragmentNames.ContainsKey(fragmentName))
            {
                this.Errors.Add(this.GetFragmentNameError(fragmentName,
                                                          new ASTNode[] { this.knownFragmentNames[fragmentName], node.Name }));
            }
            else
            {
                this.knownFragmentNames.Add(node.Name.Value, node.Name);
            }

            return(base.BeginVisitFragmentDefinition(node));
        }
Exemplo n.º 13
0
        public override GraphQLFragmentDefinition BeginVisitFragmentDefinition(
            GraphQLFragmentDefinition node)
        {
            {
                Tracker.EnterFragmentDefinition?.Invoke(node);
            }

            var result = base.BeginVisitFragmentDefinition(node);


            {
                Tracker.LeaveFragmentDefinition?.Invoke(node);
            }

            return(result);
        }
Exemplo n.º 14
0
        // Given a reference to a fragment, return the represented collection of fields
        // as well as a list of nested fragment names referenced via fragment spreads.
        private CachedField GetReferencedFieldsAndFragmentNames(
            Dictionary <GraphQLSelectionSet, CachedField> cachedFieldsAndFragmentNames,
            GraphQLFragmentDefinition fragment)
        {
            // Short-circuit building a type from the node if possible.
            if (cachedFieldsAndFragmentNames.ContainsKey(fragment.SelectionSet))
            {
                return(cachedFieldsAndFragmentNames[fragment.SelectionSet]);
            }

            var fragmentType = Ast.TypeFromAst(_context.Schema, fragment.TypeCondition);

            return(GetFieldsAndFragmentNames(
                       cachedFieldsAndFragmentNames,
                       fragmentType,
                       fragment.SelectionSet));
        }
        public virtual GraphQLFragmentDefinition BeginVisitFragmentDefinition(GraphQLFragmentDefinition node)
        {
            this.BeginVisitNode(node.TypeCondition);
            this.BeginVisitNode(node.Name);

            if (node.Directives != null)
            {
                this.BeginVisitNodeCollection(node.Directives);
            }

            if (node.SelectionSet != null)
            {
                this.BeginVisitNode(node.SelectionSet);
            }

            return(this.EndVisitFragmentDefinition(node));
        }
Exemplo n.º 16
0
 public FragmentType(GraphQLFragmentDefinition definition)
 {
     this.definition = definition;
     this.Name       = definition.Name?.Value;
     this.Selection  = new SetSelection(this.definition);
 }
 public override GraphQLFragmentDefinition BeginVisitFragmentDefinition(GraphQLFragmentDefinition node)
 {
     return(node);
 }
Exemplo n.º 18
0
 public FragmentBelongsToOperationVisitorContext(GraphQLFragmentDefinition fragment)
 {
     Fragment = fragment;
 }
Exemplo n.º 19
0
 private GraphQLBaseType GetFragmentType(GraphQLFragmentDefinition fragmentDefinition)
 {
     return(this.SchemaRepository.GetSchemaOutputTypeByName(fragmentDefinition.TypeCondition.Name.Value));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance with the specified properties.
 /// </summary>
 public UniqueFragmentNamesError(ValidationContext context, GraphQLFragmentDefinition node, GraphQLFragmentDefinition altNode)
     : base(context.Document.Source, NUMBER, DuplicateFragmentNameMessage(node.FragmentName.Name.StringValue), node, altNode)
 {
 }
Exemplo n.º 21
0
 internal string ResolveFragment(GraphQLFragmentDefinition operation)
 {
     return(astPrinter.Print(operation));
 }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance with the specified properties.
 /// </summary>
 public NoUnusedFragmentsError(ValidationContext context, GraphQLFragmentDefinition node)
     : base(context.Document.Source, NUMBER, UnusedFragMessage(node.FragmentName.Name.StringValue), node)
 {
 }
Exemplo n.º 23
0
 private void ResolveFragmentDefinition(GraphQLFragmentDefinition graphQLFragmentDefinition)
 {
     this.fragments.Add(graphQLFragmentDefinition.Name.Value, graphQLFragmentDefinition);
 }
Exemplo n.º 24
0
 public void AddFragment(GraphQLFragmentDefinition fragment)
 => ValidationContext.AddListItem(nameof(GetRecursivelyReferencedFragmentsVisitorContext), fragment);
Exemplo n.º 25
0
    public void MergeFieldAndFragment()
    {
        var fragmentSelection = new GraphQLSelectionSet
        {
            Selections = new List <ASTNode>
            {
                FirstTestField
            }
        };
        var fragment = new GraphQLFragmentDefinition
        {
            FragmentName = new GraphQLFragmentName {
                Name = new GraphQLName("fragment")
            },
            TypeCondition = new GraphQLTypeCondition
            {
                Type = new GraphQLNamedType
                {
                    Name = new GraphQLName("Query")
                }
            },
            SelectionSet = fragmentSelection
        };

        var document = new GraphQLDocument
        {
            Definitions = new List <ASTNode>
            {
                fragment
            }
        };

        var query = new ObjectGraphType {
            Name = "Query"
        };

        query.Fields.Add(new FieldType
        {
            Name         = "test",
            ResolvedType = new StringGraphType()
        });
        var schema = new Schema {
            Query = query
        };

        var context = new ExecutionContext
        {
            Document = document,
            Schema   = schema
        };

        var fragSpread = new GraphQLFragmentSpread {
            FragmentName = new GraphQLFragmentName {
                Name = new GraphQLName("fragment")
            }
        };
        var outerSelection = new GraphQLSelectionSet
        {
            Selections = new List <ASTNode>
            {
                fragSpread,
                SecondTestField
            }
        };

        var fields = CollectFrom(context, query, outerSelection);

        fields.ShouldHaveSingleItem();
        fields["test"].Field.SelectionSet.Selections.ShouldContain(x => x == FirstInnerField);
        fields["test"].Field.SelectionSet.Selections.ShouldContain(x => x == SecondInnerField);
    }
        public override GraphQLFragmentDefinition EndVisitFragmentDefinition(GraphQLFragmentDefinition node)
        {
            this.typeStack.Pop();

            return(base.EndVisitFragmentDefinition(node));
        }
 public virtual GraphQLFragmentDefinition EndVisitFragmentDefinition(GraphQLFragmentDefinition node)
 {
     return(node);
 }
Exemplo n.º 28
0
 public virtual GraphQLFragmentDefinition BeginVisitFragmentDefinition(GraphQLFragmentDefinition node)
 {
     this.BeginVisitNode(node.TypeCondition);
     return(node);
 }