Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/no-filters-needed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': minor
---

Adds new `unfiltered` shorthand function for an empty filter (exported from '@keystone-6/core/access')
5 changes: 5 additions & 0 deletions .changeset/session-no-never.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Removes `SessionStrategy`'s type parameter of `StartSessionData`, removal is non-breaking as the parameter was unusable
5 changes: 1 addition & 4 deletions examples/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
"dependencies": {
"@keystone-6/auth": "^7.0.0",
"@keystone-6/core": "^5.0.0",
"@prisma/client": "^4.13.0",
"next": "^13.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"@prisma/client": "^4.13.0"
},
"devDependencies": {
"prisma": "^4.13.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/auth/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const lists: Lists = {
update: isAdminOrSameUserFilter,
},
item: {
// this is redundant as ^filter.update should prevent unauthorised updates
// this is redundant as ^filter.update should stop unauthorised updates
// we include it anyway as a demonstration
update: isAdminOrSameUser,
},
Expand Down
3 changes: 1 addition & 2 deletions examples/custom-field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"dependencies": {
"@keystone-6/core": "^5.0.0",
"@keystone-ui/fields": "^7.1.1",
"@prisma/client": "^4.13.0",
"react": "^18.2.0"
"@prisma/client": "^4.13.0"
},
"devDependencies": {
"prisma": "^4.13.0",
Expand Down
Binary file added examples/custom-session/keystone-example.db
Binary file not shown.
45 changes: 45 additions & 0 deletions examples/custom-session/keystone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists, Session } from './schema';
import type { Context, TypeInfo } from '.keystone/types';

const sillySessionStrategy = {
async get({ context }: { context: Context }): Promise<Session | undefined> {
if (!context.req) return;

// WARNING: for demonstrative purposes only, this has no authentication
// use `Cookie:user=clh9v6pcn0000sbhm9u0j6in0` for Alice (admin)
// use `Cookie:user=clh9v762w0002sbhmhhyc0340` for Bob
//
// in practice, you should use authentication for your sessions, such as OAuth or JWT
const { cookie = '' } = context.req.headers;
const [user, id] = cookie.split('=');
if (user !== 'user') return;

const who = await context.sudo().db.User.findOne({ where: { id } });
if (!who) return;
return {
id,
admin: who.admin,
};
},

// we don't need these unless we want to support the functions
// context.sessionStrategy.start
// context.sessionStrategy.end
//
async start() {},
async end() {},
};

export default config<TypeInfo>({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
session: sillySessionStrategy,
});
21 changes: 21 additions & 0 deletions examples/custom-session/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@keystone-6/custom-session",
"version": "0.0.1",
"private": true,
"license": "MIT",
"scripts": {
"dev": "keystone dev",
"start": "keystone start",
"build": "keystone build",
"postinstall": "keystone postinstall"
},
"dependencies": {
"@keystone-6/auth": "^7.0.0",
"@keystone-6/core": "^5.0.0",
"@prisma/client": "^4.13.0"
},
"devDependencies": {
"prisma": "^4.13.0",
"typescript": "~5.0.0"
}
}
7 changes: 7 additions & 0 deletions examples/custom-session/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"template": "node",
"container": {
"startScript": "keystone dev",
"node": "16"
}
}
269 changes: 269 additions & 0 deletions examples/custom-session/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
# This file is automatically generated by Keystone, do not modify it manually.
# Modify your Keystone config when you want to change this.

type Post {
id: ID!
title: String
content: String
}

input PostWhereUniqueInput {
id: ID
}

input PostWhereInput {
AND: [PostWhereInput!]
OR: [PostWhereInput!]
NOT: [PostWhereInput!]
id: IDFilter
title: StringFilter
content: StringFilter
}

input IDFilter {
equals: ID
in: [ID!]
notIn: [ID!]
lt: ID
lte: ID
gt: ID
gte: ID
not: IDFilter
}

input StringFilter {
equals: String
in: [String!]
notIn: [String!]
lt: String
lte: String
gt: String
gte: String
contains: String
startsWith: String
endsWith: String
not: NestedStringFilter
}

input NestedStringFilter {
equals: String
in: [String!]
notIn: [String!]
lt: String
lte: String
gt: String
gte: String
contains: String
startsWith: String
endsWith: String
not: NestedStringFilter
}

input PostOrderByInput {
id: OrderDirection
title: OrderDirection
content: OrderDirection
}

enum OrderDirection {
asc
desc
}

input PostUpdateInput {
title: String
content: String
}

