cdk-appsync-transformer
Project description
AppSync Transformer Construct for AWS CDK
Notice
This is a work in progress and is being migrated from aws-cdk-appsync-transformer to follow community naming guidelines and to utilize projen. For CDK versions < 1.64.0 please use that version.
Why This Package
In April 2020 I wrote a blog post on using the AWS Cloud Development Kit with AppSync. I wrote my own transformer in order to emulate AWS Amplify's method of using GraphQL directives in order to template a lot of the Schema Definition Language.
This package is my attempt to convert all of that effort into a separate construct in order to clean up the process.
How Do I Use It
Example Usage
API With Default Values
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_appsync_transformer import AppSyncTransformer
AppSyncTransformer(self, "my-cool-api",
schema_path="schema.graphql"
)
schema.graphql
type Customer @model
@auth(rules: [
{ allow: groups, groups: ["Admins"] },
{ allow: private, provider: iam, operations: [read, update] }
]) {
id: ID!
firstName: String!
lastName: String!
active: Boolean!
address: String!
}
type Product @model
@auth(rules: [
{ allow: groups, groups: ["Admins"] },
{ allow: public, provider: iam, operations: [read] }
]) {
id: ID!
name: String!
description: String!
price: String!
active: Boolean!
added: AWSDateTime!
orders: [Order] @connection
}
type Order @model
@key(fields: ["id", "productID"]) {
id: ID!
productID: ID!
total: String!
ordered: AWSDateTime!
}
Supported Amplify Directives
Tested:
Experimental:
-
- These work differently here than they do in Amplify - see Functions below
Not Yet Supported:
Authentication
User Pool Authentication
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
user_pool = UserPool(self, "my-cool-user-pool", ...
)
user_pool_client = UserPoolClient(self, f"{id}-client",
user_pool=self.user_pool, ...
)
AppSyncTransformer(self, "my-cool-api",
schema_path="schema.graphql",
authorization_config={
"default_authorization": {
"authorization_type": AuthorizationType.USER_POOL,
"user_pool_config": {
"user_pool": user_pool,
"app_id_client_regex": user_pool_client.user_pool_client_id,
"default_action": UserPoolDefaultAction.ALLOW
}
}
}
)
IAM
Unauth Role: TODO
Auth Role: Unsupported (for now?). Authorized roles (Lambda Functions, EC2 roles, etc) are required to setup their own role permissions.
Functions
Fields with the @function directive will be accessible via api.outputs.FUNCTION_RESOLVERS. It will return an array like below.Currently these are not named and do not specify a region. There are improvements that can be made here but this simple way has worked for me so I've implemented it first. Typically I send all @function requests to one Lambda Function and have it route as necessary.
[
{ typeName: 'Query', fieldName: 'listUsers' },
{ typeName: 'Query', fieldName: 'getUser' },
{ typeName: 'Mutation', fieldName: 'createUser' },
{ typeName: 'Mutation', fieldName: 'updateUser' }
]
DataStore Support
- Pass
syncEnabled: trueto theAppSyncTransformerProps - Generate necessary exports (see Code Generation below)
Code Generation
I've written some helpers to generate code similarly to how AWS Amplify generates statements and types. You can find the code here.
Versioning
I will attempt to align the major and minor version of this package with AWS CDK, but always check the release descriptions for compatibility.
Limitations
Contributing
See CONTRIBUTING for details
License
Distributed under Apache License, Version 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cdk-appsync-transformer-1.65.1.tar.gz.
File metadata
- Download URL: cdk-appsync-transformer-1.65.1.tar.gz
- Upload date:
- Size: 12.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bba77fc6248b29deb4e0c38e0de48133ece5bc38f2e439d7fb5d6346486351ec
|
|
| MD5 |
2c89a81135924a08172d4468617b306c
|
|
| BLAKE2b-256 |
f95fa6caf75933a8d11f724b89e0edd91e4f87072a2143f01b650e54f46cf63d
|
File details
Details for the file cdk_appsync_transformer-1.65.1-py3-none-any.whl.
File metadata
- Download URL: cdk_appsync_transformer-1.65.1-py3-none-any.whl
- Upload date:
- Size: 12.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a98dcf27a72ee532fbec1a73087c597585e5a15b89e8bd3b37604e1de1e6a2e
|
|
| MD5 |
8628cfe91f9532c6302a0ba938e9609c
|
|
| BLAKE2b-256 |
b29f745f8b1cd488ddb159d0e02fcc6807b04c3abee7b9477b3438ed87aaa0a5
|