graphql-to-dart
graphql-to-dart copied to clipboard
toJson() should not include items which were not set
final testInput = CreateTestInput(fkID: '123', color: 'red');
print('${createTestInput.toJson()}');
// This prints { fkID: 123, color: red, otherAttr: null, id: null, ...}
This becomes a problem when trying to use this library with https://github.com/zino-app/graphql-flutter because in most cases you don't want to explicitly null things out.
Workaround:
final newItemResult = await client.mutate(MutationOptions(
documentNode: gql(mutationString),
variables: { 'input': createTestInput.toJson()
..removeWhere((_, dynamic val) => val == null) // remove the null items
}));
I've been rewriting graphql-to-dart
as built-graphql
recently, for which nulls will be excluded by default.