public void AddDelegationPath_SingleComponent_TwoArgs()
        {
            // arrange
            var fieldNode = new FieldDefinitionNode(
                null,
                new NameNode("foo"),
                null,
                Array.Empty <InputValueDefinitionNode>(),
                new NamedTypeNode(new NameNode("Type")),
                Array.Empty <DirectiveNode>());

            // act
            var path = new SelectionPathComponent(
                new NameNode("bar"),
                new[]
            {
                new ArgumentNode("baz",
                                 new ScopedVariableNode(
                                     null,
                                     new NameNode("qux"),
                                     new NameNode("quux"))),
                new ArgumentNode("value_arg", "value")
            });

            fieldNode = fieldNode.AddDelegationPath("schemName", path);

            // assert
            var schema = new DocumentNode(new[]
            {
                new ObjectTypeDefinitionNode
                (
                    null,
                    new NameNode("Object"),
                    null,
                    Array.Empty <DirectiveNode>(),
                    Array.Empty <NamedTypeNode>(),
                    new[] { fieldNode }
                )
            });

            SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot();
        }
Ejemplo n.º 2
0
        public static FieldDefinitionNode AddDelegationPath(
            this FieldDefinitionNode field,
            NameString schemaName,
            SelectionPathComponent selectionPath)
        {
            if (field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if (selectionPath == null)
            {
                throw new ArgumentNullException(nameof(selectionPath));
            }

            schemaName.EnsureNotEmpty(nameof(schemaName));

            return(AddDelegationPath(
                       field,
                       schemaName,
                       selectionPath.ToString()));
        }
Ejemplo n.º 3
0
        private static void IntegrateFields(
            ObjectTypeDefinitionNode rootType,
            ITypeInfo typeInfo,
            ISet <string> names,
            ICollection <FieldDefinitionNode> fields)
        {
            string schemaName = typeInfo.Schema.Name;

            foreach (FieldDefinitionNode field in rootType.Fields)
            {
                FieldDefinitionNode current = field;

                if (names.Add(current.Name.Value))
                {
                    current = current.AddDelegationPath(schemaName);
                }
                else
                {
                    var path = new SelectionPathComponent(
                        field.Name,
                        field.Arguments.Select(t => new ArgumentNode(
                                                   t.Name,
                                                   new ScopedVariableNode(
                                                       null,
                                                       new NameNode(ScopeNames.Arguments),
                                                       t.Name))).ToList());

                    var newName = new NameNode(
                        typeInfo.CreateUniqueName(current));

                    current = current.WithName(newName)
                              .AddDelegationPath(schemaName, path);
                }

                fields.Add(current);
            }
        }
        public void AddDelegationPath_SingleComponent_SchemNameIsEmpty()
        {
            // arrange
            var fieldNode = new FieldDefinitionNode(
                null,
                new NameNode("foo"),
                null,
                Array.Empty <InputValueDefinitionNode>(),
                new NamedTypeNode(new NameNode("Type")),
                Array.Empty <DirectiveNode>());

            // act
            var path = new SelectionPathComponent(
                new NameNode("bar"),
                new[]
            {
                new ArgumentNode("baz",
                                 new ScopedVariableNode(
                                     null,
                                     new NameNode("qux"),
                                     new NameNode("quux")))
            });

            Action action = () => fieldNode.AddDelegationPath(default, path);
 public static FieldDefinitionNode AddDelegationPath(
     this FieldDefinitionNode field,
     NameString schemaName,
     SelectionPathComponent selectionPath) =>
 AddDelegationPath(field, schemaName, selectionPath, false);