1.1.0 • Published 4 years ago

graphql-transform-transformer v1.1.0

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

graphql-transform-transformer

A custom transformer of the amplify-cli. It can transform fields.

directive @transform(expression: String!, foreach: Boolean = false) on FIELD_DEFINITION

Usage

1. Install package

npm install graphql-transform-transformer -D

or

yarn add graphql-transform-transformer -D

2. Setup custom transformer

Edit amplify/backend/api/<YOUR_API>/transform.conf.json and append "./graphql-transform-transformer" to transformers field.

    "transformers": [
      "graphql-transform-transformer"
    ]

3. Use @transform directive

Append @transform to target fields.

type Post @model {
  id: ID!
  title: String! @transform(expression: ".toLowerCase().trim()")
  text: String
  tags: [String!] @transform(expression: ".trim()", foreach: true)
}

You can refer the field itself by .. This transformer doesn't check type soundness, writing correct expressions are up to you.

3.1 How it works

AppSync uses Apache Velocity for resolver mapping. It supports basic operators like logical operators. Besides, It supports Java methods. Thus, you can do whatever you want. But I'm not sure which Java version is used inside AppSync, you may find missing methods.

GraphQL TypeJava Class
IDjava.lang.String
Stringjava.lang.String
Intjava.lang.Integer
Floatjava.lang.Double
Booleanjava.lang.Boolean
Arrayjava.util.ArrayList
Enumjava.lang.String

4. Export NODE_PATH

This step isn't necessary once https://github.com/aws-amplify/amplify-cli/pull/3236 merged.

export NODE_PATH=./node_modules

License

Fork of https://github.com/amazon-archives/aws-reinvent-2019-mobile-workshops/tree/master/MOB405/01%20-%20Finished

ISC

Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Copyright 2020 Hiroshi Ioka. All Rights Reserved.