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

Commit

Permalink
bugfix/multiple_queries_in_document
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilich6107 committed May 11, 2021
1 parent d92d3f2 commit 2e7a6d2
Show file tree
Hide file tree
Showing 5 changed files with 443 additions and 113 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.0.0-beta.11

- document generation fix for https://github.com/comigor/artemis/issues/307

## 7.0.0-beta.10

- union generation fix for https://github.com/comigor/artemis/issues/284
Expand Down
36 changes: 17 additions & 19 deletions lib/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ Iterable<QueryDefinition> generateDefinitions(
List<FragmentDefinitionNode> fragmentsCommon,
CanonicalVisitor canonicalVisitor,
) {
final fragments = <FragmentDefinitionNode>[];

final documentFragments =
document.definitions.whereType<FragmentDefinitionNode>();

Expand All @@ -140,12 +138,19 @@ Iterable<QueryDefinition> generateDefinitions(
document.definitions.whereType<OperationDefinitionNode>().toList();

return operations.map((operation) {
final fragments = <FragmentDefinitionNode>[];
final definitions = document.definitions
// filtering unused operations
.where((e) {
return e is! OperationDefinitionNode || e == operation;
}).toList();

if (fragmentsCommon.isEmpty) {
fragments.addAll(documentFragments);
} else {
final fragmentsOperation =
_extractFragments(operation.selectionSet, fragmentsCommon);
document.definitions.addAll(fragmentsOperation);
definitions.addAll(fragmentsOperation);
fragments.addAll(fragmentsOperation);
}

Expand Down Expand Up @@ -174,14 +179,14 @@ Iterable<QueryDefinition> generateDefinitions(

final rootTypeName =
(schemaVisitor.schemaDefinitionNode?.operationTypes ?? [])
.firstWhereOrNull((e) => e.operation == operation.type)
?.type
.name
.value ??
.firstWhereOrNull((e) => e.operation == operation.type)
?.type
.name
.value ??
suffix;

final TypeDefinitionNode parentType =
objectVisitor.getByName(rootTypeName)!;
objectVisitor.getByName(rootTypeName)!;

final name = QueryName.fromPath(
path: createPathName([
Expand All @@ -208,21 +213,14 @@ Iterable<QueryDefinition> generateDefinitions(
usedInputObjects: {},
);

final visitor = GeneratorVisitor(
context: context,
);

DocumentNode(
definitions: document.definitions
// filtering unused operations
.where((e) => e is! OperationDefinitionNode || e == operation)
.toList(),
).accept(visitor);
final visitor = GeneratorVisitor(context: context);
final documentDefinitions = DocumentNode(definitions: definitions);
documentDefinitions.accept(visitor);

return QueryDefinition(
name: name,
operationName: operationName,
document: document,
document: documentDefinitions,
classes: [
...canonicalVisitor.enums
.where((e) => context.usedEnums.contains(e.name)),
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: artemis
version: 7.0.0-beta.10
version: 7.0.0-beta.11

description: Build dart types from GraphQL schemas and queries (using Introspection Query).
homepage: https://github.com/comigor/artemis
Expand All @@ -22,7 +22,7 @@ dependencies:
gql_http_link: ^0.4.0-nullsafety.1
gql_link: ^0.4.0-nullsafety.3
gql: ^0.13.0-nullsafety.2
http: ^0.13.2
http: ^0.13.3
json_annotation: ^4.0.1
meta: ^1.3.0
path: ^1.8.0
Expand All @@ -32,7 +32,7 @@ dependencies:

dev_dependencies:
args: ^2.1.0
build_runner: ^2.0.1
build_runner: ^2.0.2
build_test: ^2.1.0
json_serializable: ^4.1.1
build_resolvers: ^2.0.1
Expand Down
Loading

0 comments on commit 2e7a6d2

Please sign in to comment.