https://github.com/half2me/amplify-transformers
Useful GraphQL Transformers for AppSync/Amplify
https://github.com/half2me/amplify-transformers
Last synced: 9 months ago
JSON representation
Useful GraphQL Transformers for AppSync/Amplify
- Host: GitHub
- URL: https://github.com/half2me/amplify-transformers
- Owner: half2me
- License: mit
- Created: 2020-12-14T19:11:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-24T19:01:04.000Z (about 5 years ago)
- Last Synced: 2024-12-06T21:54:52.626Z (over 1 year ago)
- Language: TypeScript
- Size: 84 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Amplify Transformers
A collection of useful transformers for your GraphQL schema
## Installation
Install with `npm install --save @halftome/amplify-transformers`
## Usage
### Setup Custom Transformers
Edit `amplify/backend/api//transform.conf.json` and append the following:
```json
"transformers": [
"@halftome/amplify-transformers/dist/PipelineTransformer",
"@halftome/amplify-transformers/dist/DynamoDBTransformer"
]
```
### DynamoDB
Use the `@dynamodb` directive to attach a DynamoDB resolver to your field.
Example:
```graphql
type Foo @model {
id: ID!
name: String!
}
type Query {
fooBar: Foo @dynamodb(table: "Foo")
}
```
The default templates will be `Query.fooBar.req.vtl` and `Query.fooBar.res.vtl` generated from the type and the field. If they don't exist, they will be generated, but you need to change the content of the request mapping template.
### Pipeline
Use the `@pipeline` directive to attach a Pipeline resolver to your field. This will just create an empty pipeline. To add functions to the pipeline, use the other directives.
Example:
```graphql
type Foo @model {
id: ID!
name: String!
}
type Baz @model {
id: ID!
name: String!
}
type Query {
fooBarBaz: FooBaz
@pipeline
@dynamodb(table: "Foo", name: "GetFoo")
@dynamodb(table: "Baz", name: "GetBaz")
}
```
This will create a pipeline which executes two dynamodb resolvers one after another. First `Foo`, then `Baz`. Their request mapping templates are in the `pipelineFunctions` directory, and need to be overriden to do anything useful.
## Known Issues / Gotchas
When chaining directives, their order is not necessarily in the order they are written in GraphQL. See this issue for details: https://github.com/aws-amplify/amplify-cli/issues/6176 This is why its important to have the pipeline transformer defined first in `transform.conf.json`. Hopefully this will be fixed soon, and it will allow us to use the `@function` directive with the `@pipeline`