printDirectives method

  1. @experimental
String printDirectives(
  1. GraphQLElement element
)

Implementation

@experimental
String printDirectives(GraphQLElement element) {
  final _excludedDirectiveNames = [
    graphQLDeprecatedDirective.name,
    graphQLSpecifiedByDirective.name,
    graphQLOneOfDirective.name,
  ];
  final filteredDirectives = getDirectivesFromElement(element).where(
    (dir) => !_excludedDirectiveNames.contains(dir.name.value),
  );
  final directiveStrings = [
    if (element is GraphQLInputObjectType && element.isOneOf) '@oneOf',
    if (element is GraphQLScalarType) printSpecifiedByURL(element),
    if (element is GraphQLObjectField)
      printDeprecated(element.deprecationReason),
    if (element is GraphQLFieldInput)
      printDeprecated(element.deprecationReason),
    if (element is GraphQLEnumValue)
      printDeprecated(element.deprecationReason),
    ...filteredDirectives.map(printNode),
  ].where((str) => str.isNotEmpty);
  return directiveStrings.isEmpty ? '' : ' ${directiveStrings.join(' ')}';
}