Skip to content

Commit

Permalink
closes #178
Browse files Browse the repository at this point in the history
  • Loading branch information
smkhalsa committed Jul 15, 2021
1 parent 3ca283f commit ab517dc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions codegen/gql_code_builder/lib/src/built_class.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "package:built_collection/built_collection.dart";
import "package:code_builder/code_builder.dart";
import "package:recase/recase.dart";

import "./common.dart";
import "./utils/to_camel_case.dart";

/// Generates a class that implements [Built], along with its serializers
Class builtClass({
Expand Down Expand Up @@ -68,7 +68,7 @@ Class builtClass({
if (getters != null) ...getters,
// Serlialization methods
buildSerializerGetter(className).rebuild(
(b) => b..body = Code("_\$${className.camelCase}Serializer"),
(b) => b..body = Code("_\$${toCamelCase(className)}Serializer"),
),
buildToJsonGetter(className),
buildFromJsonGetter(className),
Expand Down
14 changes: 7 additions & 7 deletions codegen/gql_code_builder/lib/src/schema/enum.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "package:built_collection/built_collection.dart";
import "package:code_builder/code_builder.dart";
import "package:gql/ast.dart";
import "package:gql_code_builder/schema.dart";
import "package:recase/recase.dart";

import "package:gql_code_builder/src/common.dart";
import "../../schema.dart";
import "../common.dart";
import "../utils/to_camel_case.dart";

Class buildEnumClass(
EnumTypeDefinitionNode node,
Expand Down Expand Up @@ -97,7 +97,7 @@ ListBuilder<Method> _buildMethods(
..type = MethodType.getter
..name = "serializer"
..lambda = true
..body = Code("_\$${enumName.camelCase}Serializer"),
..body = Code("_\$${toCamelCase(enumName)}Serializer"),
),
Method(
(b) => b
Expand All @@ -113,7 +113,7 @@ ListBuilder<Method> _buildMethods(
..type = MethodType.getter
..name = "values"
..lambda = true
..body = Code("_\$${enumName.camelCase}Values"),
..body = Code("_\$${toCamelCase(enumName)}Values"),
),
Method(
(b) => b
Expand All @@ -128,7 +128,7 @@ ListBuilder<Method> _buildMethods(
),
)
..lambda = true
..body = refer("_\$${enumName.camelCase}ValueOf")
..body = refer("_\$${toCamelCase(enumName)}ValueOf")
.call([refer("name")]).code,
),
],
Expand Down Expand Up @@ -177,5 +177,5 @@ Field _buildConst(
..type = refer(enumName)
..name = _escapeConstName(node.name.value)
..assignment = Code(
"_\$${enumName.camelCase}${_escapeConstName(node.name.value)}"),
"_\$${toCamelCase(enumName)}${_escapeConstName(node.name.value)}"),
);
17 changes: 17 additions & 0 deletions codegen/gql_code_builder/lib/src/utils/to_camel_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
String toCamelCase(String name) {
var result = "";
var upperCase = false;
var firstCharacter = true;
for (final char in name.split("")) {
if (char == "_") {
upperCase = true;
} else {
result += firstCharacter
? char.toLowerCase()
: (upperCase ? char.toUpperCase() : char);
upperCase = false;
firstCharacter = false;
}
}
return result;
}
7 changes: 3 additions & 4 deletions codegen/gql_code_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: gql_code_builder
version: 0.2.0
description: Dart code builders taking *.graphql documents and SDL to build useful classes.
repository: https://github.com/gql-dart/gql
environment:
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
dependencies:
analyzer: ^1.2.0
built_collection: ^5.0.0
built_value: ^8.0.6
Expand All @@ -13,8 +13,7 @@ dependencies:
gql: ^0.13.0
gql_exec: ^0.3.0
path: ^1.8.0
recase: ^4.0.0
dev_dependencies:
dev_dependencies:
build_runner: ^2.0.0
gql_pedantic: ^1.0.2
test: ^1.16.8

0 comments on commit ab517dc

Please sign in to comment.