Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit e541203

Browse files
committed
Merge branch 'beta' into alpha
2 parents 72f4872 + 3a9ef9b commit e541203

44 files changed

Lines changed: 430 additions & 418 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p align="center"><a href="https://www.prisma.io"><img src="https://i.imgur.com/wD4rVt4.png" alt="Prisma" height="160px"></a></p>
1+
<p align="center"><a href="https://www.prisma.io"><img src="https://i.imgur.com/QgwDieO.png" alt="Prisma" height="230px"></a></p>
22

33
[Website](https://www.prisma.io)[Docs](https://www.prisma.io/docs/)[Blog](https://www.prisma.io/blog)[Forum](https://www.prisma.io/forum)[Slack](https://slack.prisma.io/)[Twitter](https://twitter.com/prisma)[OSS](https://oss.prisma.io/)[Learn](https://www.howtographql.com)
44

ROADMAP.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@ The following lists represent a number of smaller-scope issues and improvements
1212

1313
#### Improvements
1414

15-
- [Unstable tie breaking for cursor based pagination #3258](https://github.com/prisma/prisma/issues/3258)
16-
- [Nested upsert in create mutations (correct: nested connectOrCreate) #2194](https://github.com/prisma/prisma/issues/2194)
17-
- [Use sensible migration values for existing nodes when adding required fields #2323](https://github.com/prisma/prisma/issues/2323)
18-
- [Allow for custom IDs to be submitted in a create-mutation #3839](https://github.com/prisma/prisma/issues/3839)
19-
- [Support cascading delete with deleteMany #1936](https://github.com/prisma/prisma/issues/1936)
20-
- [[Mongo] improve relational link design to enhance performance #3754](https://github.com/prisma/prisma/issues/3754)
21-
- [Add inner connection fields #1780](https://github.com/prisma/prisma/issues/1780)
22-
- [Order by multiple fields #62](https://github.com/prisma/prisma/issues/62)
15+
- [ ] [Nested upsert in create mutations (correct: nested connectOrCreate) #2194](https://github.com/prisma/prisma/issues/2194)
16+
- [ ] [Use sensible migration values for existing nodes when adding required fields #2323](https://github.com/prisma/prisma/issues/2323)
17+
- [ ] [Allow for custom IDs to be submitted in a create-mutation #3839](https://github.com/prisma/prisma/issues/3839)
18+
- [ ] [Support cascading delete with deleteMany #1936](https://github.com/prisma/prisma/issues/1936)
19+
- [ ] [[Mongo] improve relational link design to enhance performance #3754](https://github.com/prisma/prisma/issues/3754)
20+
- [ ] [Add inner connection fields #1780](https://github.com/prisma/prisma/issues/1780)
21+
- [ ] [Order by multiple fields #62](https://github.com/prisma/prisma/issues/62)
2322

2423
#### Bug fixes
2524

26-
- [Updating Scalar List Values of a Node does not trigger a change of the updatedAt value of a Node #2053](https://github.com/prisma/prisma/issues/2053)
27-
- [Export import fails #3183](https://github.com/prisma/prisma/issues/3183)
28-
- [Introspect postgres: "Could not connect to database. Prisma Config doesn't have any database connection" #3136](https://github.com/prisma/prisma/issues/3136)
29-
- [SDL declare order with relation. #3698](https://github.com/prisma/prisma/issues/3698)
30-
- [Unstable tie breaking for cursor based pagination #3258](https://github.com/prisma/prisma/issues/3258)
31-
- [Multiple pgRelation on connect mutation #3041](https://github.com/prisma/prisma/issues/3041)
25+
- [x] [Updating Scalar List Values of a Node does not trigger a change of the updatedAt value of a Node #2053](https://github.com/prisma/prisma/issues/2053)
26+
- [x] [Unstable tie breaking for cursor based pagination #3258](https://github.com/prisma/prisma/issues/3258)
27+
- [ ] [Export import fails #3183](https://github.com/prisma/prisma/issues/3183)
28+
- [ ] [Introspect postgres: "Could not connect to database. Prisma Config doesn't have any database connection" #3136](https://github.com/prisma/prisma/issues/3136)
3229

3330
### Specification phase
3431

@@ -59,4 +56,4 @@ While the following features are currently not listed in the `Q1/Q2 2019`-sectio
5956
- Observability & monitoring
6057
- Caching
6158
- Subscriptions & clustering
62-
- Query analytics
59+
- Query analytics

cli/packages/prisma-cli-engine/src/Client/Client.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,18 @@ export class Client {
114114
) {
115115
if (!process.env.PRISMA_MANAGEMENT_API_SECRET) {
116116
throw new Error(
117-
`Server at ${
118-
this.env.activeCluster.baseUrl
119-
} requires a cluster secret. Please provide it with the env var PRISMA_MANAGEMENT_API_SECRET`,
117+
`Server at ${chalk.bold(
118+
this.env.activeCluster.name
119+
)
120+
} requires the Management API secret. Please set the the ${chalk.bold('PRISMA_MANAGEMENT_API_SECRET')} environment variable.
121+
122+
Learn more about this error in the docs: https://bit.ly/authentication-and-security-docs`,
120123
)
121124
} else {
122125
throw new Error(
123-
`Cluster secret in env var PRISMA_MANAGEMENT_API_SECRET does not match for cluster ${
124-
this.env.activeCluster.name
125-
}`,
126+
`Can not authenticate against Prisma server. It seems that your ${chalk.bold('PRISMA_MANAGEMENT_API_SECRET')} environment variable is set incorrectly. Please make sure that it matches the value that was used when the Prisma server was deployed.
127+
128+
For more info visit: https://bit.ly/authentication-and-security-docs`,
126129
)
127130
}
128131
}

cli/packages/prisma-cli-engine/src/commands/help.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class Help extends Command {
9797
offset: number = 1,
9898
) {
9999
const color = this.out.color
100-
this.out.log(`\nGraphQL Database Gateway (${chalk.underline(
100+
this.out.log(`\nPrisma replaces traditional ORMs (${chalk.underline(
101101
'https://www.prisma.io',
102102
)})
103103

docs/1.27/datamodel-and-migrations/datamodel-MONGO-knun.mdx

Lines changed: 10 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The datamodel of your service configuration has two major roles:
1818
- **Define the underlying database schema** (the defined models are mapped to MonogDB [collections](https://docs.mongodb.com/manual/reference/glossary/#term-collection)).
1919
- It is the foundation for the **auto-generated CRUD and realtime operations** of your Prisma API. [Learn more](#data-model-vs-prisma-graphql-schema).
2020

21-
The datamodel is written in the GraphQL [Schema Definition Language](https://www.prisma.io/blog/graphql-sdl-schema-definition-language-6755bcb9ce51/) (SDL) and stored in one or more [`.prisma`-files](#files). These `.prisma`-files need to be referenced in your [1](5cy7) under the `datamodel` property. For example:
21+
The datamodel is written using a subset of the GraphQL [Schema Definition Language](https://www.prisma.io/blog/graphql-sdl-schema-definition-language-6755bcb9ce51/) (SDL) and stored in one or more [`.prisma`-files](#files). These `.prisma`-files need to be referenced in your [1](5cy7) under the `datamodel` property. For example:
2222

2323
<Code lines="2">
2424

@@ -33,21 +33,10 @@ datamodel: datamodel.prisma
3333
3434
There are several available building blocks to shape your datamodel.
3535
36-
- [**Types**](#object-types) consist of multiple [fields](#fields) and typically represent entities from your application domain (e.g. `User`, `Car`, `Order`). Each non-embedded type in your datamodel is mapped to a MongoDB collection and CRUD operations are added to the GraphQL schema.
36+
- [**Types**](#object-types) consist of multiple [fields](#fields) and typically represent entities from your application domain (e.g. `User`, `Car`, `Order`). Each non-embedded type in your datamodel is mapped to a MongoDB collection and CRUD operations are exposed in the generated Prisam client API.
3737
- [**Relations**](#relations) describe _relationships_ between types. With MongoDB, a relation can be modeled as an [embedded type](#embedded-types) or as [link relation](#link-relations).
3838
- [**Directives**](#graphql-directives) covering different use cases such as type constraints or cascading delete behaviour.
3939

40-
### Why SDL?
41-
42-
The main reason why SDL is used for data modeling is twofold:
43-
44-
- SDL is an **intuitive, simple and concise** way to express type definitions and therefore contributes to a **great developer experience**.
45-
- Using GraphQL SDL to define models that are used as foundation for a GraphQL API is an **idiomatic** approach.
46-
47-
There is no hard technical requirement that would dictate the use of SDL and Prisma might allow for other approaches to provide model definitions in the future.
48-
49-
> To learn more about the SDL, you can check out the official [GraphQL documentation](http://graphql.org/learn/schema/#type-language) or read the actual [specification](http://facebook.github.io/graphql/draft/#sec-Type-System).
50-
5140
## Example
5241

5342
A simple example `datamodel.prisma` file:
@@ -132,62 +121,11 @@ Applying changes... (22/22)
132121
Applying changes... 0.4s
133122
```
134123
135-
## Datamodel vs Prisma GraphQL schema
136-
137-
When starting out with GraphQL and Prisma, the amount of SDL-files you're working with can be confusing. Yet, it's crucial to understand what the role of each of them is.
138-
139-
Looking only at Prisma, there are two SDL-files that are relevant:
140-
141-
- The **datamodel** containing the _model definitions_ for your Prisma APIs, typically called `datamodel.prisma`.
142-
- The **Prisma GraphQL schema** defining the actual CRUD/realtime _operations_ of the service's API, typically called `prisma.graphql`.
143-
144-
The Prisma database database schema is generated based on the datamodel:
145-
146-
![](https://i.imgur.com/jHkNjKU.png)
147-
148-
The illustration shows a simplified version of the generated Prisma GraphQL schema, you can find the full schema [here](https://gist.github.com/gc-codesnippets/f302c104f2806f9e13f41d909e07d82d).
149-
150-
<Collapse title="Learn more about GraphQL schemas">
151-
152-
A [GraphQL schema](https://www.prisma.io/blog/graphql-server-basics-the-schema-ac5e2950214e/) defines the operations of a GraphQL API. It effectively is a collection of _types_ written in SDL (SDL also supports primitives like interfaces, enums, union types and more, you can learn everything about GraphQL's type system [here](http://graphql.org/learn/schema/#type-system)).
153-
154-
A GraphQL schema has three special _root types_: `Query`, `Mutation` and `Subscription`. These types define the _entry points_ for the API and define what operations the API will accept. To learn more about GraphQL schema, check out this [article](https://www.prisma.io/blog/graphql-server-basics-the-schema-ac5e2950214e/).
155-
156-
</Collapse>
157-
158-
### The datamodel
159-
160-
The datamodel is written manually by the developers of the Prisma service. It defines the models and structures the developer wants to use in their API.
161-
162-
Strictly speaking, the **datamodel is not a valid GraphQL schema** because it does not contain any of GraphQL's root types (`Query`, `Mutation`, `Subscription`) and therefore does not define any API operations.
163-
164-
The datamodel only serves as _foundation_ for the generation of the actual GraphQL schema that defines the GraphQL API of your Prisma service.
165-
166-
### The Prisma GraphQL schema
167-
168-
The Prisma GraphQL schema can be dowloaded from a Prisma service using the `graphql-schema` generator in your 1:
169-
170-
```yml
171-
generate:
172-
- generator: `graphql-schema`
173-
output: ./prisma-schema
174-
```
175-
176-
Now you can run `prisma generate` and the Prisma CLI will stored the Prisma GraphQLS schema in `./prisma-schema/prisma.graphql`.
177-
178-
### A note on the application schema
179-
180-
If you've already looked into building your own GraphQL server based on Prisma, you might have come across another `.graphql`-file which is referred to as your **application schema** (typically called `schema.graphql` or `app.graphql`).
181-
182-
This is a valid GraphQL schema (meaning it contains the `Query`, `Mutation` and `Subscription` root types) that defines the API of your _application layer_. In contrast to Prisma's _generic_ CRUD API, the application layer's API should expose _domain-specific_ operations that are tailored to the needs of your client applications.
183-
184-
The application layer uses Prisma as a _data access layer_ and delegates incoming requests to the service's Prisma API where they're actually resolved against the database.
185-
186124
## Files
187125
188126
You can write your datamodel in a single `.prisma`-file or split it accross multiple ones.
189127
190-
The `.prisma`-files containing the datamodel need to be specified in your 1 under the `datamodel` property. For example:
128+
The `.prisma`-files containing the datamodel need to be referenced in your `prisma.yml` under the `datamodel` property. For example:
191129
192130
```yml
193131
datamodel:
@@ -214,8 +152,6 @@ A type has a _name_ and one or multiple [_fields_](#fields). Type names can only
214152
215153
An instantiation of a type is called a _node_. This term refers to a node inside your _data graph_.
216154
217-
Every type you define in your datamodel will be available as an analogous type in the generated _Prisma GraphQL schema_.
218-
219155
### Defining an object type
220156
221157
A object type is defined in the datamodel with the keyword `type`:
@@ -373,7 +309,7 @@ type User {
373309

374310
### Type modifiers
375311

376-
In a field definition, a type can be annotated with a _type modifier_. GraphQL supports two type modifiers:
312+
In a field definition, a type can be annotated with a _type modifier_. SDL supports two type modifiers:
377313

378314
- **Required fields:** Annotate the type with a `!`, e.g. `name: String!`
379315
- **Lists:** Annotate the type with a pair of enclosing `[]`, e.g. `friends: [User]`
@@ -392,7 +328,7 @@ type Article {
392328

393329
Notice the two `!` type modifiers, here is what they express:
394330

395-
- The first `!` type modifier (right after `String`) means that no item in the list can be `null`, e.g. this value for `tags` would not be valid: `["Software", null, "GraphQL"]`
331+
- The first `!` type modifier (right after `String`) means that no item in the list can be `null`, e.g. this value for `tags` would not be valid: `["Software", null, "Prisma"]`
396332
- The second `!` type modifier (after the closing square bracket) means that the list itself can never be `null`, it might be _empty_ though. Consequently, `null` is not a valid value for the `tags` field but `[]` is.
397333

398334
#### Required
@@ -448,7 +384,7 @@ For every field that's annotated with `@unique`, you're able to query the corres
448384

449385
For example, considering the above datamodel, you can now retrieve a particular `User` node by its `email` address:
450386

451-
<Code languages={["TypeScript", "JavaScript", "Flow", "Go", "GraphQL"]}>
387+
<Code languages={["TypeScript", "JavaScript", "Flow", "Go"]}>
452388

453389
```ts
454390
const user = await prisma.user({
@@ -475,19 +411,8 @@ userByEmail, err := client.User(prisma.UserWhereUniqueInput{
475411
}).Exec(ctx)
476412
```
477413

478-
```graphql
479-
query {
480-
user(where: {
481-
email: "alice@prisma.io"
482-
}) {
483-
name
484-
}
485-
}
486-
```
487-
488414
</Code>
489415

490-
491416
#### More constraints
492417

493418
More database constraints will be added soon. Please join the discussion in this [feature request](https://github.com/prisma/prisma/issues/728) if you have wish to see certain constraints implemented in Prisma.
@@ -523,14 +448,6 @@ Values for fields annotated with the `@id`-directive have the following properti
523448
* Always start with a (lowercase) letter, e.g. `c`
524449
* Follows [cuid](https://github.com/ericelliott/cuid) (_collision resistant unique identifiers_) scheme
525450

526-
Notice that all model types in the Prisma GraphQL schema will implement the `Node` interface. This is what the `Node` interface looks like:
527-
528-
```graphql
529-
interface Node {
530-
id: ID! @id
531-
}
532-
```
533-
534451
#### System fields: `createdAt` and `updatedAt`
535452

536453
The datamodel further provides two special directives which you can add to your fields:
@@ -689,7 +606,7 @@ Note that in this case the relation needs to be annotated with the [`@relation`
689606

690607
For a _to-one_ relation field, you can configure whether it is _required_ or _optional_. The `!` type modifier means that this field can never be `null`. A field for the address of a user would therefore be of type `Address` or `Address!`.
691608

692-
Nodes for a type that contains a required _to-one_ relation field can only be created using a [nested mutation](qwe2#nested-mutations) to ensure the respective field will not be `null`.
609+
Nodes for a type that contains a required _to-one_ relation field can only be created using a [nested mutation](rsc6#nested-object-writes) to ensure the respective field will not be `null`.
693610

694611
Consider again the following relation:
695612

@@ -708,7 +625,7 @@ type Car {
708625

709626
A `Car` can never be created without a `User` and the other way around because that would violate the required constraint. You therefore need to create both at the same time using a declarative nested write:
710627

711-
<Code languages={["TypeScript", "JavaScript", "Flow", "Go", "GraphQL"]}>
628+
<Code languages={["TypeScript", "JavaScript", "Flow", "Go"]}>
712629

713630
```ts
714631
const newUser = await prisma
@@ -756,23 +673,6 @@ newUser, err := client.CreateUser(prisma.UserCreateInput{
756673
}).Exec(ctx)
757674
```
758675

759-
```graphql
760-
mutation {
761-
createUser(data: {
762-
car: {
763-
create: {
764-
color: "Yellow"
765-
}
766-
}
767-
}) {
768-
id
769-
car {
770-
id
771-
}
772-
}
773-
}
774-
```
775-
776676
</Code>
777677

778678
Note that a _to-many_ relation field is always set to required. For example, a field that contains many user addresses always uses the type `[Address!]!` and can never be of type `[Address!]`, `[Address]!` or `[Address]`.
@@ -876,13 +776,6 @@ Let's investigate the deletion behaviour for the three types:
876776
- the related `Blog` node continues to exist and the deleted `Comment` node is removed from its `comments` list.
877777
- the related `User` node continues to exist and the deleted `Comment` node is removed from its `comments` list.
878778

879-
### Generated API operations for relations
880-
881-
The relations that are included in your schema affect the available operations in the [Prisma API](/use-prisma-api). Here is an overview of the generated CRUD and realtime operations for every relation in your Prisma API:
882-
883-
- [Relation queries](qwe1#querying-data-across-relations) allow you to query data across types or aggregated for a relation (note that this is also possible using [Relay](https://facebook.github.io/relay/)'s [connection model](qwe1#connection-queries)).
884-
- [Nested mutations](qwe2#nested-mutations) allow you to create, connect, update, upsert and delete multiple related nodes within the same mutation.
885-
- [Relation subscriptions](qwe3#relation-subscriptions) allow you to get notified of changes to a relation.
886779

887780
## SDL directives
888781

@@ -952,12 +845,12 @@ In this section, we describe further SDL features that are not yet supported for
952845

953846
### Interfaces
954847

955-
"Like many type systems, GraphQL supports interfaces. An interface is an abstract type that includes a certain set of fields that a type must include to implement the interface." From the official [GraphQL Documentation](http://graphql.org/learn/schema/#interfaces)
848+
"Like many type systems, [SDL] supports interfaces. An interface is an abstract type that includes a certain set of fields that a type must include to implement the interface." From the official [Documentation](http://graphql.org/learn/schema/#interfaces)
956849

957850
To learn more about when and how interfaces are coming to Prisma, check out this [feature request](https://github.com/prisma/prisma/issues/83).
958851

959852
### Union types
960853

961-
"Union types are very similar to interfaces, but they don't get to specify any common fields between the types." From the official [GraphQL Documentation](http://graphql.org/learn/schema/#union-types)
854+
"Union types are very similar to interfaces, but they don't get to specify any common fields between the types." From the official [Documentation](http://graphql.org/learn/schema/#union-types)
962855

963856
To learn more about when and how union types are coming to Prisma, check out this [feature request](https://github.com/prisma/prisma/issues/165).

0 commit comments

Comments
 (0)