This repository has been archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
(question) Direction on implementing an Upload scalar #21
Comments
ryankauk
changed the title
(question) Was wondering if I could get some direction on implementing an Upload scalar
(question) Direction on implementing an Upload scalar
Aug 9, 2020
So, I just pushed some (hacky) changes to
A snippet of my schema:
path: savvy_app|lib/graphql/schema.graphql
imports:
- package:savvy_app/graphql/scalars/scalars.dart
- package:built_value/json_object.dart
exports:
- package:savvy_app/graphql/scalars/scalars.dart
- package:built_value/json_object.dart
convenienceSerializersFunction: withScalarSerializers
scalars:
# not sure if this is even necessary if you're not renaming but still good for documentation
MultipartFile: MultipartFile /// `savvy_app/graphql/scalars/scalars.dart`
class IsoDurationSerializer implements PrimitiveSerializer<Duration> {
@override
Duration deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
assert(
serialized is String,
"IsoDurationSerializer expected 'String' but got ${serialized.runtimeType}",
);
return parseIsoDuration(serialized as String);
}
@override
String serialize(
Serializers serializers,
Duration duration, {
FullType specifiedType = FullType.unspecified,
}) =>
toIsoString(duration);
@override
Iterable<Type> get types => [Duration];
@override
String get wireName => "Duration";
}
ConvenienceSerializers withScalarSerializers(Serializers serializers) =>
ConvenienceSerializers((serializers.toBuilder()
..addAll(<Serializer>[
IsoDurationSerializer(),
// MultipartFileSerializer(),
]))
.build()); Unrelatedly, it's also possible to provide your own custom models for object and input types: replaceTypes:
TemporalIdInput: TemporalId
irreducibleTypes:
- name: TemporalId
# whether or not you want built_value to generate a model
generate: false |
@ryankauk are you in the discord? https://discord.gg/tXTtBfC |
@micimize Perfect thank you I'll try this out. No I didn't realize there was one. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hey there, I have the graphql upload on my server and am wondering the best way to handle the serialization. It would essentially be a MultipartFile, but I'm not sure where I need to return this with built_value usage. Any help would be appreciated!
The text was updated successfully, but these errors were encountered: