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())); }
/// <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; }
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); }
protected override bool IsInstanceOfType(StringValueNode valueSyntax) { return(NameUtils.IsValidGraphQLName(valueSyntax.AsSpan())); }
protected override bool IsInstanceOfType(StringValueNode literal) { return(NameUtils.IsValidGraphQLName(literal.AsSpan())); }