Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
performance fix 2
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilich6107 committed Mar 1, 2022
1 parent 6412324 commit 5202ac2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 7.3.2-beta

- performance improvements-2

## 7.3.1-beta

- performance improvements
Expand Down
29 changes: 19 additions & 10 deletions lib/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,13 @@ Make sure your query is correct and your schema is updated.''');

final nextClassName = aliasedContext.fullPathName();

final dartTypeName = gql.buildTypeName(fieldType, context.options,
dartType: true,
replaceLeafWith: ClassName.fromPath(path: nextClassName),
schema: context.schema);
final dartTypeName = gql.buildTypeName(
fieldType,
context.options,
dartType: true,
replaceLeafWith: ClassName.fromPath(path: nextClassName),
typeDefinitionNodeVisitor: context.typeDefinitionNodeVisitor,
);

logFn(context, aliasedContext.align + 1,
'${aliasedContext.path}[${aliasedContext.currentType!.name.value}][${aliasedContext.currentClassName} ${aliasedContext.currentFieldName}] ${fieldAlias == null ? '' : '($fieldAlias) '}-> ${dartTypeName.namePrintable}');
Expand Down Expand Up @@ -360,8 +363,12 @@ Make sure your query is correct and your schema is updated.''');

if (scalar?.customParserImport != null &&
nextType.name.value == scalar?.graphQLType) {
final graphqlTypeName = gql.buildTypeName(fieldType, context.options,
dartType: false, schema: context.schema);
final graphqlTypeName = gql.buildTypeName(
fieldType,
context.options,
dartType: false,
typeDefinitionNodeVisitor: context.typeDefinitionNodeVisitor,
);

jsonKeyAnnotation['fromJson'] =
'fromGraphQL${graphqlTypeName.parserSafe}ToDart${dartTypeName.parserSafe}';
Expand All @@ -376,10 +383,12 @@ Make sure your query is correct and your schema is updated.''');

if (fieldType is ListTypeNode) {
final innerDartTypeName = gql.buildTypeName(
fieldType.type, context.options,
dartType: true,
replaceLeafWith: ClassName.fromPath(path: nextClassName),
schema: context.schema);
fieldType.type,
context.options,
dartType: true,
replaceLeafWith: ClassName.fromPath(path: nextClassName),
typeDefinitionNodeVisitor: context.typeDefinitionNodeVisitor,
);
jsonKeyAnnotation['unknownEnumValue'] =
'${innerDartTypeName.dartTypeSafe}.${artemisUnknown.name.namePrintable}';
} else {
Expand Down
15 changes: 9 additions & 6 deletions lib/generator/graphql_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ TypeName buildTypeName(
GeneratorOptions options, {
bool dartType = true,
Name? replaceLeafWith,
DocumentNode? schema,
required TypeDefinitionNodeVisitor typeDefinitionNodeVisitor,
}) {
if (node is NamedTypeNode) {
final typeVisitor = TypeDefinitionNodeVisitor();
schema!.accept(typeVisitor);
final type = typeVisitor.getByName(node.name.value);
final type = typeDefinitionNodeVisitor.getByName(node.name.value);

if (type != null) {
if (type is ScalarTypeDefinitionNode) {
Expand Down Expand Up @@ -78,8 +76,13 @@ TypeName buildTypeName(
}

if (node is ListTypeNode) {
final typeName = buildTypeName(node.type, options,
dartType: dartType, replaceLeafWith: replaceLeafWith, schema: schema);
final typeName = buildTypeName(
node.type,
options,
dartType: dartType,
replaceLeafWith: replaceLeafWith,
typeDefinitionNodeVisitor: typeDefinitionNodeVisitor,
);
return ListOfTypeName(
typeName: typeName,
isNonNull: node.isNonNull,
Expand Down
23 changes: 14 additions & 9 deletions lib/visitor/generator_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ class GeneratorVisitor extends RecursiveVisitor {
)
.fullPathName();

final dartTypeName = gql.buildTypeName(node.type, context.options,
dartType: true,
replaceLeafWith: ClassName.fromPath(path: nextClassName),
schema: context.schema);
final dartTypeName = gql.buildTypeName(
node.type,
context.options,
dartType: true,
replaceLeafWith: ClassName.fromPath(path: nextClassName),
typeDefinitionNodeVisitor: context.typeDefinitionNodeVisitor,
);

final jsonKeyAnnotation = <String, String>{};

Expand All @@ -170,10 +173,12 @@ class GeneratorVisitor extends RecursiveVisitor {
final variableNodeType = node.type;
if (variableNodeType is ListTypeNode) {
final innerDartTypeName = gql.buildTypeName(
variableNodeType.type, context.options,
dartType: true,
replaceLeafWith: ClassName.fromPath(path: nextClassName),
schema: context.schema);
variableNodeType.type,
context.options,
dartType: true,
replaceLeafWith: ClassName.fromPath(path: nextClassName),
typeDefinitionNodeVisitor: context.typeDefinitionNodeVisitor,
);
jsonKeyAnnotation['unknownEnumValue'] =
'${EnumName(name: innerDartTypeName.name).dartTypeSafe}.${artemisUnknown.name.namePrintable}';
} else {
Expand All @@ -192,7 +197,7 @@ class GeneratorVisitor extends RecursiveVisitor {
node.type,
context.options,
dartType: false,
schema: context.schema,
typeDefinitionNodeVisitor: context.typeDefinitionNodeVisitor,
);

jsonKeyAnnotation['fromJson'] =
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: artemis
version: 7.3.1-beta
version: 7.3.2-beta

description: Build dart types from GraphQL schemas and queries (using Introspection Query).
homepage: https://github.com/comigor/artemis
Expand Down

0 comments on commit 5202ac2

Please sign in to comment.