visitDocumentNode method

  1. @override
List<GraphQLError>? visitDocumentNode(
  1. DocumentNode node
)

Visit DocumentNode.

Implementation

@override
List<GraphQLError>? visitDocumentNode(DocumentNode node) {
  final nonExecutable = node.definitions.where(
    (element) => element is! ExecutableDefinitionNode,
  );
  return nonExecutable.map((e) {
    final nameNode = e.nameNode;
    final _str = nameNode == null
        ? e is SchemaDefinitionNode || e is SchemaExtensionNode
            ? 'schema'
            : '$e'
        : '"${nameNode.value}"';
    return GraphQLError(
      'The $_str definition is not executable.',
      // TODO: 3I get the span from schema nodes
      locations: GraphQLErrorLocation.firstFromNodes([
        e,
        nameNode,
        if (e is SchemaDefinitionNode)
          e.operationTypes.firstOrNull?.type.name,
        if (e is SchemaDefinitionNode) e.directives.firstOrNull?.name,
        if (e is SchemaExtensionNode) e.operationTypes.firstOrNull?.type.name,
        if (e is SchemaExtensionNode) e.directives.firstOrNull?.name,
      ]),
      extensions: _executableDefinitionsSpec.extensions(),
    );
  }).toList();
  // return false;
}