Skip to content

Commit

Permalink
Merge branch 'next' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
maoosi committed Jun 25, 2021
2 parents 9ee3d11 + d21752d commit feae1a4
Show file tree
Hide file tree
Showing 47 changed files with 2,469 additions and 323,691 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ node_modules/
# Test files
test/generated/

# Dist folder
dist/

# Docs
docs/.vuepress/dist/

Expand Down
127 changes: 122 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,128 @@
# Changelog

## Version 1.0.0-beta.57
## 🎉 Version 1.0.0-beta.58

### ⚠️ (Breaking) Fix: Issue linked to Prisma models naming

Using a model name format other than PascalCase OR already in the plural form, was causing mapping issues between GraphQL queries and Prisma Client.

> This feature is only breaking in case you were NOT following PascalCase naming convention for models OR affected by one of the below examples.
#### Before

- Model `person`: GQL types generated were not using camelCase (`getperson`, `listpersons`, etc...)
- Model `People`: Was wrongly mapping to singular `person` instead of `people`.
- Model `PersonEmails`: Was wrongly mapping to `prismaClient.personemail` instead of `prismaClient.personemails`
- Model `person_emails`: Was throwing an error when calling the API.

#### After

- Model `person`: GQL types are now properly using camelCase (`getPerson`, `listPersons`, etc...)
- Model `People`: Mapping back to the right `people` model.
- Model `PersonEmails`: Mapping back to the right `prismaClient.personemails`
- Model `person_emails`: Properly converted to `getPersonEmails` and mapped back to `prismaClient.person_emails`

### ⚠️ (Breaking) Feat: orderBy query filter updated to support multiple fields

#### Before

```graphql
query {
listPosts(orderBy: { title: ASC }) {
title
}
}
```

#### After

```graphql
query {
listPosts(
orderBy: [
{ title: ASC },
{ preview: ASC },
]
) {
title
}
}
```

### 🆕 Feat: New Queries, Mutations and Subscriptions added

```graphql
# New `createMany` mutation (example for Post model)
mutation {
createManyPosts(
data: [
{ title: "How to get started with Prisma-AppSync" }
{ title: "How to migrate to Prisma-AppSync" }
]
) {
count
}
}

# New `updateMany` mutation (example for Post model)
mutation {
updateManyPosts(
where: { title: { startsWith: "How to" } }
data: { category: "guides" }
) {
count
}
}

# New `count` query (example for Post model)
query {
countPosts(
where: { title: { startsWith: "How to" } }
)
}

# New `onUpserted` subscription (example for Post model)
# > Triggered from `upsertPost` mutation.
subscription {
onUpsertedPost {
title
category
}
}

# New `onMutated` subscription (example for Post model)
# > Triggered from ANY SINGLE record mutation (excl. `on*ManyPosts`).
subscription {
onMutatedPost {
title
category
}
}

# New `on[Action]Many` subscriptions (example for Post model)
subscription { onCreatedManyPosts { count } }
subscription { onUpdatedManyPosts { count } }
subscription { onDeletedManyPosts { count } }

# New `onMutatedMany` subscription (example for Post model)
# > Triggered from ANY MULTIPLE records mutation (excl. single record mutations).
subscription { onMutatedManyPosts { count } }
```

### 🆕 Misc

- The `authIdentity` property (accessible from the hooks) now includes `requestApiKey` and `requestUserAgent` when using `API_KEY` authorization.
- Comments added in the generate GraphQL schema (visible from AppSync query editor docs).
- Updated Boilerplate to reflect new changes.
- Updated generated API documentation to reflect new changes.
- Upgraded Prisma to v2.25.0.

## 🎉 Version 1.0.0-beta.57

- Feat: Support for prisma ^2.24.1 added.
- Fix: Type issue in the Boilerplate.

## Version 1.0.0-beta.56
## 🎉 Version 1.0.0-beta.56

### ⚠️ Breaking

