Skip to content

Commit

Permalink
refactor: Add const constructor to visitors
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinVignal committed Oct 22, 2024
1 parent 12f047b commit 7851de0
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AddTypenameTypedLink extends TypedLink {
..operation = Operation(
document: transform(
request.operation.document,
[AddTypenameVisitor()],
const [AddTypenameVisitor()],
),
operationName: request.operation.operationName,
),
Expand Down
2 changes: 1 addition & 1 deletion packages/ferry/lib/src/add_typename_typed_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AddTypenameTypedLink extends TypedLink {
(op) => Operation(
document: transform(
op.document,
[
const [
AddTypenameVisitor(),
],
),
Expand Down
2 changes: 2 additions & 0 deletions packages/ferry_generator/lib/src/utils/add_introspection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const typenameField = FieldDefinitionNode(
);

class AddTypenameField extends TransformingVisitor {
const AddTypenameField();

@override
ObjectTypeDefinitionNode visitObjectTypeDefinitionNode(
ObjectTypeDefinitionNode node,
Expand Down
2 changes: 1 addition & 1 deletion packages/normalize/lib/src/denormalize_fragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Map<String, dynamic>? denormalizeFragment({
if (addTypename) {
document = transform(
document,
[AddTypenameVisitor()],
const [AddTypenameVisitor()],
);
}
final fragmentMap = getFragmentMap(document);
Expand Down
2 changes: 1 addition & 1 deletion packages/normalize/lib/src/denormalize_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Map<String, dynamic>? denormalizeOperation({
if (addTypename) {
document = transform(
document,
[AddTypenameVisitor()],
const [AddTypenameVisitor()],
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/normalize/lib/src/normalize_fragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void normalizeFragment({
// Always add typenames to ensure data is stored with typename
document = transform(
document,
[AddTypenameVisitor()],
const [AddTypenameVisitor()],
);

final fragmentMap = getFragmentMap(document);
Expand Down
2 changes: 1 addition & 1 deletion packages/normalize/lib/src/normalize_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void normalizeOperation({
if (addTypename) {
document = transform(
document,
[AddTypenameVisitor()],
const [AddTypenameVisitor()],
);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/normalize/lib/src/utils/add_typename_visitor.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:gql/ast.dart';

class AddTypenameVisitor extends TransformingVisitor {
const AddTypenameVisitor();

@override
FieldNode visitFieldNode(FieldNode node) {
if (node.selectionSet == null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/normalize/lib/src/utils/validate_structure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool _validateSelectionSet({
if (addTypename) {
document = transform(
document,
[AddTypenameVisitor()],
const [AddTypenameVisitor()],
);
}
final fragmentMap = getFragmentMap(document);
Expand Down
4 changes: 3 additions & 1 deletion packages/normalize/lib/src/utils/well_known_directives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ bool isSkipped(SelectionNode node, Map<String, dynamic> variables) {

class _SelectionNodeDirectiveVisitor
extends SimpleVisitor<List<DirectiveNode>?> {
static final instance = _SelectionNodeDirectiveVisitor();
const _SelectionNodeDirectiveVisitor();

static const instance = _SelectionNodeDirectiveVisitor();

@override
List<DirectiveNode> visitFieldNode(FieldNode node) {
Expand Down

0 comments on commit 7851de0

Please sign in to comment.