diff --git a/angel_graphql/lib/angel_graphql.dart b/angel_graphql/lib/angel_graphql.dart index 7673a86e..780cc100 100644 --- a/angel_graphql/lib/angel_graphql.dart +++ b/angel_graphql/lib/angel_graphql.dart @@ -1,4 +1,46 @@ +import 'package:angel_framework/angel_framework.dart'; +import 'package:graphql_schema/graphql_schema.dart'; export 'src/graphiql.dart'; export 'src/graphql_http.dart'; export 'src/graphql_ws.dart'; export 'src/resolvers.dart'; + +/// 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 { + @override + String get name => 'Upload'; + + @override + String get description => + 'Represents a file that has been uploaded to the server.'; + + @override + GraphQLType coerceToInputObject() => this; + + @override + UploadedFile deserialize(UploadedFile serialized) => serialized; + + @override + UploadedFile serialize(UploadedFile value) => value; + + @override + ValidationResult 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 implements ValidationResult { + final bool successful; + final List errors; + final T value; + + _Vr(this.successful, {this.errors, this.value}); +}