Skip to content

Commit

Permalink
feat: Add enum
Browse files Browse the repository at this point in the history
  • Loading branch information
budde377 committed Apr 13, 2024
1 parent 8caa265 commit 9758570
Show file tree
Hide file tree
Showing 85 changed files with 2,455 additions and 341 deletions.
14 changes: 12 additions & 2 deletions packages/graphql_codegen/example/lib/schema.graphqls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -264,7 +269,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
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 @@ -337,7 +337,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.13.11"
version: "0.14.11"
graphql_flutter:
dependency: "direct main"
description:
Expand Down
5 changes: 2 additions & 3 deletions packages/graphql_codegen/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: graphql_codegen_example

environment:
sdk: '>=2.14.0 <3.0.0'
sdk: ">=2.17.0 <3.0.0"

dependencies:
graphql_flutter: 5.2.0-beta.3
graphql: 5.2.0-beta.3
flutter:
sdk: flutter


dev_dependencies:
graphql_codegen:
graphql_codegen:
path: "../"
build_runner: ^2.0.3
test: ^1.17.4
39 changes: 39 additions & 0 deletions packages/graphql_codegen/lib/src/printer/base/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,45 @@ List<Spec> printEnum(PrintContext<ContextEnum> context) {
Enum(
(b) => b
..name = className
..constructors = ListBuilder<Constructor>(
[
Constructor(
(b) => b
..name = 'fromJson'
..factory = true
..requiredParameters = ListBuilder(
[
Parameter(
(b) => b
..name = 'value'
..type = refer('String'),
)
],
)
..body = refer(
context.namePrinter.printFromJsonConverterFunctionName(
context.path,
),
).call([refer('value')]).code
..lambda = true,
),
],
)
..methods = ListBuilder<Method>(
[
Method(
(b) => b
..name = 'toJson'
..returns = refer('String')
..body = refer(
context.namePrinter.printToJsonConverterFunctionName(
context.path,
),
).call([refer('this')]).code
..lambda = true,
),
],
)
..values = ListBuilder<EnumValue>(
values.map(
(e) {
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.13.11
version: 0.14.11
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 @@ -9,7 +9,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -78,7 +83,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -76,7 +81,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -78,7 +83,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -76,7 +81,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ enum Enum$E {
B,
@Deprecated('Please don\'t')
DEPRECATED,
$unknown
$unknown;

factory Enum$E.fromJson(String value) => fromJson$Enum$E(value);

String toJson() => toJson$Enum$E(this);
}

String toJson$Enum$E(Enum$E e) {
Expand Down Expand Up @@ -43,7 +47,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -112,7 +121,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -368,7 +373,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
enum Enum$MyEnum { FIRST, LAST, OTHER }
enum Enum$MyEnum {
FIRST,
LAST,
OTHER;

factory Enum$MyEnum.fromJson(String value) => fromJson$Enum$MyEnum(value);

String toJson() => toJson$Enum$MyEnum(this);
}

String toJson$Enum$MyEnum(Enum$MyEnum e) {
switch (e) {
Expand Down Expand Up @@ -33,7 +41,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -102,7 +115,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
Expand Down
26 changes: 23 additions & 3 deletions packages/graphql_codegen/test/assets/enums/schema.graphql.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
enum Enum$Enum { FOO, BAR, BAZ_BOB, VOID, $unknown }
enum Enum$Enum {
FOO,
BAR,
BAZ_BOB,
VOID,
$unknown;

factory Enum$Enum.fromJson(String value) => fromJson$Enum$Enum(value);

String toJson() => toJson$Enum$Enum(this);
}

String toJson$Enum$Enum(Enum$Enum e) {
switch (e) {
Expand Down Expand Up @@ -39,7 +49,12 @@ enum Enum$__TypeKind {
INPUT_OBJECT,
LIST,
NON_NULL,
$unknown
$unknown;

factory Enum$__TypeKind.fromJson(String value) =>
fromJson$Enum$__TypeKind(value);

String toJson() => toJson$Enum$__TypeKind(this);
}

String toJson$Enum$__TypeKind(Enum$__TypeKind e) {
Expand Down Expand Up @@ -108,7 +123,12 @@ enum Enum$__DirectiveLocation {
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION,
$unknown
$unknown;

factory Enum$__DirectiveLocation.fromJson(String value) =>
fromJson$Enum$__DirectiveLocation(value);

String toJson() => toJson$Enum$__DirectiveLocation(this);
}

String toJson$Enum$__DirectiveLocation(Enum$__DirectiveLocation e) {
Expand Down
Loading

0 comments on commit 9758570

Please sign in to comment.