Exemple #1
0
        public void CreateArgumentWithoutLocation()
        {
            // arrange
            var name  = new NameNode("foo");
            var value = new StringValueNode("bar");

            // act
            var argument = new ArgumentNode(name, value);

            // assert
            Assert.Equal(NodeKind.Argument, argument.Kind);
            Assert.Null(argument.Location);
            Assert.Equal(name, argument.Name);
            Assert.Equal(value, argument.Value);
        }
        public void Argument_GetNodes()
        {
            // arrange
            var name     = new NameNode("foo");
            var value    = new StringValueNode("bar");
            var argument = new ArgumentNode(null, name, value);

            // act
            ISyntaxNode[] nodes = argument.GetNodes().ToArray();

            // assert
            Assert.Collection(nodes,
                              n => Assert.Equal(name, n),
                              v => Assert.Equal(value, v));
        }
Exemple #3
0
        public void Create_StringValueNode_3_Location_Is_Null()
        {
            // arrange
            var stringValue = Encoding.UTF8.GetBytes("abc");

            // act
            var value = new StringValueNode(null, stringValue, true);

            // assert
            Assert.Equal("abc", value.Value);
            Assert.True(value.Block);
            Assert.Equal(SyntaxKind.StringValue, value.Kind);
            Assert.Null(value.Location);
            Assert.Empty(value.GetNodes());
        }
Exemple #4
0
        public void Create_StringValueNode_2_With_Location()
        {
            // arrange
            var location = new Location(1, 1, 1, 1);

            // act
            var value = new StringValueNode(location, "abc", true);

            // assert
            Assert.Equal("abc", value.Value);
            Assert.True(value.Block);
            Assert.Equal(SyntaxKind.StringValue, value.Kind);
            Assert.Same(location, value.Location);
            Assert.Empty(value.GetNodes());
        }
Exemple #5
0
 public FieldDefinitionNode(
     Location location,
     NameNode name,
     StringValueNode description,
     IReadOnlyList <InputValueDefinitionNode> arguments,
     ITypeNode type,
     IReadOnlyList <DirectiveNode> directives)
     : base(location, name, directives)
 {
     Description = description;
     Arguments   = arguments
                   ?? throw new ArgumentNullException(nameof(arguments));
     Type = type
            ?? throw new ArgumentNullException(nameof(type));
 }
Exemple #6
0
        public void CreateArgumentWithConvenienceConstructor()
        {
            // arrange
            var name  = "foo";
            var value = new StringValueNode("bar");

            // act
            var argument = new ArgumentNode(name, value);

            // assert
            Assert.Equal(NodeKind.Argument, argument.Kind);
            Assert.Null(argument.Location);
            Assert.Equal(name, argument.Name.Value);
            Assert.Equal(value, argument.Value);
        }
 public DirectiveDefinitionNode(
     Location location,
     NameNode name,
     StringValueNode description,
     IReadOnlyCollection <InputValueDefinitionNode> arguments,
     IReadOnlyCollection <NameNode> locations)
 {
     Location = location;
     Name     = name
                ?? throw new System.ArgumentNullException(nameof(name));
     Description = description;
     Arguments   = arguments
                   ?? throw new System.ArgumentNullException(nameof(arguments));
     Locations = locations
                 ?? throw new System.ArgumentNullException(nameof(locations));
 }
Exemple #8
0
        public void WithValue_1()
        {
            // arrange
            var value = new StringValueNode("abc");

            // act
            value = value.WithValue("def");


            // assert
            Assert.Equal("def", value.Value);
            Assert.False(value.Block);
            Assert.Equal(SyntaxKind.StringValue, value.Kind);
            Assert.Null(value.Location);
            Assert.Empty(value.GetNodes());
        }
        public void CreateArgumentWithLocation()
        {
            // arrange
            var location = new Location(0, 0, 0, 0);
            var name     = new NameNode("foo");
            var value    = new StringValueNode("bar");

            // act
            var argument = new ArgumentNode(location, name, value);

            // assert
            Assert.Equal(SyntaxKind.Argument, argument.Kind);
            Assert.Equal(location, argument.Location);
            Assert.Equal(name, argument.Name);
            Assert.Equal(value, argument.Value);
        }
