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

Commit

Permalink
Merge pull request #378 from comigor/feature/no-need-for-fragments-glob
Browse files Browse the repository at this point in the history
no need for fragments glob
  • Loading branch information
vasilich6107 authored Mar 28, 2022
2 parents 8577d97 + 90e30bb commit ed08803
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 120 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.5.0-beta

- there is no need to use `fragments_glob` any more just specify the glob which will include all your graphql docs

## 7.4.0-beta

- allow using file fragments and common fragments at the same time
Expand Down
47 changes: 32 additions & 15 deletions lib/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,31 @@ LibraryDefinition generateLibrary(

schema.accept(canonicalVisitor);

final queryDefinitions = gqlDocs
final documentFragments = gqlDocs
.map((doc) => doc.definitions.whereType<FragmentDefinitionNode>())
.expand((e) => e)
.toList();

final documentsWithoutFragments = gqlDocs.map((doc) {
return DocumentNode(
definitions:
doc.definitions.where((e) => e is! FragmentDefinitionNode).toList(),
span: doc.span,
);
}).toList();

final queryDefinitions = documentsWithoutFragments
.map((doc) => generateDefinitions(
schema: schema,
typeDefinitionNodeVisitor: typeDefinitionNodeVisitor,
path: path,
document: doc,
options: options,
schemaMap: schemaMap,
fragmentsCommon: fragmentsCommon,
fragmentsCommon: [
...documentFragments,
...fragmentsCommon,
],
canonicalVisitor: canonicalVisitor,
))
.expand((e) => e)
Expand Down Expand Up @@ -110,12 +126,13 @@ Set<FragmentDefinitionNode> _extractFragments(SelectionSetNode? selectionSet,
selectionSet.selections
.whereType<FragmentSpreadNode>()
.forEach((selection) {
final fragmentDefinitions = fragmentsCommon.firstWhere(
(fragmentDefinition) =>
fragmentDefinition.name.value == selection.name.value);
result.add(fragmentDefinitions);
result.addAll(
_extractFragments(fragmentDefinitions.selectionSet, fragmentsCommon));
final fragmentDefinitions = fragmentsCommon.where((fragmentDefinition) =>
fragmentDefinition.name.value == selection.name.value);
result.addAll(fragmentDefinitions);
for (var fragmentDefinition in fragmentDefinitions) {
result.addAll(_extractFragments(
fragmentDefinition.selectionSet, fragmentsCommon));
}
});
}
return result;
Expand All @@ -133,8 +150,8 @@ Iterable<QueryDefinition> generateDefinitions({
required List<FragmentDefinitionNode> fragmentsCommon,
required CanonicalVisitor canonicalVisitor,
}) {
final documentFragments =
document.definitions.whereType<FragmentDefinitionNode>();
// final documentFragments =
// document.definitions.whereType<FragmentDefinitionNode>();

// if (documentFragments.isNotEmpty && fragmentsCommon.isNotEmpty) {
// throw FragmentIgnoreException();
Expand All @@ -144,9 +161,9 @@ Iterable<QueryDefinition> generateDefinitions({
document.definitions.whereType<OperationDefinitionNode>().toList();

return operations.map((operation) {
final fragments = <FragmentDefinitionNode>[
...documentFragments,
];
// final fragments = <FragmentDefinitionNode>[
// ...documentFragments,
// ];
final definitions = document.definitions
// filtering unused operations
.where((e) {
Expand All @@ -157,7 +174,7 @@ Iterable<QueryDefinition> generateDefinitions({
final fragmentsOperation =
_extractFragments(operation.selectionSet, fragmentsCommon);
definitions.addAll(fragmentsOperation);
fragments.addAll(fragmentsOperation);
// fragments.addAll(fragmentsOperation);
}

final basename = p.basenameWithoutExtension(path).split('.').first;
Expand Down Expand Up @@ -218,7 +235,7 @@ Iterable<QueryDefinition> generateDefinitions({
currentClassName: null,
generatedClasses: [],
inputsClasses: [],
fragments: fragments,
fragments: fragmentsCommon,
usedEnums: {},
usedInputObjects: {},
);
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.4.0-beta
version: 7.5.0-beta

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

0 comments on commit ed08803

Please sign in to comment.