Beispiel #1
0
        public override object ParseLiteral(IValueNode literal)
        {
            if (literal == null)
            {
                throw new ArgumentNullException(nameof(literal));
            }

            if (literal is StringValueNode stringLiteral)
            {
                if (!NameUtils.IsValidGraphQLName(stringLiteral.Value))
                {
                    throw new ScalarSerializationException(
                              string.Format(CultureInfo.InvariantCulture,
                                            AbstractionResources.Type_NameIsNotValid,
                                            stringLiteral.Value ?? "null"));
                }
                return(new NameString(stringLiteral.Value));
            }

            if (literal is NullValueNode)
            {
                return(null);
            }

            throw new ScalarSerializationException(
                      TypeResourceHelper.Scalar_Cannot_ParseLiteral(
                          Name, literal.GetType()));
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameString"/> struct.
 /// </summary>
 /// <param name="value">The actual type name string</param>
 /// <exception cref="ArgumentException"></exception>
 public NameString(string value)
 {
     if (!NameUtils.IsValidGraphQLName(value))
     {
         throw new ArgumentException(
                   string.Format(CultureInfo.InvariantCulture,
                                 AbstractionResources.Type_NameIsNotValid,
                                 value ?? "null"),
                   nameof(value));
     }
     Value = value;
 }
Beispiel #3
0
        public override bool IsInstanceOfType(IValueNode literal)
        {
            if (literal == null)
            {
                throw new ArgumentNullException(nameof(literal));
            }

            if (literal is NullValueNode)
            {
                return(true);
            }

            return(literal is StringValueNode s &&
                   NameUtils.IsValidGraphQLName(s.Value));
        }
        private IReadOnlyList <GraphQLConfig> GetGraphQLConfigs(
            GeneratorExecutionContext context)
        {
            var list = new List <GraphQLConfig>();

            foreach (var configLocation in GetGraphQLConfigFiles(context))
            {
                try
                {
                    string json   = File.ReadAllText(configLocation);
                    var    config = JsonConvert.DeserializeObject <GraphQLConfig>(json);

                    if (NameUtils.IsValidGraphQLName(config.Extensions.StrawberryShake.Name))
                    {
                        config.Location = configLocation;
                        list.Add(config);
                    }
                    else
                    {
                        ReportInvalidClientName(
                            context,
                            config.Extensions.StrawberryShake.Name,
                            configLocation);
                    }
                }
                catch (Exception ex)
                {
                    throw new GraphQLException(
                              ErrorBuilder.New()
                              .SetMessage(ex.Message)
                              .SetException(ex)
                              .SetExtension(ErrorHelper.FileExtensionKey, configLocation)
                              .AddLocation(new HotChocolate.Location(1, 1))
                              .Build());
                }
            }

            return(list);
        }
Beispiel #5
0
 protected override bool IsInstanceOfType(StringValueNode valueSyntax)
 {
     return(NameUtils.IsValidGraphQLName(valueSyntax.AsSpan()));
 }
Beispiel #6
0
 protected override bool IsInstanceOfType(StringValueNode literal)
 {
     return(NameUtils.IsValidGraphQLName(literal.AsSpan()));
 }