part of graphql_schema.src.schema; /// `true` or `false`. final GraphQLScalarType graphQLBoolean = new _GraphQLBoolType(); /// A UTF‐8 character sequence. final GraphQLScalarType graphQLString = new _GraphQLStringType._(); /// The ID scalar type represents a unique identifier, often used to re-fetch an object or as the key for a cache. /// /// The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable. final GraphQLScalarType graphQLId = new _GraphQLStringType._('ID'); /// A [DateTime], serialized as an ISO-8601 string.. final GraphQLScalarType graphQLDate = new _GraphQLDateType._(); /// A signed 32‐bit integer. final GraphQLScalarType graphQLInt = new _GraphQLNumType( 'Int', 'A signed 64-bit integer.', (x) => x is int, 'an integer'); /// A signed double-precision floating-point value. final GraphQLScalarType graphQLFloat = new _GraphQLNumType( 'Float', 'A signed double-precision floating-point value.', (x) => x is double, 'a float'); abstract class GraphQLScalarType extends GraphQLType with _NonNullableMixin { Type get valueType => Value; } typedef bool _NumVerifier(x); class _GraphQLBoolType extends GraphQLScalarType { @override bool serialize(bool value) { return value; } @override String get name => 'Boolean'; @override String get description => 'A boolean value; can be either true or false.'; @override ValidationResult validate(String key, input) { if (input != null && input is! bool) return new ValidationResult._failure( ['Expected "$key" to be a boolean.']); return new ValidationResult._ok(input); } @override bool deserialize(bool serialized) { return serialized; } @override GraphQLType coerceToInputObject() => this; } class _GraphQLNumType extends GraphQLScalarType { final String name; final String description; final _NumVerifier verifier; final String expected; _GraphQLNumType(this.name, this.description, this.verifier, this.expected); @override ValidationResult validate(String key, input) { if (input != null && !verifier(input)) return new ValidationResult._failure( ['Expected "$key" to be $expected.']); return new ValidationResult._ok(input); } @override T deserialize(T serialized) { return serialized; } @override T serialize(T value) { return value; } @override GraphQLType coerceToInputObject() => this; } class _GraphQLStringType extends GraphQLScalarType { final String name; _GraphQLStringType._([this.name = 'String']); @override String get description => 'A character sequence.'; @override String serialize(String value) => value; @override String deserialize(String serialized) => serialized; @override ValidationResult validate(String key, input) => input == null || input is String ? new ValidationResult._ok(input) : new ValidationResult._failure(['Expected "$key" to be a string.']); @override GraphQLType coerceToInputObject() => this; } class _GraphQLDateType extends GraphQLScalarType with _NonNullableMixin { _GraphQLDateType._(); @override String get name => 'Date'; @override String get description => 'An ISO-8601 Date.'; @override String serialize(DateTime value) => value.toIso8601String(); @override DateTime deserialize(String serialized) => DateTime.parse(serialized); @override ValidationResult validate(String key, input) { if (input != null && input is! String) return new ValidationResult._failure( ['$key must be an ISO 8601-formatted date string.']); else if (input == null) return new ValidationResult._ok(input); try { DateTime.parse(input); return new ValidationResult._ok(input); } on FormatException { return new ValidationResult._failure( ['$key must be an ISO 8601-formatted date string.']); } } @override GraphQLType coerceToInputObject() => this; }