platform/packages/graphql/angel_graphql/lib/angel_graphql.dart

47 lines
1.4 KiB
Dart
Raw Permalink Normal View History

2019-08-14 02:50:04 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:graphql_schema/graphql_schema.dart';
2018-08-02 17:02:00 +00:00
export 'src/graphiql.dart';
export 'src/graphql_http.dart';
2019-04-18 00:52:26 +00:00
export 'src/graphql_ws.dart';
2018-08-04 19:18:53 +00:00
export 'src/resolvers.dart';
2019-08-14 02:50:04 +00:00
/// The canonical [GraphQLUploadType] instance.
final GraphQLUploadType graphQLUpload = GraphQLUploadType();
/// A [GraphQLScalarType] that is used to read uploaded files from
/// `multipart/form-data` requests.
class GraphQLUploadType extends GraphQLScalarType<UploadedFile, UploadedFile> {
@override
String get name => 'Upload';
@override
String get description =>
'Represents a file that has been uploaded to the server.';
@override
GraphQLType<UploadedFile, UploadedFile> coerceToInputObject() => this;
@override
UploadedFile deserialize(UploadedFile serialized) => serialized;
@override
UploadedFile serialize(UploadedFile value) => value;
@override
ValidationResult<UploadedFile> validate(String key, UploadedFile input) {
if (input != null && input is! UploadedFile) {
return _Vr(false, errors: ['Expected "$key" to be a boolean.']);
}
return _Vr(true, value: input);
}
}
// TODO: Really need to make the validation result constructors *public*
class _Vr<T> implements ValidationResult<T> {
final bool successful;
final List<String> errors;
final T value;
_Vr(this.successful, {this.errors, this.value});
}