Exemple #10
0
        public void WithLocation()
        {
            // arrange
            var location = new Location(1, 1, 1, 1);
            var value    = new StringValueNode("abc");

            // act
            value = value.WithLocation(location);


            // assert
            Assert.Equal("abc", value.Value);
            Assert.False(value.Block);
            Assert.Equal(SyntaxKind.StringValue, value.Kind);
            Assert.Same(location, value.Location);
            Assert.Empty(value.GetNodes());
        }
Exemple #11
0
        public InputValueDefinitionNode(
            Location location,
            NameNode name,
            StringValueNode description,
            ITypeNode type,
            IValueNode defaultValue,
            IReadOnlyCollection <DirectiveNode> directives)
            : base(location, name, directives)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            Description  = description;
            Type         = type;
            DefaultValue = defaultValue;
        }
        public void DirectiveDefinition_ToString()
        {
            // arrange
            var name        = new NameNode("foo");
            var description = new StringValueNode("bar");
            var arguments   = new List <InputValueDefinitionNode>();
            var locations   = new List <NameNode> {
                new NameNode(DirectiveLocation.Field.ToString())
            };

            // act
            var directiveDefinition = new DirectiveDefinitionNode(
                null, name, description, true,
                arguments, locations);

            // assert
            directiveDefinition.ToString().MatchSnapshot();
        }
 public DirectiveDefinitionNode(
     Location location,
     NameNode name,
     StringValueNode description,
     bool isRepeatable,
     IReadOnlyList <InputValueDefinitionNode> arguments,
     IReadOnlyList <NameNode> locations)
 {
     Location = location;
     Name     = name
                ?? throw new ArgumentNullException(nameof(name));
     Description  = description;
     IsRepeatable = isRepeatable;
     Arguments    = arguments
                    ?? throw new ArgumentNullException(nameof(arguments));
     Locations = locations
                 ?? throw new ArgumentNullException(nameof(locations));
 }
