graphql-default-value-transformer
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

graphql-default-value-transformer

Add default values to fields in GraphQL schemas for AWS Amplify. Confirmed working with Amplify CLI 4.17.2.

installation

Amplify CLI requires custom transformers to be installed globally as of right now:

npm i -g graphql-default-value-transformer

configuration

In your Amplify project, find the transform.conf.json file under <project-path>/amplify/backend/api/<your-api-name>/. Add the npm package name for this transformer - graphql-default-value-transformer - to the transformers property:

{
  "transformers": [
    "graphql-default-value-transformer"
  ]
}

usage

Supply the @default directive with a single value parameter on any scalar/enum field under a @model. The value parameter must be formatted as a string regardless of the corresponding field type.

type Post @model {
  id: ID!
  title: String! @default(value: "hello world")
  viewCount: Int @default(value: "9001")
  tag: Tag @default(value: "RANDOM")
}
enum Tag {
  NEWS
  RANDOM
}

limitations

This transformer only supports scalar and enum types, include the AWS specific types (e.g.: AWSDateTime).

license

MIT

/graphql-default-value-transformer/

    Package Sidebar

    Install

    npm i graphql-default-value-transformer

    Weekly Downloads

    212

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    31.6 kB

    Total Files

    12

    Last publish

    Collaborators

    • trek10-package-manager