Skip to content

Commit 4b37845

Browse files
committed
Merge branch 'next' into main
2 parents dd1dcf1 + f83de8a commit 4b37845

25 files changed

+696
-454
lines changed

CHANGELOG.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,98 @@
11
# Changelog
22

3+
## Version 1.0.0-beta.56
4+
5+
### ⚠️ Breaking
6+
7+
- Feat: Introducing pagination on list queries.
8+
- Feat: Introducing entirely refactored filters on list queries, closer to the Prisma syntax.
9+
10+
#### Filtering (breaking)
11+
12+
To simplify both usage and implementation, filtering on fields and relations have been refactored entirely. The syntax is now closer to [how Prisma handles filtering](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#filter-conditions-and-operators).
13+
14+
```graphql
15+
# before
16+
query {
17+
listPosts(
18+
where: { title_startsWith: "Foo" }
19+
) {
20+
title
21+
}
22+
}
23+
24+
# after (1.0.0-beta.56+)
25+
query {
26+
listPosts(
27+
where: { title: { startsWith: "Foo" } }
28+
) {
29+
title
30+
}
31+
}
32+
```
33+
34+
```graphql
35+
# before
36+
query {
37+
listPosts(
38+
where: { title: "Foo" }
39+
) {
40+
title
41+
}
42+
}
43+
44+
# after (1.0.0-beta.56+)
45+
query {
46+
listPosts(
47+
where: { title: { equals: "Foo" } }
48+
) {
49+
title
50+
}
51+
}
52+
```
53+
54+
Some Types have also been renamed for more consistency:
55+
56+
- `CreateRelations` renamed to `CreateRelationsInput`
57+
- `UpdateRelations` renamed to `UpdateRelationsInput`
58+
- `WhereInput` renamed to `WhereFilterInput`
59+
60+
#### Pagination (breaking)
61+
62+
Introducing pagination on list queries ([using Prisma offset pagination](https://www.prisma.io/docs/concepts/components/prisma-client/pagination)).
63+
64+
```graphql
65+
# after (1.0.0-beta.56+)
66+
query {
67+
listPosts(
68+
skip: 0
69+
take: 20
70+
) {
71+
title
72+
}
73+
}
74+
```
75+
76+
If the `take` parameter is omitted, PrismaAppSync will use a default value of `50`. It is also possible to change the default value:
77+
78+
```typescript
79+
// Set the default value to 50, if the `take` parameter is omitted.
80+
const app = new PrismaAppSync({
81+
connectionUrl: process.env.DB_CONNECTION_URL,
82+
defaultPagination: 20
83+
})
84+
85+
// Disable pagination limit, if the `take` parameter is omitted.
86+
const app = new PrismaAppSync({
87+
connectionUrl: process.env.DB_CONNECTION_URL,
88+
defaultPagination: false
89+
})
90+
```
91+
92+
### Non-breaking
93+
94+
- Fix: Has no exported member 'Prisma' issue resolved ([issues/11](https://github.com/maoosi/prisma-appsync/issues/11))
95+
396
## Version 1.0.0-beta.53
497

598
### ⚠️ Breaking

boilerplate/handler.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ const app = new PrismaAppSync({
66
connectionUrl: process.env.CONNECTION_URL,
77
debug: true
88
})
9+
<% if (testingMode) { %>
10+
// Prisma middleware
11+
app.prisma.$use(async (params, next) => {
12+
console.log('Hello from Prisma middleware!', params)
13+
return next(params)
14+
})
915

10-
// Lambda function handler
16+
<% } %>// Lambda function handler
1117
export const main = async (event: any, context: any, callback: any) => {
1218
context.callbackWaitsForEmptyEventLoop = false
1319
console.info('Received event:', JSON.stringify(event))
@@ -22,25 +28,15 @@ export const main = async (event: any, context: any, callback: any) => {
2228
where: { id: customResolverParams.args.postId }
2329
})
2430
}
25-
2631
app.registerCustomResolvers({ incrementPostsViews })
2732

28-
// Prisma middleware
29-
app.prisma.$use(async (params, next) => {
30-
console.log('Hello from Prisma middleware!', params)
31-
return next(params)
32-
})
33-
3433
<% } %>// Parse the `event` from your Lambda function
3534
app.parseEvent(event)
3635

3736
// Handle CRUD operations / resolve query
3837
const result = await app.resolve()
3938
console.info('Resolver result:', result)
4039

41-
// Close database connection
42-
await app.prisma.$disconnect()
43-
4440
// Return query result
4541
return Promise.resolve(result)
4642

dist/generator.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316575,7 +316575,7 @@ var require_package2 = __commonJS2((exports2, module2) => {
316575316575
module2.exports = {
316576316576
name: "prisma-appsync",
316577316577
description: "\u26A1 AppSync GraphQL API Generator for \u25ED Prisma 2, the next-gen ORM.",
316578-
version: "1.0.0-beta.54",
316578+
version: "1.0.0-beta.56",
316579316579
bin: "./dist/generator.js",
316580316580
repository: "git@github.com:maoosi/prisma-appsync.git",
316581316581
author: "maoosi <hello@sylvainsimao.fr>",
@@ -321101,6 +321101,7 @@ var PrismaAppSyncCompiler = class {
321101321101
name: field.name,
321102321102
scalar: this.getFieldScalar(field),
321103321103
isRequired: this.isFieldRequired(field),
321104+
isEnum: this.isFieldEnum(field),
321104321105
isEditable: !this.isFieldGeneratedRelation(field, model) && !this.isFieldImmutableDate(field),
321105321106
isUnique: this.isFieldUnique(field, model),
321106321107
...field.relationName && {
@@ -321164,6 +321165,7 @@ var PrismaAppSyncCompiler = class {
321164321165
subFields.push({
321165321166
name: idFields.join("_"),
321166321167
scalar: `${idFields.join("_")}FieldsInput!`,
321168+
isEnum: false,
321167321169
isRequired: true,
321168321170
isEditable: false,
321169321171
isUnique: true,
@@ -321179,6 +321181,9 @@ var PrismaAppSyncCompiler = class {
321179321181
isFieldRequired(searchField) {
321180321182
return searchField.isRequired && !(searchField.relationName && searchField.isList);
321181321183
}
321184+
isFieldEnum(searchField) {
321185+
return searchField.kind === "enum";
321186+
}
321182321187
isFieldImmutableDate(searchField) {
321183321188
return searchField.isId || searchField.isUpdatedAt || ["updatedAt", "createdAt"].includes(searchField.name);
321184321189
}

dist/prisma-appsync/_adapter.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RequestProps, AdapterOptions, AuthType, Operation } from './_types';
22
export declare class PrismaAppSyncAdapter {
33
private customResolvers;
44
private debug;
5+
private defaultPagination;
56
operation: Operation;
67
model: string;
78
args: RequestProps;
@@ -16,7 +17,5 @@ export declare class PrismaAppSyncAdapter {
1617
private getInclude;
1718
private getSelect;
1819
private parseSelectionList;
19-
private parseData;
20-
private parseWhere;
2120
private parseOrderBy;
2221
}

dist/prisma-appsync/_constants.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
export declare const PrismaAppSyncOperations: string[];
2-
export declare const PrismaCombinators: string[];
3-
export declare const PrismaOperators: string[];
42
export declare const PrismaOrderByArgs: string[];
53
export declare const PrismaExclWords: string[];
64
export declare const AuthModes: {

dist/prisma-appsync/_types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ export declare type Options = {
88
connectionUrl: string;
99
debug?: boolean;
1010
sanitize?: boolean;
11+
defaultPagination?: number | false;
1112
};
1213
export declare type PrivateOptions = {
1314
connectionUrl: string;
1415
debug: boolean;
1516
sanitize: boolean;
17+
defaultPagination: number | false;
1618
};
1719
export declare type AdapterOptions = {
20+
defaultPagination: number | false;
1821
customResolvers: any;
1922
debug: boolean;
2023
};
@@ -33,6 +36,8 @@ export declare type RequestProps = {
3336
include?: any;
3437
where?: any;
3538
orderBy?: any;
39+
skip?: number;
40+
take?: number;
3641
[key: string]: any;
3742
};
3843
export declare type BeforeResolveProps = {

dist/prisma-appsync/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { PrismaClient } from '@prisma/client';
22
import { PrismaAppSyncAdapter } from './_adapter';
33
import { PrismaAppSyncResolver } from './_resolver';
4-
import { Options, AdapterOptions, RequestProps, AuthType, AuthIdentityProps, AuthRule, CustomResolverProps, AfterResolveProps, BeforeResolveProps } from './_types';
4+
import { Options, RequestProps, AuthType, AuthIdentityProps, AuthRule, CustomResolverProps, AfterResolveProps, BeforeResolveProps } from './_types';
55
import { AuthModes, Operations, AuthActions } from './_constants';
6-
export { PrismaAppSyncAdapter, PrismaAppSyncResolver, Options, AdapterOptions, RequestProps, AuthType, AuthIdentityProps, AuthRule, CustomResolverProps, AfterResolveProps, BeforeResolveProps, AuthModes, Operations, AuthActions };
6+
export { PrismaAppSyncAdapter, PrismaAppSyncResolver, Options, RequestProps, AuthType, AuthIdentityProps, AuthRule, CustomResolverProps, AfterResolveProps, BeforeResolveProps, AuthModes, Operations, AuthActions };
77
export declare class PrismaAppSync {
88
adapter: PrismaAppSyncAdapter;
99
resolver: PrismaAppSyncResolver;

dist/prisma-appsync/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/templates/docs/model.md.njk

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ query {
6969

7070
### Querying multiple {{ model.pluralizedName }}
7171

72-
Multiple {{ model.pluralizedName }} queries can take two inputs:
72+
Multiple {{ model.pluralizedName }} queries can take four inputs:
7373

74-
- `where`: `{{ model.name }}WhereInput` An optional object type to filter the content based on a nested set of criteria.
74+
- `where`: `{{ model.name }}WhereFilterInput` An optional object type to filter the content based on a nested set of criteria.
7575
- `orderBy`: `{{ model.name }}OrderByInput` An optional object type to select which field(s) and order to sort the records on. Sorting can be in ascending order `ASC` or descending order `DESC`.
76+
- `skip`: `Int` An optional number that specifies how many of the returned objects in the list should be skipped.
77+
- `take`: `Int` An optional number that specifies how many objects should be returned in the list.
7678

7779
**Standard query**
7880

@@ -92,11 +94,14 @@ query {
9294
}
9395
```
9496

95-
**Standard query with where**
97+
**Standard query with offset pagination**
9698

9799
```graphql
98100
query {
99-
list{{ model.pluralizedName }}(where: { {{ modelField.name }}: {{ modelField.sample | safe }} }) {
101+
list{{ model.pluralizedName }}(
102+
skip: 0
103+
take: 25
104+
) {
100105
{% for field in model.fields -%}
101106
{% if field.relation and field.relation.kind === 'one' -%}
102107
{{ field.name }} # Relation to one
@@ -110,34 +115,33 @@ query {
110115
}
111116
```
112117

113-
**Advanced query using filters**
114-
115-
<details><summary>List of all filters available</summary>
116-
<p>
118+
**Standard query with basic where filter**
117119

118120
```graphql
119-
{% for field in model.fields -%}
120-
{% if not field.relation -%}
121-
{{ field.name }}: {{ field.scalar }}
122-
{{ field.name }}_equals: {{ field.scalar }}
123-
{{ field.name }}_not: {{ field.scalar }}
124-
{{ field.name }}_lt: {{ field.scalar }}
125-
{{ field.name }}_lte: {{ field.scalar }}
126-
{{ field.name }}_gt: {{ field.scalar }}
127-
{{ field.name }}_gte: {{ field.scalar }}
128-
{{ field.name }}_contains: {{ field.scalar }}
129-
{{ field.name }}_startsWith: {{ field.scalar }}
130-
{{ field.name }}_endsWith: {{ field.scalar }}
131-
{% endif -%}
132-
{% endfor %}
121+
query {
122+
list{{ model.pluralizedName }}(where: {
123+
{{ modelField.name }}: { equals: {{ modelField.sample | safe }}}
124+
}) {
125+
{% for field in model.fields -%}
126+
{% if field.relation and field.relation.kind === 'one' -%}
127+
{{ field.name }} # Relation to one
128+
{% elseif field.relation and field.relation.kind === 'many' %}
129+
{{ field.name }} # Relation to many
130+
{% else -%}
131+
{{ field.name }}
132+
{% endif -%}
133+
{% endfor -%}
134+
}
135+
}
133136
```
134137

135-
</p>
136-
</details>
138+
**Standard query with more advanced where filter**
137139

138140
```graphql
139141
query {
140-
list{{ model.pluralizedName }}(where: { {{ modelField.name }}_startsWith: {{ modelField.sample | safe }} }) {
142+
list{{ model.pluralizedName }}(where: {
143+
{{ modelField.name }}: { not: { equals: {{ modelField.sample | safe }} } }
144+
}) {
141145
{% for field in model.fields -%}
142146
{% if field.relation and field.relation.kind === 'one' -%}
143147
{{ field.name }} # Relation to one
@@ -394,7 +398,7 @@ mutation {
394398

395399
Multiple {{ model.pluralizedName }} delete mutations can take one input:
396400

397-
- `where`: `{{ model.name }}WhereInput!` A required object type specifying a field with a unique constraint (like {{ modelField.name }}).
401+
- `where`: `{{ model.name }}WhereFilterInput!` A required object type specifying a field with a unique constraint (like {{ modelField.name }}).
398402

399403
**Standard deleteMany mutation**
400404

0 commit comments

Comments
 (0)