Skip to content

Commit bddb0e7

Browse files
authored
fix: Don't remove when. (#361)
1 parent f44da83 commit bddb0e7

6 files changed

Lines changed: 501 additions & 50 deletions

File tree

packages/graphql_codegen/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.1
2+
3+
- Don't remove `when` and `maybeWhen` when `disableCopyWithGeneration = true`.
4+
15
# 1.0.0
26

37
- Supports `@oneOf` directive on input.

packages/graphql_codegen/example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ packages:
342342
path: ".."
343343
relative: true
344344
source: path
345-
version: "1.0.0"
345+
version: "1.0.1"
346346
graphql_flutter:
347347
dependency: "direct main"
348348
description:

packages/graphql_codegen/lib/src/printer/base/document.dart

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ Class printContext(PrintContext c) {
151151
List<Spec> printContextExtension(PrintContext c) {
152152
final context = c.context;
153153

154-
if (context.config.disableCopyWithGeneration) {
155-
return [];
156-
}
157-
158154
final properties = c.context.properties;
159155

160156
final whenMethod = _printWhen(
@@ -168,26 +164,29 @@ List<Spec> printContextExtension(PrintContext c) {
168164
context.typenameProperty,
169165
context.possibleTypes,
170166
);
171-
167+
final methods = [
168+
if (!context.config.disableCopyWithGeneration)
169+
_printCopyWithMethod(
170+
c.namePrinter.printClassName(context.path),
171+
c,
172+
),
173+
if (whenMethod != null) whenMethod,
174+
if (maybeWhenMethod != null) maybeWhenMethod,
175+
];
172176
return [
173-
Extension(
174-
(b) => b
175-
..name = c.namePrinter.printClassExtensionName(context.path)
176-
..on = refer(c.namePrinter.printClassName(context.path))
177-
..methods = ListBuilder([
178-
_printCopyWithMethod(
179-
c.namePrinter.printClassName(context.path),
180-
c,
181-
),
182-
if (whenMethod != null) whenMethod,
183-
if (maybeWhenMethod != null) maybeWhenMethod,
184-
]),
185-
),
186-
...printCopyWithClasses(
187-
c,
188-
c.namePrinter.printClassName(context.path),
189-
properties,
190-
),
177+
if (methods.isNotEmpty)
178+
Extension(
179+
(b) => b
180+
..name = c.namePrinter.printClassExtensionName(context.path)
181+
..on = refer(c.namePrinter.printClassName(context.path))
182+
..methods = ListBuilder(methods),
183+
),
184+
if (!context.config.disableCopyWithGeneration)
185+
...printCopyWithClasses(
186+
c,
187+
c.namePrinter.printClassName(context.path),
188+
properties,
189+
),
191190
];
192191
}
193192

packages/graphql_codegen/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: |
33
Simple, opinionated, codegen library for GraphQL. It allows you to
44
generate serializers and client helpers to easily call and parse your data.
55
6-
version: 1.0.0
6+
version: 1.0.1
77
homepage: https://github.com/heftapp/graphql_codegen/tree/main/packages/graphql_codegen
88
repository: https://github.com/heftapp/graphql_codegen/tree/main/packages/graphql_codegen
99

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
scalar DateTime
22

3-
type Query {
3+
input DataQuery {
44
time: DateTime
55
}
66

7-
query FetchScalars {
8-
time
7+
type Query {
8+
data(input: DataQuery): I
99
}
1010

11-
input CreateScalar {
12-
time: DateTime
11+
12+
interface I {
13+
value: String
14+
}
15+
16+
type A implements I {
17+
value: String
18+
}
19+
20+
type B implements I {
21+
value: String
1322
}
23+
24+
25+
fragment FA on A {
26+
value
27+
}
28+
29+
fragment FB on B {
30+
value
31+
}
32+
33+
query FetchScalars {
34+
data {
35+
...FA
36+
...FB
37+
}
38+
}
39+

0 commit comments

Comments
 (0)