@polywrap/schema-parse
TypeScript icon, indicating that this package has built-in type declarations

0.12.2 • Public • Published

@polywrap/schema-parse

Parse & validate WRAP schemas, converting them into a WRAP ABI structure. Optionally perform transformations upon the WRAP ABI.

Usage

import {
  Abi,
  parseSchema,
  ParserOptions
} from "@polywrap/schema-parse";

const schema = readFileSync("module.graphql", "utf-8");
const options: ParserOptions = { };

const abi: Abi = parseSchema(schema, options);

Options

interface ParserOptions {
  // Disable schema validation
  noValidate?: boolean;
  // Use custom validators
  validators?: SchemaValidatorBuilder[];
  // Use custom extractors
  extractors?: SchemaExtractorBuilder[];
  // Use custom transformations
  transforms?: AbiTransforms[];
}

ABI Transforms

ABI transformations can be used to modify the ABI structure. A variety of pre-defined transformations can be found in the ./src/transform/ directory.

Example:

import {
  Abi,
  AbiTransforms,
  GenericDefinition,
  parseSchema
} from "@polywrap/schema-parse";

function extendType(extension: any): AbiTransforms {
  return {
    enter: {
      Abi: (abi: Abi) => ({
        ...abi,
        extension,
      }),
      GenericDefinition: (def: GenericDefinition) => ({
        ...def,
        ...extension,
      }),
    },
  };
}

Usage:

parseSchema(schema, {
  transforms: [
    extendType({ newProp: "foo" })
  ]
});

Readme

Keywords

none

Package Sidebar

Install

npm i @polywrap/schema-parse

Weekly Downloads

22

Version

0.12.2

License

MIT

Unpacked Size

235 kB

Total Files

111

Last publish

Collaborators

  • polywrap-build-bot
  • dorgjelli