Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(normalize,ferry,ferry_generator): Add const constructor to visitors #614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 2 additions & 2 deletions packages/normalize/lib/src/utils/well_known_directives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:gql/ast.dart';
/// - a @skip directive with an if-argument that evaluates to true
/// - a @include directive with an if-argument that evaluates to false
bool isSkipped(SelectionNode node, Map<String, dynamic> variables) {
final directives = node.accept(_SelectionNodeDirectiveVisitor.instance);
final directives = node.accept(const _SelectionNodeDirectiveVisitor());

final skipOrIncludeDirective = directives?.firstWhereOrNull(
(directive) => const {'skip', 'include'}.contains(directive.name.value));
Expand Down Expand Up @@ -41,7 +41,7 @@ bool isSkipped(SelectionNode node, Map<String, dynamic> variables) {

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

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