proceedDeprecated function

List<String> proceedDeprecated(
  1. List<DirectiveNode>? directives
)

Proceeds deprecated annotation

Implementation

List<String> proceedDeprecated(
  List<DirectiveNode>? directives,
) {
  final annotations = <String>[];

  final deprecatedDirective = directives?.firstWhereOrNull(
    (directive) => directive.name.value == 'deprecated',
  );

  if (deprecatedDirective != null) {
    final reasonValueNode = deprecatedDirective.arguments
        .firstWhereOrNull((argument) => argument.name.value == 'reason')
        ?.value;

    final reason = reasonValueNode is StringValueNode
        ? reasonValueNode.value.replaceAll("'", "\\'").replaceAll(r'$', r'\$')
        : 'No longer supported';

    annotations.add("Deprecated('$reason')");
  }

  return annotations;
}