Exemple #14
0
        /// <summary>
        /// Parses an enum value definitions.
        /// <see cref="EnumValueDefinitionNode" />:
        /// Description? EnumValue Directives[isConstant=true]?
        /// </summary>
        /// <param name="context">The parser context.</param>
        private EnumValueDefinitionNode ParseEnumValueDefinition(
            ParserContext context)
        {
            SyntaxToken          start       = context.Current;
            StringValueNode      description = ParseDescription(context);
            NameNode             name        = ParseName(context);
            List <DirectiveNode> directives  =
                ParseDirectives(context, true);
            Location location = context.CreateLocation(start);

            return(new EnumValueDefinitionNode
                   (
                       location,
                       name,
                       description,
                       directives
                   ));
        }
        public void StringArg()
        {
            // arrange
            byte[] sourceText = Encoding.UTF8.GetBytes(
                "{ a(b:\"Q3VzdG9tZXIteDE=\") }");

            // act
            var parser = new Utf8GraphQLParser(
                sourceText, ParserOptions.Default);
            DocumentNode document = parser.Parse();

            // assert
            StringValueNode value = Assert.IsType <StringValueNode>(
                document.Definitions.OfType <OperationDefinitionNode>().First()
                .SelectionSet.Selections.OfType <FieldNode>().First()
                .Arguments.First().Value);

            Assert.Equal("Q3VzdG9tZXIteDE=", value.Value);
        }
        public void WithDescription()
        {
            // arrange
            var name        = new NameNode("foo");
            var description = new StringValueNode("bar");
            var arguments   = new List <InputValueDefinitionNode>();
            var locations   = new List <NameNode>();

            var directiveDefinition = new DirectiveDefinitionNode(
                null, name, description, true,
                arguments, locations);

            // act
            directiveDefinition = directiveDefinition
                                  .WithDescription(new StringValueNode("qux"));

            // assert
            directiveDefinition.MatchSnapshot();
        }
        public void AsRepeatable()
        {
            // arrange
            var name        = new NameNode("foo");
            var description = new StringValueNode("bar");
            var arguments   = new List <InputValueDefinitionNode>();
            var locations   = new List <NameNode>();

            var directiveDefinition = new DirectiveDefinitionNode(
                null, name, description, false,
                arguments, locations);

            // act
            directiveDefinition = directiveDefinition
                                  .AsRepeatable();

            // assert
            directiveDefinition.MatchSnapshot();
        }
        /// <summary>
        /// Parses an enum value definitions.
        /// <see cref="EnumValueDefinitionNode" />:
        /// Description? EnumValue Directives[isConstant=true]?
        /// </summary>
        /// <param name="context">The parser context.</param>
        private EnumValueDefinitionNode ParseEnumValueDefinition()
        {
            TokenInfo start = Start();

            StringValueNode      description = ParseDescription();
            NameNode             name        = ParseName();
            List <DirectiveNode> directives  =
                ParseDirectives(true);

            Location location = CreateLocation(in start);

            return(new EnumValueDefinitionNode
                   (
                       location,
                       name,
                       description,
                       directives
                   ));
        }
        public void EnumTypeDefinitionWithoutValues_ArgumentNullException()
        {
            // arrange
            var location    = new Location(0, 0, 0, 0);
            var name        = new NameNode("foo");
            var description = new StringValueNode("bar");
            var directives  = new List <DirectiveNode>();

            // act
            Action a = () => new EnumTypeDefinitionNode(
                location,
                name,
                description,
                directives,
                null);

            // assert
            Assert.Throws <ArgumentNullException>(a);
        }
        public void CreateArgumentWithLocation()
        {
            // arrange
            var source = new Source("foo");
            var start  = new SyntaxToken(
                TokenKind.StartOfFile, 0, 0, 1, 1, null);
            var location = new Location(source, start, start);
            var name     = new NameNode("foo");
            var value    = new StringValueNode("bar");

            // act
            var argument = new ArgumentNode(location, name, value);

            // assert
            Assert.Equal(NodeKind.Argument, argument.Kind);
            Assert.Equal(location, argument.Location);
            Assert.Equal(name, argument.Name);
            Assert.Equal(value, argument.Value);
        }
Exemple #21
0
        /// <summary>
        /// Parses a scalar type definition.
        /// <see cref="ScalarTypeDefinitionNode" />:
        /// Description?
        /// scalar Name Directives[isConstant=true]?
        /// </summary>
        /// <param name="context">The parser context.</param>
        private static ScalarTypeDefinitionNode ParseScalarTypeDefinition(
            ParserContext context)
        {
            SyntaxToken     start       = context.Current;
            StringValueNode description = ParseDescription(context);

            context.ExpectScalarKeyword();
            NameNode             name       = ParseName(context);
            List <DirectiveNode> directives =
                ParseDirectives(context, true);
            Location location = context.CreateLocation(start);

            return(new ScalarTypeDefinitionNode
                   (
                       location,
                       name,
                       description,
                       directives
                   ));
        }
        private void WriteDescription(
            StringValueNode description,
            DocumentWriter writer)
        {
            if (description != null)
            {
                writer.WriteStringValue(description);

                if (_indent)
                {
                    writer.WriteLine();
                }
                else
                {
                    writer.WriteSpace();
                }

                WriteIndentation(writer);
            }
        }
        public ScalarTypeDefinitionNode(
            Location location,
            NameNode name,
            StringValueNode description,
            IReadOnlyCollection <DirectiveNode> directives)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

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

            Location    = location;
            Name        = name;
            Description = description;
            Directives  = directives;
        }
        public void EqualsIValueNode()
        {
            // arrange
            var a = new FloatValueNode(1.0);
            var b = new FloatValueNode(1.0);
            var c = new FloatValueNode(2.0);
            var d = new StringValueNode("foo");

            // act
            bool ab_result    = a.Equals((IValueNode)b);
            bool aa_result    = a.Equals((IValueNode)a);
            bool ac_result    = a.Equals((IValueNode)c);
            bool ad_result    = a.Equals((IValueNode)d);
            bool anull_result = a.Equals(default(IValueNode));

            // assert
            Assert.True(ab_result);
            Assert.True(aa_result);
            Assert.False(ac_result);
            Assert.False(ad_result);
            Assert.False(anull_result);
        }
