Exemplo n.º 1
0
        public object ParseLiteral(GraphQLScalarValue input)
        {
            if (input.Kind == ASTNodeKind.NullValue)
            {
                return(null);
            }

            if (input.Kind == ASTNodeKind.BooleanValue)
            {
                var value = input.Value;

                if (value == null)
                {
                    return(null);
                }

                if (string.Equals("0", value, StringComparison.Ordinal))
                {
                    return(false);
                }

                if (string.Equals("1", value, StringComparison.Ordinal))
                {
                    return(true);
                }

                return(Convert.ToBoolean(input.Value, NumberFormatInfo.InvariantInfo));
            }

            throw new FormatException(
                      $"Cannot coerce Bool value from '{input.Kind}'");
        }
Exemplo n.º 2
0
        public override GraphQLScalarValue BeginVisitIntValue(GraphQLScalarValue value)
        {
            {
                Tracker.EnterIntValue?.Invoke(value);
            }

            return(base.BeginVisitIntValue(value));
        }
 public void Values_Parse_Successfully(ASTNodeKind kind, string valueString)
 {
     //note: thousand separators and/or culture-specific characters are invalid graphql literals, and will not be returned by graphql-parser
     //uppercase TRUE and FALSE are also invalid graphql input data, and will not be returned by graphql-parser
     //whitespace will not be returned by graphql-parser
     var converter = new CoreToVanillaConverter("");
     var value     = new GraphQLScalarValue(kind)
     {
         Value = valueString
     };
     var ret = converter.Value(value);
 }
Exemplo n.º 4
0
        public void ParseLiteral(string input, long expected)
        {
            /* Given */
            var astValue = new GraphQLScalarValue(ASTNodeKind.IntValue)
            {
                Value = input
            };

            /* When */
            var actual = _sut.ParseLiteral(astValue);

            /* Then */
            Assert.Equal(expected, actual);
        }
Exemplo n.º 5
0
        public object ParseLiteral(GraphQLScalarValue input)
        {
            if (input.Kind == ASTNodeKind.NullValue)
            {
                return(null);
            }

            if (input.Kind == ASTNodeKind.StringValue)
            {
                return(input.Value);
            }

            throw new FormatException(
                      $"Cannot coerce Long value from '{input.Kind}'");
        }
Exemplo n.º 6
0
        public override GraphQLScalarValue BeginVisitEnumValue(GraphQLScalarValue value)
        {
            {
                Tracker.EnterEnumValue?.Invoke(value);
            }

            var _ = base.BeginVisitEnumValue(value);


            {
                Tracker.LeaveEnumValue?.Invoke(value);
            }

            return(_);
        }
Exemplo n.º 7
0
        public object ParseLiteral(GraphQLScalarValue input)
        {
            if (input.Kind == ASTNodeKind.NullValue)
            {
                return(null);
            }

            if (input.Kind == ASTNodeKind.FloatValue || input.Kind == ASTNodeKind.IntValue)
            {
                if (input.Value == null)
                {
                    return(null);
                }

                return(Convert.ToDouble(input.Value, NumberFormatInfo.InvariantInfo));
            }

            throw new FormatException(
                      $"Cannot coerce Long value from '{input.Kind}'");
        }
Exemplo n.º 8
0
        public object ParseLiteral(GraphQLScalarValue input)
        {
            if (input.Kind == ASTNodeKind.NullValue)
            {
                return(null);
            }

            if (input.Kind == ASTNodeKind.IntValue)
            {
                if (input.Value == null)
                {
                    return(null);
                }

                return(Convert.ToInt64(input.Value));
            }

            throw new FormatException(
                      $"Cannot coerce Long value from '{input.Kind}'");
        }
Exemplo n.º 9
0
        public void ParseLiteral(string input, string expected)
        {
            /* Given */
            var astValue = new GraphQLScalarValue(ASTNodeKind.EnumValue)
            {
                Value = input
            };

            var Enum = new EnumType("TestResult", new EnumValues
            {
                ["SUCCESS"]      = null,
                ["FAILURE"]      = null,
                ["INCONCLUSIVE"] = null
            });

            /* When */
            var actual = Enum.ParseLiteral(astValue);

            /* Then */
            Assert.Equal(expected, actual);
        }
Exemplo n.º 10
0
        internal void Resolve(GraphQLDocument doc, IGraphQLType rootType, GraphQLScalarValue specifiedTypeName = null)
        {
            this.RootType = rootType;

            foreach (FieldSelection f in this.Fields)
            {
                f.Resolve(doc, rootType as IGraphQLFieldCollection);
            }

            foreach (SetSelection f in this.inlineFragments)
            {
                IGraphQLType root = doc.ResolveType(f.TypeCondition);
                f.Resolve(doc, root);
                this.fragments.Add(f);
            }

            // do these after the inline fragments as they have been pre-resolved
            foreach (GraphQLName name in this.fragmentNames)
            {
                var fragmentRoot = doc.ResolveType(name.Value) as FragmentType;
                this.fragmentsItems.Add(fragmentRoot);
                this.fragments.Add(fragmentRoot.Selection);
            }

            // merge fields from fragments into root object
            foreach (SetSelection f in this.fragments)
            {
                var currentFieldRefs = fields.Select(x => x.UniqueIdentifier);
                var newFields        = f.Fields.Where(x => !currentFieldRefs.Contains(x.UniqueIdentifier));
                fields.AddRange(newFields);
            }

            this.SpecifiedTypeName = specifiedTypeName;

            this.UniqueIdentifier = $"{this.TypeCondition?.Name?.Value}_{rootType?.Name}_{string.Join("|", this.Fields.Select(x => x.UniqueIdentifier))}_{string.Join("|", this.fragments.Select(x => x.UniqueIdentifier))}";
        }
Exemplo n.º 11
0
 public virtual GraphQLScalarValue BeginVisitBooleanValue(GraphQLScalarValue value) => value;
Exemplo n.º 12
0
        public object ParseLiteral(GraphQLScalarValue input)
        {
            var value = _values.SingleOrDefault(v => v.Key == input.Value?.ToUpperInvariant());

            return(value.Key);
        }
Exemplo n.º 13
0
 public virtual GraphQLScalarValue BeginVisitEnumValue(GraphQLScalarValue value)
 {
     return(value);
 }
Exemplo n.º 14
0
 public virtual GraphQLScalarValue BeginVisitBooleanValue(GraphQLScalarValue value)
 {
     return(value);
 }
Exemplo n.º 15
0
 private string PrintNullValue(GraphQLScalarValue node)
 {
     return("null");
 }
Exemplo n.º 16
0
 private string PrintBooleanValue(GraphQLScalarValue node)
 {
     return(node.Value);
 }
Exemplo n.º 17
0
 public virtual GraphQLScalarValue BeginVisitStringValue(GraphQLScalarValue value) => value;
Exemplo n.º 18
0
 public virtual GraphQLScalarValue BeginVisitFloatValue(GraphQLScalarValue value) => value;
Exemplo n.º 19
0
 private string PrintIntValue(GraphQLScalarValue node)
 {
     return(node.Value);
 }
Exemplo n.º 20
0
 public virtual GraphQLScalarValue BeginVisitEnumValue(GraphQLScalarValue value) => value;
Exemplo n.º 21
0
 private string PrintStringValue(GraphQLScalarValue node)
 {
     return($"\"{node.Value}\"");
 }
Exemplo n.º 22
0
 public object ParseLiteral(GraphQLScalarValue input)
 {
     return(Converter.ParseLiteral(input));
 }