buildSchemaLibrary function

Library buildSchemaLibrary(
  1. SourceNode schemaSource,
  2. String partUrl,
  3. Map<String, Reference> typeOverrides,
  4. EnumFallbackConfig enumFallbackConfig, {
  5. bool generatePossibleTypesMap = false,
  6. Allocator? allocator,
  7. TriStateValueConfig triStateValueConfig = TriStateValueConfig.never,
  8. bool generateVarsCreateFactories = false,
})

Implementation

Library buildSchemaLibrary(SourceNode schemaSource, String partUrl,
    Map<String, Reference> typeOverrides, EnumFallbackConfig enumFallbackConfig,
    {bool generatePossibleTypesMap = false,
    Allocator? allocator,
    TriStateValueConfig triStateValueConfig = TriStateValueConfig.never,
    bool generateVarsCreateFactories = false}) {
  final lib = buildSchema(
      schemaSource,
      typeOverrides,
      enumFallbackConfig,
      allocator ?? Allocator(),
      triStateValueConfig,
      generateVarsCreateFactories) as Library;

  final Code? possibleTypes;
  if (generatePossibleTypesMap && lib.body.isNotEmpty) {
    possibleTypes = buildPossibleTypes(schemaSource.document);
  } else {
    possibleTypes = null;
  }
  return lib.rebuild(
    (b) {
      b.directives.add(
        Directive.part(partUrl),
      );
      if (possibleTypes != null) {
        b.body.add(possibleTypes);
      }
      return b;
    },
  );
}