Exemple #25
0
        public void EnumTypeDefinitionWithoutValues_ArgumentNullException()
        {
            // arrange
            var source = new Source("foo");
            var start  = new SyntaxToken(
                TokenKind.StartOfFile, 0, 0, 1, 1, null);
            var location    = new Location(source, start, start);
            var name        = new NameNode("foo");
            var description = new StringValueNode("bar");
            var directives  = new List <DirectiveNode>();

            // act
            Action a = () => new EnumTypeDefinitionNode(
                location,
                name,
                description,
                directives,
                null);

            // assert
            Assert.Throws <ArgumentNullException>(a);
        }
        internal Utf8GraphQLParser(
            Utf8GraphQLReader reader,
            ParserOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (reader.Kind == TokenKind.EndOfFile)
            {
                throw new ArgumentException(
                          LangResources.GraphQLData_Empty,
                          nameof(reader));
            }

            _options           = options;
            _createLocation    = !options.NoLocations;
            _allowFragmentVars = options.Experimental.AllowFragmentVariables;
            _reader            = reader;
            _description       = null;
        }
        public Utf8GraphQLParser(
            ReadOnlySpan <byte> graphQLData,
            ParserOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (graphQLData.Length == 0)
            {
                throw new ArgumentException(
                          LangResources.GraphQLData_Empty,
                          nameof(graphQLData));
            }

            _options           = options;
            _createLocation    = !options.NoLocations;
            _allowFragmentVars = options.Experimental.AllowFragmentVariables;
            _reader            = new Utf8GraphQLReader(graphQLData);
            _description       = null;
        }
        public void CreateDirectiveDefinition()
        {
            // arrange
            var name        = new NameNode("foo");
            var description = new StringValueNode("bar");
            var arguments   = new List <InputValueDefinitionNode>();
            var locations   = new List <NameNode>();

            // act
            var directiveDefinition = new DirectiveDefinitionNode(
                null, name, description, true,
                arguments, locations);

            // assert
            Assert.Equal(NodeKind.DirectiveDefinition,
                         directiveDefinition.Kind);
            Assert.Null(directiveDefinition.Location);
            Assert.Equal(name, directiveDefinition.Name);
            Assert.Equal(description, directiveDefinition.Description);
            Assert.Equal(arguments, directiveDefinition.Arguments);
            Assert.Equal(locations, directiveDefinition.Locations);
        }
        public void WithLocation()
        {
            // arrange
            var location    = new Location(0, 0, 0, 0);
            var name        = new NameNode("foo");
            var description = new StringValueNode("bar");
            var directives  = new List <DirectiveNode>();
            var values      = new List <EnumValueDefinitionNode>();

            var type = new EnumTypeDefinitionNode(
                null,
                name,
                description,
                directives,
                values);

            // act
            type = type.WithLocation(location);


            // assert
            Assert.Equal(location, type.Location);
        }
Exemple #30
0
        private InputObjectTypeDefinitionNode ParseInputObjectTypeDefinition(
            ParserContext context)
        {
            SyntaxToken     start       = context.Current;
            StringValueNode description = ParseDescription(context);

            context.ExpectInputKeyword();
            NameNode             name       = ParseName(context);
            List <DirectiveNode> directives =
                ParseDirectives(context, true);
            List <InputValueDefinitionNode> fields =
                ParseInputFieldsDefinition(context);
            Location location = context.CreateLocation(start);

            return(new InputObjectTypeDefinitionNode
                   (
                       location,
                       name,
                       description,
                       directives,
                       fields
                   ));
        }