Expand Down Expand Up @@ -98,7 +215,7 @@ const app = new PrismaAppSync({

- Fix: Has no exported member 'Prisma' issue resolved ([issues/11](https://github.com/maoosi/prisma-appsync/issues/11))

## Version 1.0.0-beta.53
## 🎉 Version 1.0.0-beta.53

### ⚠️ Breaking

Expand All @@ -123,7 +240,7 @@ app.registerCustomResolvers({ incrementPostsViews })
- Feat: For contributors, running `yarn create prisma-appsync-app . --test` now also creates a custom resolver for testing purpose.
- Fix: PNPM install not running `prisma generate` by default ([issues/11](https://github.com/maoosi/prisma-appsync/issues/11))

## Version 1.0.0-beta.52
## 🎉 Version 1.0.0-beta.52

### ⚠️ Breaking

Expand Down Expand Up @@ -168,7 +285,7 @@ afterBundling(inputDir: string, outputDir: string): string[] {
- Feat: Contribution guide added (see [CONTRIBUTING.md](CONTRIBUTING.md)) with new boilerplate testing workflow.
- Feat: Core library is now using Pnpm instead of Yarn.

## Version 1.0.0-beta.51
## 🎉 Version 1.0.0-beta.51

- Fix: Support for prisma ^2.20 added (output for generators can now be env vars).
- Feat: Ability to exclude fields and models from the generated GraphQL schema and API using `/// @PrismaAppSync.ignore` ([more details in the docs](https://prisma-appsync.vercel.app/guides/ignore.html)).
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<img width="250" height="250" src="https://prisma-appsync.vercel.app/prisma-appsync-logo.png" alt="Prisma-AppSync" />
</p>

# Prisma-AppSync &middot; [![Generic badge](https://img.shields.io/badge/Generator%20for-◭%20Prisma%202-9F7AEA.svg)](https://www.prisma.io) [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/maoosi/prisma-appsync/graphs/commit-activity)
# Prisma-AppSync &middot; [![Generic badge](https://img.shields.io/badge/Generator%20for-◭%20Prisma-9F7AEA.svg)](https://www.prisma.io) [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/maoosi/prisma-appsync/graphs/commit-activity)

**Prisma-AppSync** is a custom Generator for [Prisma 2](https://www.prisma.io), that automatically generates a fully working AWS AppSync ⚡ GraphQL CRUD API.
**Prisma-AppSync** is a [Prisma](https://www.prisma.io) Generator, that automatically converts your Schema into a full-blown ⚡&#160;GraphQL&#160;API for [AWS AppSync](https://aws.amazon.com/appsync/).

> ⚠️ ⚠️ Prisma-AppSync is highly experimental and it is not recommended to use in Production at this stage. Breaking changes might be introduced at anytime between beta versions. Feedback, suggestions and PRs welcomed.
> ⚠️ ⚠️ Prisma-AppSync is NOT ready for Production and is only recommended to use for prototyping until a stable version is released. Breaking changes might be introduced at anytime during the beta. Feedback, suggestions and PRs welcomed.
## ✨ Automatically generated

Expand All @@ -16,17 +16,17 @@

## ✔️ Features

- AppSync CRUD API (get/list/create/update/delete/deleteMany).
- AppSync CRUD API (get / list / create / update / upsert / delete / createMany / updateMany / deleteMany).
- Extensible TypeScript Class with support for hooks and custom resolvers.
- Support for AppSync authorization modes, as well as fine-grained access control.
- Real-time subscriptions (onCreated/onUpdated/onDeleted).
- Exposes Prisma relation queries (create/connect/connectOrCreate/update/upsert/delete/disconnect/set/updateMany/deleteMany).
- Real-time subscriptions (onCreated / onUpdated / onDeleted).
- Exposes Prisma relation queries (create / connect / connectOrCreate / update / upsert / delete / disconnect / set / updateMany / deleteMany).
- Full CloudWatch logs for easy debugging on AWS.
- XSS data sanitization by default.

## ⚓ Compatibility

- Prisma 2.24.1
- Prisma 2.25.0

## 📓 Documentation

Expand Down
16 changes: 8 additions & 8 deletions boilerplate/cdk/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ SERVICES_PREFIX="<%= name %>"
# https://www.prisma.io/docs/reference/database-reference/connection-urls
PRISMA_CONNECTION_URL="<%= connectionUrl %>"

# schema definition path (generated by prisma-appsync generator)
APPSYNC_SCHEMA_PATH="../prisma/generated/prisma-appsync/schema.gql"
# Root directory (relative to cdk folder)
ROOT_DIR_PATH=".."

# appsync resolvers path (generated by prisma-appsync generator)
APPSYNC_RESOLVERS_PATH="../prisma/generated/prisma-appsync/resolvers.yaml"
# lambda function handler (relative to ROOT_DIR_PATH)
HANDLER_FUNCTION_PATH="./handler.ts"

# lambda function handler (.ts source)
HANDLER_FUNCTION_PATH="../handler.ts"
# Prisma-AppSync output path (relative to ROOT_DIR_PATH)
PRISMA_APPSYNC_OUTPUT_PATH="./prisma/generated/prisma-appsync"

# schema.prisma path (from root)
PRISMA_SCHEMA_ROOT_PATH="/prisma/schema.prisma"
# schema.prisma path (relative to ROOT_DIR_PATH)
PRISMA_SCHEMA_PATH="./prisma/schema.prisma"
46 changes: 37 additions & 9 deletions boilerplate/cdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ export class AppSyncCdkStack extends cdk.Stack {
// create new API
const graphqlApi = new GraphqlApi(this, `${process.env.SERVICES_PREFIX}_Api`, {
name: `${process.env.SERVICES_PREFIX}_Api`,
schema: Schema.fromAsset( path.join(__dirname, process.env.APPSYNC_SCHEMA_PATH || ``) ),
schema: Schema.fromAsset(
path.join(
__dirname,
String(process.env.ROOT_DIR_PATH),
String(process.env.PRISMA_APPSYNC_OUTPUT_PATH),
'schema.gql'
)
),
authorizationConfig: {
defaultAuthorization: {
authorizationType: AuthorizationType.API_KEY
Expand Down Expand Up @@ -93,23 +100,38 @@ export class AppSyncCdkStack extends cdk.Stack {
runtime: Runtime.NODEJS_14_X,
timeout: cdk.Duration.seconds(10),
handler: 'main',
entry: path.join(__dirname, process.env.HANDLER_FUNCTION_PATH || ``),
entry: path.join(
__dirname,
String(process.env.ROOT_DIR_PATH),
String(process.env.HANDLER_FUNCTION_PATH)
),
memorySize: 1536,
depsLockFilePath: path.join(__dirname, '../yarn.lock'),
bundling: {
minify: true,
commandHooks: {
beforeBundling(inputDir: string, outputDir: string): string[] {
<% if (testingMode) { %>const prismaSchema = path.join(inputDir, process.env.PRISMA_SCHEMA_ROOT_PATH || 'schema.prisma')
const customSchema = path.join(path.dirname(prismaSchema), 'custom-schema.gql')
const customResolvers = path.join(path.dirname(prismaSchema), 'custom-resolvers.yaml')
const prismaSchema = path.join(
inputDir,
String(process.env.PRISMA_SCHEMA_PATH)
)

<% if (testingMode) { %>
const customSchema = path.join(
path.dirname(prismaSchema),
'custom-schema.gql'
)
const customResolvers = path.join(
path.dirname(prismaSchema),
'custom-resolvers.yaml'
)

return [
`cp ${prismaSchema} ${outputDir}`,
`cp ${customSchema} ${outputDir}`,
`cp ${customResolvers} ${outputDir}`,
]<% } else { %>return [
`cp ${path.join(inputDir, process.env.PRISMA_SCHEMA_ROOT_PATH || 'schema.prisma')} ${outputDir}`
`cp ${prismaSchema} ${outputDir}`,
]<% } %>
},
beforeInstall() {
Expand All @@ -124,14 +146,15 @@ export class AppSyncCdkStack extends cdk.Stack {
'rm -rf node_modules/.bin',
'rm -rf node_modules/prisma',
'rm -rf node_modules/prisma-appsync',
'rm -rf generated'
]
}
},
<% if (testingMode) { %>nodeModules: ['prisma', '@prisma/client'],<% } else { %>nodeModules: ['prisma', '@prisma/client', 'prisma-appsync'],<% } %>
forceDockerBundling: true
},
environment: {
CONNECTION_URL: process.env.PRISMA_CONNECTION_URL || ``
CONNECTION_URL: String(process.env.PRISMA_CONNECTION_URL)
}
})

Expand Down Expand Up @@ -178,7 +201,12 @@ export class AppSyncCdkStack extends cdk.Stack {
// read resolvers from yaml
const resolvers = yaml.load(
fs.readFileSync(
path.join(__dirname, process.env.APPSYNC_RESOLVERS_PATH || ``),
path.join(
__dirname,
String(process.env.ROOT_DIR_PATH),
String(process.env.PRISMA_APPSYNC_OUTPUT_PATH),
'resolvers.yaml'
),
'utf8'
)
)
Expand Down Expand Up @@ -218,5 +246,5 @@ export class AppSyncCdkStack extends cdk.Stack {
}

const app = new cdk.App()
new AppSyncCdkStack(app, process.env.SERVICES_PREFIX || 'AppSyncGraphQL')
new AppSyncCdkStack(app, String(process.env.SERVICES_PREFIX))
app.synth()
3 changes: 2 additions & 1 deletion boilerplate/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ app.prisma.$use(async (params, next) => {
console.log('Hello from Prisma middleware!', params)
return next(params)
})
<% } %>

<% } %>// Lambda function handler
// Lambda function handler
export const main = async (event: any, context: any, callback: any) => {
context.callbackWaitsForEmptyEventLoop = false
console.info('Received event:', JSON.stringify(event))
Expand Down
Loading

1 comment on commit feae1a4

@vercel
Copy link

@vercel vercel bot commented on feae1a4 Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.