Skip to content

Commit

Permalink
New core (#5665)
Browse files Browse the repository at this point in the history
* Remove legacy tests (#5669)

* Update @ts-gql/schema with a fix with for the inferred type of enums and use orderBy resolvers

* Unique tests (#5671)

* Add tests for uniqueness

* Update packages-next/fields/src/types/timestamp/index.ts

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>

* Fix fetching items through a relationship field

* Add defaultValue to variables in executeGraphQLFieldToRootVal

* Fix a type error

* Fix updateOne

* Use order by (#5678)

* Use orderBy instead of sortBy

* Use enum correctly

* Progress on filter things

* WIP on filters

* filters!

* Password filter

* First pass at filter test updates for new fields (#5696)

* Update filter tests for passwords (#5698)

* Fix auth

* Fix .count(), update tests (#5699)

* Remove itemQueryName

* Make the list function type errors go away

* Fix nested mutations (#5700)

* Decimal filters and scalar

* Fix type errors in document field

* Fix fetching one-sided relationships

* Fix orderBy

* manypkg fix

* Relationship tests for next fields (#5701)

* Fix one sided many-to-many queries

* Update more relationship tests

* Implement decimal field

* Cloudinary field

* Update more tests to new APIs (#5703)

* Change meta query to count

* Fix displayMode: 'count'

* More graphql api changes

* Fix some more things

* Add endSession with @ts-gql/schema

* Require that idFields are non null ids

* Update tests, fix minor bugs (#5714)

* Try fixing CodeSandbox CI

* Filter to-one relationship by null

* Fix find one with filter access control

* Get more tests working (#5721)

* Fix commands

* Move prisma utils

* Update todo example from default branch

* Fix an error

* Update tests to use new APIs (#5730)

* Disconnect fixes (#5731)

* Fix use of disconnect

* Fix disconnect usage

* And some more fixes

* Fix more tests (#5732)

* More test updates for new APIs (#5733)

* Fix tests

* WIP

* Update more tests for new APIs (#5748)

* Make orderBy essentially an input union

* manypkg fix

* sortBy -> orderBy tests

* Add orderBy test

* Update example schemas (#5762)

* Delete a bunch of old stuff to get rid of a bunch of type errors

* image and file field using interfaces

* Make things nullable

* Coerce and validate filters from access control

* Remove unused import

* Change default idField to uuid to test nested mutation behaviour with uuids

* Refactor the return type of createSystem

* Update orderBy things

* Start of legacy filters stuff

* WIP of legacy filters

* more progress on legacy filters

* more progress on legacy filters

* Fix things

* Relationship filtering

* words

* start of defaultValue and isRequired

* fix a thing

* Implement legacy defaultValue and isRequired

* Reset tests from default branch

* Change back to isIndexed and isUnique

* Reset server-side-graphql-client

* Change ordering of fields in generated prisma schema

* Simplify schema construction

* Revert "Simplify schema construction"

This reverts commit 3c5eb59.

* more things

* more alignment on graphql schema

* More alignment

* Update generated schemas

* more alignment

* orderBy and search

* More progress

* Fix a bunch of stuff

* more progress

* WIP

* Fix resolveInput

* Remove skipped thing

* Fix access control

* Fix some more things

* Update virtual field tests

* progress

* a hacky fix

* progress on cache hints

* error ordering things

* a bunch of progress on relationships

* Fix some more things

* Fix some more things

* Fix some things

* Fix some things

* Fix a thing

* fix a thing

* WIP

* FIx some more things

* Revert access control API changes

* Move some utils

* wip

* WIP

* refactoring

* Fix things

* autoIncrement as non-id field

* actually do autoIncrement as non-id field

* Fix autoIncrement

* Fix a thing

* Fix another autoIncrement thing

* i think this is it

* Fix some things

* Reset admin ui things

* Fix things

* Fix another thing

* Fix things

* Update schemas

* ordering things

* Fix some dep things

* Fix cache hints

* Cleanup

* Update @ts-gql/schema

* Remove another unused dep

* Reset docs

* Fix some things

* Experiment with schema reordering for an easier diff

* More reordering

* More changes for the diff

* more changes for the diff

* WIP

* More changes to reduce the diff size

* More schema diff fixes

* More schema alignment

* Another diff fix

* Update snapshots

* Remove a bunch of dead code

* explain a thing

* New @ts-gql/schema stuff

* Fix cloudinary descriptions

* Fix some uniqueWhere stuff

* Fix a thing

* Fix the condition

* Align error things

* Fix auth things

* Fix another usage

* Remove some unused stuff

* Start of cleanup

* Some refactoring

* More refactoring

* More refactoring

* More refactoring

* Prisma schema conflicting enum error fix

* More prisma schema error fixes

* More cleanup

* More refactoring

* More refactoring

* Add @ts-gql/schema dep back

* Fix some things

* Redorder a thing

* More reordering

* Fix some things

* Remove misleading comments (the mentioned problem won't happen)

* More reordering

* Remove a non-null assertion

* Fix a thing

* Fix things

* Remove more dead code

* More reordering

* More refactoring

* More refactoring

* More cleanup

* More cleanup

* More cleanup

* More cleanup

* More cleanup

* Fix more things

* Start of changesets

* Revert "More cleanup"

This reverts commit 1a38262.

* Remove a thing

* Fix more docs

* words

* Remove a thing that we shouldn't do

* Add another changeset

* changeset

* changeset

* Enable cloudinary field tests for a sec

* More things

* the long name is good

* changeset

* some more things

* changeset

* Add cloudinaryImage filters back because why not

* Fix more things

* Stop exporting some things

* Use an if

* Fix a comment

* Fix a thing

* things

* Remove an unused thing

* Remove an unnecessary thing

* Remove commented out lines

* Reset changes to a thing

* Remove more dead code

* More dead code

* Remove usages of interfaces file

* Fix a thing

* Fix things

* words

* Use the right secret field impls

* Allow virtual fields that reference other list types

* Use @graphql-ts/schema

* Rename `types` to `schema`

* Fix afterChange not being called for nested creates

* Explicitly export

* Update .changeset/mean-chairs-destroy.md

Co-authored-by: Tim Leslie <timl@thinkmill.com.au>

* Remove added support for plural, label, singular and path options for now

* Update docs

* Remove commented out plugins thing

* Fix docs for GraphQL plural and add a changeset for it

Co-authored-by: Tim Leslie <timl@thinkmill.com.au>
  • Loading branch information
emmatown and timleslie authored Jun 8, 2021
1 parent cdb30c4 commit a3b07ea
Show file tree
Hide file tree
Showing 196 changed files with 7,173 additions and 11,517 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-eels-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

The ordering of types in the generated `schema.graphql` has changed due to the re-implementation of the core of Keystone, you will need to run `keystone-next dev`/`keystone-next postinstall --fix` to update it.
5 changes: 5 additions & 0 deletions .changeset/few-hounds-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

`createSystem` no longer accepts a Prisma client directly and it returns `getKeystone` which accepts the generated Prisma client and returns `connect`, `disconnect` and `createContext` instead of returning a `keystone` instance object.
5 changes: 5 additions & 0 deletions .changeset/little-chicken-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields': major
---

The relationship field now returns a `[Item!]` instead of a `[Item!]!`, this is so that if an error occurs when resolving the related items, only the relationship field will be returned as null rather than the whole item being returned as null.
5 changes: 5 additions & 0 deletions .changeset/mean-chairs-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields': major
---

The API to configure `virtual` fields has changed to accept a `field` using the `schema` API exported from `@keystone-next/types` rather than GraphQL SDL.
10 changes: 10 additions & 0 deletions .changeset/plenty-flies-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@keystone-next/auth': major
'@keystone-next/cloudinary': major
'@keystone-next/fields': major
'@keystone-next/fields-document': major
'@keystone-next/keystone': major
'@keystone-next/types': major
---

The core of Keystone has been re-implemented to make implementing fields and new features in Keystone easier. While the observable changes for most users should be minimal, there could be breakage. If you implemented a custom field type, you will need to change it to the new API, see fields in the `@keystone-next/fields` package for inspiration on how to do this.
5 changes: 5 additions & 0 deletions .changeset/rare-coats-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

The ordering of relationships fields in the generated Prisma schema has changed so that it aligns with the order specified in the list config with the opposites to one-sided relationships added at the end. The name of one-to-one and one-to-many relationships has also changed to include `_` between the list key and field key to align with many-to-many relationships. Note that these changes do **not require a migration**, only your `schema.prisma` file will need to be updated with `keystone-next dev`/`keystone-next postinstall --fix`.
5 changes: 5 additions & 0 deletions .changeset/rich-worms-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

The `id` field on the item returned from `context.db.lists` functions/passed to hooks/field type resolvers is now whatever the actual id field returned from Prisma is rather than a stringified version of it.
6 changes: 6 additions & 0 deletions .changeset/six-colts-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-next/keystone': major
'@keystone-next/types': major
---

Replaced `graphql.itemQueryName` with always using the list key as the singular name in GraphQL and renamed `graphql.listQueryName` to `graphql.plural`
6 changes: 6 additions & 0 deletions .changeset/slow-camels-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-next/keystone': major
'@keystone-next/types': major
---

The `KeystoneContext` type no longer has the `keystone` object or functions to run access control.
6 changes: 6 additions & 0 deletions .changeset/small-guests-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-next/keystone': major
'@keystone-next/types': major
---

List level create, update and delete access control is now called for each operation in a many operation rather than on all of the operations as a whole. This means that rather than recieving originalInput as an array with itemIds, your access control functions will always be called with just an itemId and/or originalInput(depending on which access control function it is). If your access control functions already worked with creating/updating/deleting one item, they will continue working (though you may get TypeScript errors if you were previously handling itemIds and originalInput as an array, to fix that, you should stop handling that case).
15 changes: 15 additions & 0 deletions .changeset/smooth-pears-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@keystone-next/fields': major
---

The `password` field type now adds a GraphQL type `PasswordState` to the GraphQL output type instead of adding `${fieldKey}_is_set`.

```graphql
type User {
password: PasswordState
}

type PasswordState {
isSet: Boolean!
}
```
6 changes: 6 additions & 0 deletions .changeset/thin-humans-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-next/auth': major
'@keystone-next/fields': major
---

The way that the implementations of `generateHash` and `compare` are passed from the password field to auth has changed to be in the extensions object of the GraphQL output field. Unless you've written your own password field implementation or you're using mismatching versions of @keystone-next/auth and @keystone-next/fields, this won't affect you.
5 changes: 5 additions & 0 deletions .changeset/wicked-moles-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

Filters returned from access control now go through GraphQL validation and coercion like filters that you pass in through the GraphQL API, this will produce better errors when you return invalid values.
26 changes: 8 additions & 18 deletions docs/pages/apis/access-control.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,14 @@ export default config({

Imperative access control functions are passed a collection of arguments which can be used to determine whether the operation is allowed.

| Argument | Description |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `listKey` | The key of the list being operated on. |
| `operation` | The CRUD operation being performed (`'create'`, `'read'`, `'update'`, `'delete'`). |
| `session` | The current session object. See the [Sessions API](./session) for details. |
| `originalInput` | For `create` and `update` operations, this is the value of `data` passed into the mutation. For `read` and `delete` operations this value is `undefined`. |
| `gqlName` | The name of the query or mutation being called. |
| `itemId` | The `id` of the item being updated/deleted in singular `update` and `delete` operations. The `id` of the item being searched for in a single item query. `undefined` for other operations. |
| `itemIds` | The `ids` of the items being updated/deleted in multiple `update` and `delete` operations. `undefined` for other operations. |
| `context` | The [`KeystoneContext`](./context) object of the originating GraphQL operation. |

> **Important**: When writing imperative access control functions it is essential to consider both singular and multi-value operations.
> If you check the `itemId` in the singular case, then you also need to check the `itemIds` in the multi-value case.
> Similarly, `originalInput` will be different in the singular and multi-valued cases.
| Argument | Description |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `listKey` | The key of the list being operated on. |
| `operation` | The CRUD operation being performed (`'create'`, `'read'`, `'update'`, `'delete'`). |
| `session` | The current session object. See the [Sessions API](./session) for details. |
| `originalInput` | For `create` and `update` operations, this is the value of `data` passed into the mutation. For `read` and `delete` operations this value is `undefined`. |
| `itemId` | The `id` of the item being updated/deleted in `update` and `delete` operations. `undefined` for other operations. |
| `context` | The [`KeystoneContext`](./context) object of the originating GraphQL operation. |

```typescript
import { config, createSchema, list } from '@keystone-next/keystone/schema';
Expand All @@ -174,9 +168,7 @@ export default config({
operation,
session,
originalInput,
gqlName,
itemId,
itemIds,
context,
}) => {
return true;
Expand Down Expand Up @@ -298,7 +290,6 @@ Imperative access control functions are passed a collection of arguments which c
| `operation` | The CRU operation being performed (`'create'`, `'read'`, `'update'`). |
| `session` | The current session object. See the [Sessions API](./session) for details. |
| `originalInput` | For `create` and `update` operations, this is the value of `data` passed into the mutation. For `read` operations this value is `undefined`. |
| `gqlName` | The name of the query or mutation being called. |
| `context` | The [`KeystoneContext`](./context) object of the originating GraphQL operation. |
| `item` | The item being updated, deleted, or read. This object is an unresolved list item. See the [list item API](./list-items) for more details on unresolved list items. |

Expand All @@ -318,7 +309,6 @@ export default config({
operation,
session,
originalInput,
gqlName,
context,
item,
}) => {
Expand Down
12 changes: 0 additions & 12 deletions docs/pages/apis/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ context = {
// Database access
prisma,

// Access control helpers
getListAccessControlForUser,
getFieldAccessControlForUser,

// Images API
images: {
getSrc,
Expand All @@ -62,7 +58,6 @@ context = {

// Deprecated
gqlNames,
keystone,
};
```

Expand Down Expand Up @@ -123,11 +118,6 @@ The following functions will create a new `KeystoneContext` object with this beh

The `KeystoneContext` object exposes the underlying database driver directly via `context.prisma`, which is a [Prisma Client](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference) object.

### Access control helpers

The functions `getListAccessControlForUser()` and `getFieldAccessControlForUser()` are used by the internal Keystone resolvers to apply access control.
They should not be called directly.

### Images API

If [support for image fields](./config#images) is enabled in the system, then an `images` API will be made available on the `context` object.
Expand Down Expand Up @@ -171,6 +161,4 @@ They will be removed in future releases.

`gqlNames`: A function which takes a `listKey` and returns an object containing the GraphQL query, mutation and type names related to that list.

`keystone`: An object representing the internal state of the system.

export default ({ children }) => <Markdown>{children}</Markdown>;
20 changes: 9 additions & 11 deletions docs/pages/apis/fields.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -557,29 +557,27 @@ A `virtual` field represents a value which is computed a read time, rather than

Options:

- `resolver` (required):
- `graphQLReturnType` (required):
- `field` (required):
- `graphQLReturnFragment` (default: `undefined` ):
- `extendGraphQLTypes` (default: `[]`):
- `args` (default: `[]`):

```typescript
import { config, createSchema, list } from '@keystone-next/keystone/schema';
import { virtual } from '@keystone-next/fields';
import { schema } from '@keystone-next/types';

export default config({
lists: createSchema({
ListName: list({
fields: {
fieldName: virtual({
resolver: (item, args, context, info) => `/* ... */`,
graphQLReturnType: '...',
field: schema.field({
type: schema.String,
args: { something: schema.arg({ type: schema.Int }) },
resolve(item, args, context, info) {

}
})
graphQLReturnFragment: '...',
extendGraphQLTypes: ['...'],
args: [
{ name: '...', type: 'String' },
/* ... */
],
}),
/* ... */
},
Expand Down
3 changes: 1 addition & 2 deletions docs/pages/apis/schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ Options:

- `description` (default: `undefined`): Sets the description of the associated GraphQL type in the generated GraphQL API documentation.
Overrides the list-level `description` config option.
- `itemQueryName` (default: List key, e.g `'User'`): Overrides the name used in singular mutations and queries (e.g. `User`, `updateUser`, etc).
- `listQueryName`: (default: Pluralised list key, e.g. `'Users'`): Overrides the name used in multiple mutations and queries (e.g. `allUsers`, `updateUsers`, etc).
- `plural`: (default: Pluralised list key, e.g. `'Users'`): Overrides the name used in multiple mutations and queries (e.g. `allUsers`, `updateUsers`, etc).
- `queryLimits` (default: `undefined`): Allows you to limit the number of results returned from a query to this list in the GraphQL API.
See also the global `graphql.queryLimits` option in the [System Configuration API](./config).
- `cacheHint` (default: `undefined`): Allows you to specific the [dynamic cache control hints](https://www.apollographql.com/docs/apollo-server/performance/caching/#in-your-resolvers-dynamic) used for queries to this this list.
Expand Down
Loading

1 comment on commit a3b07ea

@vercel
Copy link

@vercel vercel bot commented on a3b07ea Jun 8, 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.