interfaceRepresentation method

String interfaceRepresentation(
  1. GraphQLInterfaceType type
)

Renders a Dart abstract class for a GraphQL interface type: declared fields become abstract final fields with mapped Dart types (FR-008).

Implementation

String interfaceRepresentation(GraphQLInterfaceType type) {
  final className = DartTypeNamer.className(type.name);
  final buffer = StringBuffer();
  buffer.writeln(
    '/// Dart representation of the GraphQL interface `${type.name}`.',
  );
  buffer.writeln('abstract class $className {');
  buffer.writeln('  const $className();');
  for (final field in type.fields) {
    final dartType = mapType(field.type);
    final fieldName = DartTypeNamer.fieldName(field.name);
    buffer.writeln('  final $dartType $fieldName;');
  }
  buffer.writeln('}');
  return buffer.toString();
}