示例#1
0
        public void MergeFieldAndFragment()
        {
            var fragment = new FragmentDefinition(new NameNode("fragment"));
            var fragmentSelection = new SelectionSet();
            fragmentSelection.Add(FirstTestField);
            fragment.SelectionSet = fragmentSelection;
            fragment.Type = new GraphQL.Language.AST.NamedType(
                new NameNode("Person"));

            var fragments = new Fragments { fragment };

            var schema = new Schema();
            schema.RegisterType(new PersonType());

            var context = new ExecutionContext
            {
                Fragments = fragments,
                Schema = schema
            };

            var fragSpread = new FragmentSpread(new NameNode("fragment"));
            var outerSelection = new SelectionSet();
            outerSelection.Add(fragSpread);
            outerSelection.Add(SecondTestField);

            var fields = ExecutionHelper.CollectFields(
                context,
                new PersonType(),
                outerSelection);

            fields.ShouldHaveSingleItem();
            fields["test"].SelectionSet.Selections.ShouldContain(x => x.IsEqualTo(FirstInnerField));
            fields["test"].SelectionSet.Selections.ShouldContain(x => x.IsEqualTo(SecondInnerField));
        }
示例#2
0
        public void BeMergedCorrectlyInCaseOfFields()
        {
            var outerSelection = new SelectionSet();
            outerSelection.Add(FirstTestField);
            outerSelection.Add(SecondTestField);

            var fields = ExecutionHelper.CollectFields(new ExecutionContext(), null, outerSelection);

            fields.ContainsKey("test").ShouldBeTrue();
            fields["test"].SelectionSet.Selections.ShouldContain(x => x.IsEqualTo(FirstInnerField));
            fields["test"].SelectionSet.Selections.ShouldContain(x => x.IsEqualTo(SecondInnerField));
        }
示例#3
0
        public void NotMergeAliasedFields()
        {
            var outerSelection = new SelectionSet();
            outerSelection.Add(FirstTestField);
            outerSelection.Add(AliasedTestField);

            var fields = ExecutionHelper.CollectFields(new ExecutionContext(), null, outerSelection);

            fields["test"].SelectionSet.Selections.ShouldHaveSingleItem();
            fields["test"].SelectionSet.Selections.ShouldContain(x => x.IsEqualTo(FirstInnerField));
            fields["alias"].SelectionSet.Selections.ShouldHaveSingleItem();
            fields["alias"].SelectionSet.Selections.ShouldContain(x => x.IsEqualTo(SecondInnerField));
        }
示例#4
0
        public void TestValidate_WhenNotAuthenticatedAndOnlyAccessingPrivateAndQueryTypes_ShouldGenerateErrors()
        {
            // Given
            var selectionSet = new SelectionSet();

            selectionSet.Add(new Field(new NameNode("__types"), new NameNode("__types")));
            selectionSet.Add(new Field(new NameNode("me"), new NameNode("me")));
            var operation = new Operation {
                SelectionSet = selectionSet
            };

            // When
            var nodeListener = Service.Validate(_context);

            nodeListener.Enter(operation);

            // Verify
            Assert.NotEmpty(_context.Errors);
        }
示例#5
0
        public void TestValidate_WhenAuthenticated_ShouldNotGenerateErrors()
        {
            // Given
            Session.CurrentUser = new User();
            var selectionSet = new SelectionSet();

            selectionSet.Add(new Field(new NameNode("__types"), new NameNode("__types")));
            selectionSet.Add(new Field(new NameNode("me"), new NameNode("me")));
            var operation = new Operation {
                SelectionSet = selectionSet
            };

            // When
            var nodeListener = Service.Validate(_context);

            nodeListener.Enter(operation);

            // Verify
            Assert.Empty(_context.Errors);
        }
示例#6
0
        public RepeatedSubfieldsTests()
        {
            FirstInnerField     = new Field(null, new NameNode("first"));
            FirstFieldSelection = new SelectionSet();
            FirstFieldSelection.Add(FirstInnerField);
            SecondInnerField     = new Field(null, new NameNode("second"));
            SecondFieldSelection = new SelectionSet();
            SecondFieldSelection.Add(SecondInnerField);
            FirstTestField   = new Field(null, new NameNode("test"));
            SecondTestField  = new Field(null, new NameNode("test"));
            AliasedTestField = new Field(new NameNode("alias"), new NameNode("test"));

            FirstTestField.SelectionSet   = FirstFieldSelection;
            SecondTestField.SelectionSet  = SecondFieldSelection;
            AliasedTestField.SelectionSet = SecondFieldSelection;
        }
示例#7
0
        /// <summary>
        /// Create a new CsQuery object from an existing CsQuery object (or any set of DOM elements).
        /// If the source is a unassociated list of DOM elements, the context of the first element will become
        /// the context of the new CsQuery object.
        /// </summary>
        /// <param name="elements"></param>
        public CQ(IEnumerable <IDomObject> elements)
        {
            //List<IDomObject> elList = new List<IDomObject>(elements);

            bool first = true;

            if (elements is CQ)
            {
                CsQueryParent = (CQ)elements;
                first         = false;
            }

            foreach (IDomObject el in elements)
            {
                if (first)
                {
                    Document = el.Document;
                    first    = false;
                }
                SelectionSet.Add(el);
            }
        }
        public ExecutionDocumentWalkerOptions Add(object visitor)
        {
            if (visitor is IVisit <ExecutableDocument> ed)
            {
                ExecutableDocument.Add(ed);
            }

            if (visitor is IVisit <FragmentDefinition> fd)
            {
                FragmentDefinition.Add(fd);
            }

            if (visitor is IVisit <OperationDefinition> od)
            {
                OperationDefinition.Add(od);
            }

            if (visitor is IVisit <SelectionSet> ss)
            {
                SelectionSet.Add(ss);
            }


            if (visitor is IVisit <ISelection> s)
            {
                Selection.Add(s);
            }

            if (visitor is IVisit <FieldSelection> fs)
            {
                FieldSelection.Add(fs);
            }

            if (visitor is IVisit <InlineFragment> ift)
            {
                InlineFragment.Add(ift);
            }

            if (visitor is IVisit <FragmentSpread> fgs)
            {
                FragmentSpread.Add(fgs);
            }

            if (visitor is IVisit <Argument> arg)
            {
                Argument.Add(arg);
            }

            if (visitor is IVisit <NamedType> nt)
            {
                NamedType.Add(nt);
            }

            if (visitor is IVisit <VariableDefinition> vd)
            {
                VariableDefinition.Add(vd);
            }

            if (visitor is IVisit <DefaultValue> dv)
            {
                DefaultValue.Add(dv);
            }

            if (visitor is IVisit <Value> v)
            {
                Value.Add(v);
            }

            if (visitor is IVisit <Directive> d)
            {
                Directive.Add(d);
            }

            if (visitor is IVisit <TypeBase> t)
            {
                Type.Add(t);
            }

            return(this);
        }