buildAstLibrary function

Library buildAstLibrary(
  1. SourceNode source
)

Implementation

Library buildAstLibrary(
  SourceNode source,
) {
  final definitions = source.document.definitions.map(
    (def) => fromNode(def).assignConst(_getName(def)).statement,
  );

  final document = refer(
    "DocumentNode",
    "package:gql/ast.dart",
  )
      .call(
        [],
        {
          "definitions": literalList(
            source.getRefs().map(
                  (ref) => Reference(
                    ref.symbol,
                    (ref.url ?? "") + "#ast",
                  ),
                ),
          ),
        },
      )
      .assignConst("document")
      .statement;

  return Library(
    (b) => b
      ..body = ListBuilder<Spec>(
        <Spec>[
          ...definitions,
          document,
        ],
      ),
  );
}