Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/graphql_codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.13.6

- Fix bad copy class on list with default value.

# 0.13.5

- Run builder before `json_serializable`
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql_codegen/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.13.5"
version: "0.13.6"
graphql_flutter:
dependency: "direct main"
description:
Expand Down
4 changes: 4 additions & 0 deletions packages/graphql_codegen/lib/src/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:gql/ast.dart';
import 'package:graphql_codegen/src/context/schema.dart';
import 'package:graphql_codegen/src/config/config.dart';
import 'package:graphql_codegen/src/errors.dart';
import 'package:graphql_codegen/src/printer/base/utils.dart';
import 'package:graphql_codegen/src/transform/add_typename_transforming_visitor.dart';

import 'name.dart';
Expand Down Expand Up @@ -161,6 +162,9 @@ class ContextProperty {
final List<DirectiveNode> fieldDirectives;
final bool hasDefaultValue;

TypeNode get nullableTypeOnDefaultValue =>
hasDefaultValue ? typeNodeAsNullable(type) : type;

NameNode get name => alias ?? _name;

ContextProperty({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Method? _printDeepCopyTypeNode(
ContextProperty property,
bool abstract,
) {
final node = property.type;
final node = property.nullableTypeOnDefaultValue;
final namePrinter = printContext.namePrinter;
final propertyName = namePrinter.printPropertyName(property.name);
final copyClassName = namePrinter.printCopyWithClassName(
Expand Down
25 changes: 2 additions & 23 deletions packages/graphql_codegen/lib/src/printer/base/equality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ import 'package:graphql_codegen/src/printer/context.dart';

typedef DataObjResolver = Expression Function();

TypeNode _typeNodeAsNullable(TypeNode node) {
if (!node.isNonNull) {
return node;
}
if (node is ListTypeNode) {
return ListTypeNode(
type: node.type,
isNonNull: false,
);
}
if (node is NamedTypeNode) {
return NamedTypeNode(
name: node.name,
isNonNull: false,
);
}
return node;
}

Method printEqualityOperator(
PrintContext c,
String name,
Expand Down Expand Up @@ -72,7 +53,7 @@ Method printEqualityOperator(
),
],
_printPropertyEqualityCheck(
e.hasDefaultValue ? _typeNodeAsNullable(e.type) : e.type,
e.nullableTypeOnDefaultValue,
localThisName,
localOtherName,
)
Expand Down Expand Up @@ -142,9 +123,7 @@ Method printHashCodeMethod(
final localProp = context.namePrinter
.printLocalPropertyName(property.name);
final hash = _printPropertyHash(
property.hasDefaultValue
? _typeNodeAsNullable(property.type)
: property.type,
property.nullableTypeOnDefaultValue,
refer(localProp),
);
if (dataObjectCheckResolver != null &&
Expand Down
20 changes: 20 additions & 0 deletions packages/graphql_codegen/lib/src/printer/base/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:gql/ast.dart';

TypeNode typeNodeAsNullable(TypeNode node) {
if (!node.isNonNull) {
return node;
}
if (node is ListTypeNode) {
return ListTypeNode(
type: node.type,
isNonNull: false,
);
}
if (node is NamedTypeNode) {
return NamedTypeNode(
name: node.name,
isNonNull: false,
);
}
return node;
}
2 changes: 1 addition & 1 deletion packages/graphql_codegen/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: |
Simple, opinionated, codegen library for GraphQL. It allows you to
generate serializers and client helpers to easily call and parse your data.

version: 0.13.5
version: 0.13.6
homepage: https://github.com/heftapp/graphql_codegen/tree/main/packages/graphql_codegen
repository: https://github.com/heftapp/graphql_codegen/tree/main/packages/graphql_codegen

Expand Down
19 changes: 19 additions & 0 deletions packages/graphql_codegen/test/assets/issue_309/document.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
input TemplateDisciplineTopicContentInput {
howStudyIt: String!
infoContentBlocks: [I1!]!
taskContentBlocks: [I2!]
testContentBlocks: [I3!]! = []
whyStudyIt: String!
}

input I1 {
data: String
}

input I2 {
data: String
}

input I3 {
data: String
}
Loading