micimize / graphql-to-dart

generate dart classes and respective JsonSerializable transcoders
42 stars 8 forks source link

don't use required fields for magic types #13

Closed PeterZainzinger closed 5 years ago

PeterZainzinger commented 5 years ago

We accoutered another problem with the dart types. Consider the following graphql definition:

type Query {
  getFoo(id: String!): String
  getBar(id: String!): String
}

The generated code will be:

class Query {
     @JsonKey(required: true, disallowNullValue: true,)
    String getFoo;

     @JsonKey(required: true, disallowNullValue: true,)
    String getBar;

....

}

The required JsonKeys are a problem in this case because we query getFoo XOR getBar, so the fromJSON will throw an error.

My workaround is just to make all fields in the types Query, Mutation and Subscription non required.

micimize commented 5 years ago

published 👍