Skip to content

Commit

Permalink
Refactor Admin Meta GraphQL Schema (#7844)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
  • Loading branch information
emmatown and dcousens authored Aug 29, 2022
1 parent 18e29b5 commit bce4c0c
Show file tree
Hide file tree
Showing 213 changed files with 790 additions and 953 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-nouns-fall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Changes list configuration naming from `lists` to `models`, as part of adding support for Singletons
4 changes: 2 additions & 2 deletions examples/assets-local/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { config } from '@keystone-6/core';
import { lists } from './schema';
import { models } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
models,
storage: {
my_images: {
kind: 'local',
Expand Down
2 changes: 0 additions & 2 deletions examples/assets-local/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
2 changes: 1 addition & 1 deletion examples/assets-local/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { list } from '@keystone-6/core';
import { select, relationship, text, timestamp, image, file } from '@keystone-6/core/fields';

export const lists = {
export const models = {
Post: list({
fields: {
title: text({ validation: { isRequired: true } }),
Expand Down
4 changes: 2 additions & 2 deletions examples/assets-s3/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from '@keystone-6/core';
import dotenv from 'dotenv';
import { lists } from './schema';
import { models } from './schema';

dotenv.config();

Expand All @@ -16,7 +16,7 @@ export default config({
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
models,
storage: {
my_images: {
kind: 's3',
Expand Down
2 changes: 0 additions & 2 deletions examples/assets-s3/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
2 changes: 1 addition & 1 deletion examples/assets-s3/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { list } from '@keystone-6/core';
import { select, relationship, text, timestamp, image, file } from '@keystone-6/core/fields';

export const lists = {
export const models = {
Post: list({
fields: {
title: text({ validation: { isRequired: true } }),
Expand Down
4 changes: 2 additions & 2 deletions examples/auth/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { config } from '@keystone-6/core';
import { statelessSessions } from '@keystone-6/core/session';
import { createAuth } from '@keystone-6/auth';
import { lists } from './schema';
import { models } from './schema';

/**
* TODO: Implement validateItem. Would be invoked by the getItem() method in
Expand Down Expand Up @@ -63,7 +63,7 @@ export default withAuth(
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
models,
ui: {},
session:
// Stateless sessions will store the listKey and itemId of the signed-in user in a cookie
Expand Down
2 changes: 0 additions & 2 deletions examples/auth/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
2 changes: 1 addition & 1 deletion examples/auth/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { list } from '@keystone-6/core';
import { text, checkbox, password } from '@keystone-6/core/fields';

export const lists = {
export const models = {
User: list({
access: {
operation: {
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { config } from '@keystone-6/core';
import { statelessSessions } from '@keystone-6/core/session';
import { createAuth } from '@keystone-6/auth';

import { lists, extendGraphqlSchema } from './schema';
import { models, extendGraphqlSchema } from './schema';

let sessionSecret = '-- DEV COOKIE SECRET; CHANGE ME --';
let sessionMaxAge = 60 * 60 * 24 * 30; // 30 days
Expand Down Expand Up @@ -54,7 +54,7 @@ export default auth.withAuth(
},
},
},
lists,
models,
extendGraphqlSchema,
session: statelessSessions({ maxAge: sessionMaxAge, secret: sessionSecret }),
// TODO -- Create a separate example for stored/redis sessions
Expand Down
2 changes: 0 additions & 2 deletions examples/basic/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@keystone-6/core/fields';
import { document } from '@keystone-6/fields-document';
import { v4 } from 'uuid';
import { Context, Lists } from '.keystone/types';
import { Context, Models } from '.keystone/types';

type AccessArgs = {
session?: {
Expand All @@ -32,7 +32,7 @@ export const access = {

const randomNumber = () => Math.round(Math.random() * 10);

const User: Lists.User = list({
const User: Models.User = list({
ui: {
listView: {
initialColumns: ['name', 'posts', 'avatar'],
Expand Down Expand Up @@ -91,7 +91,7 @@ const User: Lists.User = list({
},
});

export const lists: Lists = {
export const models: Models = {
User,
PhoneNumber: list({
ui: {
Expand Down
4 changes: 2 additions & 2 deletions examples/blog/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config } from '@keystone-6/core';
import { lists } from './schema';
import { models } from './schema';
import { insertSeedData } from './seed-data';
import { Context } from '.keystone/types';

Expand All @@ -13,5 +13,5 @@ export default config({
}
},
},
lists,
models,
});
2 changes: 0 additions & 2 deletions examples/blog/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
2 changes: 1 addition & 1 deletion examples/blog/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { list } from '@keystone-6/core';
import { select, relationship, text, timestamp } from '@keystone-6/core/fields';

export const lists = {
export const models = {
Post: list({
fields: {
title: text({ validation: { isRequired: true } }),
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-admin-ui-logo/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { config } from '@keystone-6/core';
import { lists } from './schema';
import { models } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
models,
ui: {},
});
2 changes: 0 additions & 2 deletions examples/custom-admin-ui-logo/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-admin-ui-logo/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { list } from '@keystone-6/core';
import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields';
import { select } from '@keystone-6/core/fields';

export const lists = {
export const models = {
Task: list({
fields: {
label: text({ validation: { isRequired: true } }),
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-admin-ui-navigation/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { config } from '@keystone-6/core';
import { lists } from './schema';
import { models } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
models,
});
2 changes: 0 additions & 2 deletions examples/custom-admin-ui-navigation/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-admin-ui-navigation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { list } from '@keystone-6/core';
import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields';
import { select } from '@keystone-6/core/fields';

export const lists = {
export const models = {
Task: list({
fields: {
label: text({ validation: { isRequired: true } }),
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-admin-ui-pages/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { config } from '@keystone-6/core';
import { lists } from './schema';
import { models } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
models,
});
2 changes: 0 additions & 2 deletions examples/custom-admin-ui-pages/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-admin-ui-pages/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { list } from '@keystone-6/core';
import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields';
import { select } from '@keystone-6/core/fields';

export const lists = {
export const models = {
Task: list({
fields: {
label: text({ validation: { isRequired: true } }),
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-field-view/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { config } from '@keystone-6/core';
import { lists } from './schema';
import { models } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
models,
});
2 changes: 0 additions & 2 deletions examples/custom-field-view/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ type KeystoneMeta {
}

type KeystoneAdminMeta {
enableSignout: Boolean!
enableSessionItem: Boolean!
lists: [KeystoneAdminUIListMeta!]!
list(key: String!): KeystoneAdminUIListMeta
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-field-view/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { list } from '@keystone-6/core';
import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields';
import { json, select } from '@keystone-6/core/fields';

export const lists = {
export const models = {
Task: list({
fields: {
label: text({ validation: { isRequired: true } }),
Expand Down
10 changes: 5 additions & 5 deletions examples/custom-field/1-text-field/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
BaseListTypeInfo,
BaseModelTypeInfo,
fieldType,
FieldTypeFunc,
CommonFieldConfig,
Expand All @@ -8,15 +8,15 @@ import {
} from '@keystone-6/core/types';
import { graphql } from '@keystone-6/core';

export type TextFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
export type TextFieldConfig<ModelTypeInfo extends BaseModelTypeInfo> =
CommonFieldConfig<ModelTypeInfo> & {
isIndexed?: boolean | 'unique';
};

export function text<ListTypeInfo extends BaseListTypeInfo>({
export function text<ModelTypeInfo extends BaseModelTypeInfo>({
isIndexed,
...config
}: TextFieldConfig<ListTypeInfo> = {}): FieldTypeFunc<ListTypeInfo> {
}: TextFieldConfig<ModelTypeInfo> = {}): FieldTypeFunc<ModelTypeInfo> {
return meta =>
fieldType({
kind: 'scalar',
Expand Down
10 changes: 5 additions & 5 deletions examples/custom-field/2-stars-field/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
BaseListTypeInfo,
BaseModelTypeInfo,
fieldType,
FieldTypeFunc,
CommonFieldConfig,
Expand All @@ -13,18 +13,18 @@ import { graphql } from '@keystone-6/core';
// and a different input in the Admin UI
// https://github.com/keystonejs/keystone/tree/main/packages/core/src/fields/types/integer

export type StarsFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
export type StarsFieldConfig<ModelTypeInfo extends BaseModelTypeInfo> =
CommonFieldConfig<ModelTypeInfo> & {
isIndexed?: boolean | 'unique';
maxStars?: number;
};

export const stars =
<ListTypeInfo extends BaseListTypeInfo>({
<ModelTypeInfo extends BaseModelTypeInfo>({
isIndexed,
maxStars = 5,
...config
}: StarsFieldConfig<ListTypeInfo> = {}): FieldTypeFunc<ListTypeInfo> =>
}: StarsFieldConfig<ModelTypeInfo> = {}): FieldTypeFunc<ModelTypeInfo> =>
meta =>
fieldType({
// this configures what data is stored in the database
Expand Down
Loading

0 comments on commit bce4c0c

Please sign in to comment.