input PostUpdateArgs {
where: PostWhereUniqueInput!
data: PostUpdateInput!
}

input PostCreateInput {
title: String
content: String
}

type User {
id: ID!
name: String
admin: Boolean
}

input UserWhereUniqueInput {
id: ID
}

input UserWhereInput {
AND: [UserWhereInput!]
OR: [UserWhereInput!]
NOT: [UserWhereInput!]
id: IDFilter
name: StringFilter
admin: BooleanFilter
}

input BooleanFilter {
equals: Boolean
not: BooleanFilter
}

input UserOrderByInput {
id: OrderDirection
name: OrderDirection
admin: OrderDirection
}

input UserUpdateInput {
name: String
admin: Boolean
}

input UserUpdateArgs {
where: UserWhereUniqueInput!
data: UserUpdateInput!
}

input UserCreateInput {
name: String
admin: Boolean
}

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSON @specifiedBy(url: "http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf")

type Mutation {
createPost(data: PostCreateInput!): Post
createPosts(data: [PostCreateInput!]!): [Post]
updatePost(where: PostWhereUniqueInput!, data: PostUpdateInput!): Post
updatePosts(data: [PostUpdateArgs!]!): [Post]
deletePost(where: PostWhereUniqueInput!): Post
deletePosts(where: [PostWhereUniqueInput!]!): [Post]
createUser(data: UserCreateInput!): User
createUsers(data: [UserCreateInput!]!): [User]
updateUser(where: UserWhereUniqueInput!, data: UserUpdateInput!): User
updateUsers(data: [UserUpdateArgs!]!): [User]
deleteUser(where: UserWhereUniqueInput!): User
deleteUsers(where: [UserWhereUniqueInput!]!): [User]
endSession: Boolean!
}

type Query {
posts(where: PostWhereInput! = {}, orderBy: [PostOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: PostWhereUniqueInput): [Post!]
post(where: PostWhereUniqueInput!): Post
postsCount(where: PostWhereInput! = {}): Int
users(where: UserWhereInput! = {}, orderBy: [UserOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: UserWhereUniqueInput): [User!]
user(where: UserWhereUniqueInput!): User
usersCount(where: UserWhereInput! = {}): Int
keystone: KeystoneMeta!
}

type KeystoneMeta {
adminMeta: KeystoneAdminMeta!
}

type KeystoneAdminMeta {
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}

type KeystoneAdminUIListMeta {
key: String!
itemQueryName: String!
listQueryName: String!
hideCreate: Boolean!
hideDelete: Boolean!
path: String!
label: String!
singular: String!
plural: String!
description: String
initialColumns: [String!]!
pageSize: Int!
labelField: String!
fields: [KeystoneAdminUIFieldMeta!]!
groups: [KeystoneAdminUIFieldGroupMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean!
}

type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
isNonNull: [KeystoneAdminUIFieldMetaIsNonNull!]
fieldMeta: JSON
viewsIndex: Int!
customViewsIndex: Int
createView: KeystoneAdminUIFieldMetaCreateView!
listView: KeystoneAdminUIFieldMetaListView!
itemView(id: ID): KeystoneAdminUIFieldMetaItemView
search: QueryMode
}

enum KeystoneAdminUIFieldMetaIsNonNull {
read
create
update
}

type KeystoneAdminUIFieldMetaCreateView {
fieldMode: KeystoneAdminUIFieldMetaCreateViewFieldMode!
}

enum KeystoneAdminUIFieldMetaCreateViewFieldMode {
edit
hidden
}

type KeystoneAdminUIFieldMetaListView {
fieldMode: KeystoneAdminUIFieldMetaListViewFieldMode!
}

enum KeystoneAdminUIFieldMetaListViewFieldMode {
read
hidden
}

type KeystoneAdminUIFieldMetaItemView {
fieldMode: KeystoneAdminUIFieldMetaItemViewFieldMode
fieldPosition: KeystoneAdminUIFieldMetaItemViewFieldPosition
}

enum KeystoneAdminUIFieldMetaItemViewFieldMode {
edit
read
hidden
}

enum KeystoneAdminUIFieldMetaItemViewFieldPosition {
form
sidebar
}

enum QueryMode {
default
insensitive
}

type KeystoneAdminUIFieldGroupMeta {
label: String!
description: String
fields: [KeystoneAdminUIFieldMeta!]!
}

type KeystoneAdminUISort {
field: String!
direction: KeystoneAdminUISortDirection!
}

enum KeystoneAdminUISortDirection {
ASC
DESC
}
Loading