This repository has been archived by the owner on Sep 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Error compiling generated Dart File #5
Comments
@fvisticot I take it this means you've gotten passed #3? You'll have to provide your own custom scalars somehow, with either imports:
- "./scalars.dart"
parts:
- "./base.dart"
- "./graphql.g.dart"
scalars:
# to just get things of the ground I'd start adding aliases here.
# I'm not sure if `dynamic` will work, but `Object` is safer anyhow
I18n: Object |
Here's a complete example based on this schema: "<url_gate>/graphql"
documents:
overwrite: true
generates:
lib/serializers/graphql.dart:
plugins:
- graphql-to-dart
config:
scalars:
# to just get things of the ground I'd start adding aliases here.
# I'm not sure if `dynamic` will work, but `Object` is safer anyhow
# this could be String, but it all depends on what's coming over the wire
I18n: Object If you had a "scalar" that was actually a representation of a complex type, like a postgres datetime with class PGDateTime {
bool isInfinity = false;
DateTime value;
// value xor isInfinity
PGDateTime({
this.value,
this.isInfinity = false,
}) : assert((value != null || isInfinity == true) &&
!(value != null && isInfinity == true));
static PGDateTime parse(String formattedString) {
return formattedString == 'infinity'
? PGDateTime.infinity()
: PGDateTime(value: DateTime.parse(formattedString).toLocal());
}
PGDateTime.infinity() {
isInfinity = true;
}
PGDateTime.now() {
value = DateTime.now();
isInfinity = false;
}
PGDateTime.fromDateTime(this.value) : isInfinity = false;
String toJson() {
return isInfinity == true ? 'infinity' : value.toUtc().toIso8601String();
}
int compareTo(PGDateTime other) {
if (isInfinity) return other.isInfinity ?? false ? 0 : 1;
if (other.isInfinity) return -1;
return value.compareTo(other.value);
}
bool operator ==(dynamic other) =>
(other is PGDateTime && compareTo(other) == 0) ||
(other is DateTime && value == other) ||
(other == 'infinity' && this.isInfinity);
// TODO idk if this is idiomatic, but the thinking is that the identity of the wrapper
// is the same as that of it's contents
int get hashCode => isInfinity ? 'infinity'.hashCode : value.hashCode;
String toString() {
return 'PGDateTime(${isInfinity ? "infinity" : value.toString()})';
}
}
PGDateTime fromJsonToPGDateTime(String value) {
return PGDateTime.parse(value);
}
String fromPGDateTimeToJson(PGDateTime value) {
return value.toJson();
} and then the schema: "<url_gate>/graphql"
documents:
overwrite: true
generates:
lib/serializers/graphql.dart:
plugins:
- graphql-to-dart
config:
imports:
- "./scalars.dart"
scalars:
Datetime: PGDateTime |
hmm, will have to add a configuration option for this case. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I get an error when compiling the Dart file with command:
flutter packages pub run build_runner build
Error:
Error seems due to the following Schema information with Scalar type
scalar I18n
The text was updated successfully, but these errors were encountered: