Comments (4)
@fvisticot I take it this means you've gotten passed #3?
You'll have to provide your own custom scalars somehow, with either imports
, parts
, or in the scalars
map.
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
from graphql-to-dart.
Here's a complete example based on this codegen.yml
:
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 infinity
representation support you could make a lib/serializers/scalars.dart
:
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 codegen.yml
:
schema: "<url_gate>/graphql"
documents:
overwrite: true
generates:
lib/serializers/graphql.dart:
plugins:
- graphql-to-dart
config:
imports:
- "./scalars.dart"
scalars:
Datetime: PGDateTime
from graphql-to-dart.
Tx a lot.
Some progress, I18n is fixed.
New pb:
My schema includes property with underscore and I get error:
Optional can not start with underscore.
Any idea to fix this issue ? I can not touch to this model :(
MyObject({
@required this.id,
@required this._id,
this.title,
from graphql-to-dart.
hmm, will have to add a configuration option for this case.
Probably transformUnderscores: drop | strip | { { prefix: "str" }
Closing this in favor of #6 - will probably be a minute before I get to it though
from graphql-to-dart.
Related Issues (20)
- Optional can not start with underscore. HOT 1
- Override schema types of specific fields with custom scalars HOT 3
- Include documents in output HOT 2
- generating example file from schema
- because of helpers like .empty(), having invalid types is easy. We should validate not null somehow HOT 3
- Non nullable fields in graphql vs required fields in models HOT 5
- Cannot install HOT 1
- leverage equatable or other value-based equivalence
- Problem with aliases (on master) HOT 3
- Union Type Does Not Convert HOT 6
- Inline fragments are broken, unions won't be deserialized HOT 5
- Document using fragment causing issues when expanding fields that already exist in fragment HOT 2
- Discussion: Bake gql inside of a more global operation class HOT 1
- fragment merging HOT 1
- eventually switch to built value
- merge should map only to base types, base type methods should be respected HOT 3
- toJson() should not include items which were not set HOT 1
- Feature Request: fromJson() constructor HOT 1
- Code Generation Error "undefined_class" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-to-dart.