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.12.0-beta.10

* Provide default typename parameter to constructor

# 0.12.0-beta.9

* Support schema extensions.
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql_codegen/example/lib/fragments.graphql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Fragment$PersonSummary {
this.eventsOfEvents,
this.parents,
this.favParent,
required this.$__typename,
this.$__typename = 'Person',
});

factory Fragment$PersonSummary.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -470,7 +470,7 @@ extension ClientExtension$Fragment$PersonSummary on graphql.GraphQLClient {
class Fragment$PersonParent {
Fragment$PersonParent({
required this.name,
required this.$__typename,
this.$__typename = 'Person',
});

factory Fragment$PersonParent.fromJson(Map<String, dynamic> json) {
Expand Down
14 changes: 7 additions & 7 deletions packages/graphql_codegen/example/lib/main.graphql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class _CopyWithStubImpl$Variables$Query$FetchPerson<TRes>
class Query$FetchPerson {
Query$FetchPerson({
this.fetchPerson,
required this.$__typename,
this.$__typename = 'Query',
});

factory Query$FetchPerson.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -461,7 +461,7 @@ class Query$FetchPerson$fetchPerson implements Fragment$PersonSummary {
this.eventsOfEvents,
this.parents,
this.favParent,
required this.$__typename,
this.$__typename = 'Person',
this.children,
});

Expand Down Expand Up @@ -846,7 +846,7 @@ class Query$FetchPerson$fetchPerson$parents
implements Fragment$PersonParent, Fragment$PersonSummary {
Query$FetchPerson$fetchPerson$parents({
required this.name,
required this.$__typename,
this.$__typename = 'Person',
this.nickname,
this.dob,
this.events,
Expand Down Expand Up @@ -1278,7 +1278,7 @@ class _CopyWithStubImpl$Variables$Mutation$UpdatePerson<TRes>
class Mutation$UpdatePerson {
Mutation$UpdatePerson({
this.updatePerson,
required this.$__typename,
this.$__typename = 'Mutation',
});

factory Mutation$UpdatePerson.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -1669,7 +1669,7 @@ class Mutation$UpdatePerson$Widget
class Mutation$UpdatePerson$updatePerson {
Mutation$UpdatePerson$updatePerson({
required this.full_name,
required this.$__typename,
this.$__typename = 'Person',
});

factory Mutation$UpdatePerson$updatePerson.fromJson(
Expand Down Expand Up @@ -1900,7 +1900,7 @@ class _CopyWithStubImpl$Variables$Subscription$WatchPerson<TRes>
class Subscription$WatchPerson {
Subscription$WatchPerson({
this.watchPerson,
required this.$__typename,
this.$__typename = 'Subscription',
});

factory Subscription$WatchPerson.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -2193,7 +2193,7 @@ class Subscription$WatchPerson$Widget
class Subscription$WatchPerson$watchPerson {
Subscription$WatchPerson$watchPerson({
required this.full_name,
required this.$__typename,
this.$__typename = 'Person',
});

factory Subscription$WatchPerson$watchPerson.fromJson(
Expand Down
17 changes: 12 additions & 5 deletions packages/graphql_codegen/lib/src/printer/base/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,18 @@ Constructor _printConstructor(
[
...properties.map<Parameter>(
(p) => Parameter(
(b) => b
..required = p.isRequired
..named = true
..toThis = true
..name = c.namePrinter.printPropertyName(p.name),
(b) {
final defaultTo = p.isTypenameField &&
c.context.currentType is ObjectTypeDefinitionNode
? literalString(c.context.currentTypeName.value).code
: null;
b
..required = p.isRequired && defaultTo == null
..named = true
..toThis = true
..defaultTo = defaultTo
..name = c.namePrinter.printPropertyName(p.name);
},
),
),
],
Expand Down
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.12.0-beta.9
version: 0.12.0-beta.10
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:gql/ast.dart';
class Fragment$FReport {
Fragment$FReport({
this.title,
required this.$__typename,
this.$__typename = 'Report',
});

factory Fragment$FReport.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -156,7 +156,7 @@ class Query$Q {
this.docsWihtoutTypename,
this.docsWithAliasedTypename,
this.docsWithFragment,
required this.$__typename,
this.$__typename = 'Query',
});

factory Query$Q.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -705,7 +705,7 @@ class _CopyWithStubImpl$Query$Q$docsWithTypename<TRes>
}

class Query$Q$docsWithTypename$$Contract implements Query$Q$docsWithTypename {
Query$Q$docsWithTypename$$Contract({required this.$__typename});
Query$Q$docsWithTypename$$Contract({this.$__typename = 'Contract'});

factory Query$Q$docsWithTypename$$Contract.fromJson(
Map<String, dynamic> json) {
Expand Down Expand Up @@ -799,7 +799,7 @@ class _CopyWithStubImpl$Query$Q$docsWithTypename$$Contract<TRes>
}

class Query$Q$docsWithTypename$$Report implements Query$Q$docsWithTypename {
Query$Q$docsWithTypename$$Report({required this.$__typename});
Query$Q$docsWithTypename$$Report({this.$__typename = 'Report'});

factory Query$Q$docsWithTypename$$Report.fromJson(Map<String, dynamic> json) {
final l$$__typename = json['__typename'];
Expand Down Expand Up @@ -1026,7 +1026,7 @@ class Query$Q$docsWihtoutTypename$$Contract
implements Query$Q$docsWihtoutTypename {
Query$Q$docsWihtoutTypename$$Contract({
this.title,
required this.$__typename,
this.$__typename = 'Contract',
});

factory Query$Q$docsWihtoutTypename$$Contract.fromJson(
Expand Down Expand Up @@ -1152,7 +1152,7 @@ class Query$Q$docsWihtoutTypename$$Report
implements Query$Q$docsWihtoutTypename {
Query$Q$docsWihtoutTypename$$Report({
this.title,
required this.$__typename,
this.$__typename = 'Report',
});

factory Query$Q$docsWihtoutTypename$$Report.fromJson(
Expand Down Expand Up @@ -1659,7 +1659,7 @@ class _CopyWithStubImpl$Query$Q$docsWithFragment<TRes>
class Query$Q$docsWithFragment$$Contract implements Query$Q$docsWithFragment {
Query$Q$docsWithFragment$$Contract({
this.title,
required this.$__typename,
this.$__typename = 'Contract',
});

factory Query$Q$docsWithFragment$$Contract.fromJson(
Expand Down Expand Up @@ -1785,7 +1785,7 @@ class Query$Q$docsWithFragment$$Report
implements Fragment$FReport, Query$Q$docsWithFragment {
Query$Q$docsWithFragment$$Report({
this.title,
required this.$__typename,
this.$__typename = 'Report',
});

factory Query$Q$docsWithFragment$$Report.fromJson(Map<String, dynamic> json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const documentNodeFragmentCondition = DocumentNode(definitions: [
class Fragment$Condition$$AndCondition implements Fragment$Condition {
Fragment$Condition$$AndCondition({
required this.name,
required this.$__typename,
this.$__typename = 'AndCondition',
});

factory Fragment$Condition$$AndCondition.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -289,7 +289,7 @@ class _CopyWithStubImpl$Fragment$Condition$$AndCondition<TRes>
class Fragment$Condition$$TimeCondition implements Fragment$Condition {
Fragment$Condition$$TimeCondition({
required this.name,
required this.$__typename,
this.$__typename = 'TimeCondition',
});

factory Fragment$Condition$$TimeCondition.fromJson(
Expand Down Expand Up @@ -417,7 +417,7 @@ class Fragment$AndCondition implements Fragment$Condition$$AndCondition {
required this.left,
required this.right,
required this.name,
required this.$__typename,
this.$__typename = 'AndCondition',
});

factory Fragment$AndCondition.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -842,7 +842,7 @@ class Fragment$CompositeCondition$$AndCondition
required this.left,
required this.right,
required this.name,
required this.$__typename,
this.$__typename = 'AndCondition',
});

factory Fragment$CompositeCondition$$AndCondition.fromJson(
Expand Down Expand Up @@ -1030,7 +1030,7 @@ class Fragment$CompositeCondition$$TimeCondition
Fragment$CompositeCondition {
Fragment$CompositeCondition$$TimeCondition({
required this.name,
required this.$__typename,
this.$__typename = 'TimeCondition',
required this.before,
});

Expand Down Expand Up @@ -1346,7 +1346,7 @@ class Fragment$NonCompositeCondition$$AndCondition
Fragment$NonCompositeCondition {
Fragment$NonCompositeCondition$$AndCondition({
required this.name,
required this.$__typename,
this.$__typename = 'AndCondition',
});

factory Fragment$NonCompositeCondition$$AndCondition.fromJson(
Expand Down Expand Up @@ -1477,7 +1477,7 @@ class Fragment$NonCompositeCondition$$TimeCondition
Fragment$NonCompositeCondition {
Fragment$NonCompositeCondition$$TimeCondition({
required this.name,
required this.$__typename,
this.$__typename = 'TimeCondition',
required this.before,
});

Expand Down Expand Up @@ -1625,7 +1625,7 @@ class _CopyWithStubImpl$Fragment$NonCompositeCondition$$TimeCondition<TRes>
class Fragment$TimeCondition implements Fragment$Condition$$TimeCondition {
Fragment$TimeCondition({
required this.name,
required this.$__typename,
this.$__typename = 'TimeCondition',
required this.before,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:gql/ast.dart';
class Query$FetchShouldRender {
Query$FetchShouldRender({
required this.shouldRender,
required this.$__typename,
this.$__typename = 'Query',
});

factory Query$FetchShouldRender.fromJson(Map<String, dynamic> json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Query$Foobar {
Query$Foobar({
this.ts,
this.tss,
required this.$__typename,
this.$__typename = 'Query',
});

factory Query$Foobar.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -307,7 +307,7 @@ class Query$Foobar$ts {
Query$Foobar$ts({
this.t,
this.name,
required this.$__typename,
this.$__typename = 'TS',
});

factory Query$Foobar$ts.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -456,7 +456,7 @@ class _CopyWithStubImpl$Query$Foobar$ts<TRes>
class Query$Foobar$ts$t {
Query$Foobar$ts$t({
this.name,
required this.$__typename,
this.$__typename = 'TS',
});

factory Query$Foobar$ts$t.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -577,7 +577,7 @@ class _CopyWithStubImpl$Query$Foobar$ts$t<TRes>
class Query$Foobar$tss {
Query$Foobar$tss({
required this.nameEnforced,
required this.$__typename,
this.$__typename = 'TS',
});

factory Query$Foobar$tss.fromJson(Map<String, dynamic> json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:gql/ast.dart';
class Query$Q {
Query$Q({
this.value,
required this.$__typename,
this.$__typename = 'Query',
});

factory Query$Q.fromJson(Map<String, dynamic> json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Query$Q {
this.string,
this.$int,
this.i,
required this.$__typename,
this.$__typename = 'Q',
});

factory Query$Q.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -492,7 +492,7 @@ class _CopyWithStubImpl$Query$Q$i<TRes> implements CopyWith$Query$Q$i<TRes> {
class Mutation$M {
Mutation$M({
this.string,
required this.$__typename,
this.$__typename = 'M',
});

factory Mutation$M.fromJson(Map<String, dynamic> json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:gql/ast.dart';
class Fragment$FPerson {
Fragment$FPerson({
this.age,
required this.$__typename,
this.$__typename = 'Person',
});

factory Fragment$FPerson.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -153,7 +153,7 @@ const documentNodeFragmentFPerson = DocumentNode(definitions: [
class Query$Q {
Query$Q({
this.person,
required this.$__typename,
this.$__typename = 'Query',
});

factory Query$Q.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -456,7 +456,7 @@ class Query$Q$person$$Person implements Fragment$FPerson, Query$Q$person {
Query$Q$person$$Person({
this.name,
this.age,
required this.$__typename,
this.$__typename = 'Person',
});

factory Query$Q$person$$Person.fromJson(Map<String, dynamic> json) {
Expand Down
Loading