From 66ab8e2a36d729bd6a9c9d5f9fd92eaccdf04296 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 28 Jul 2020 13:41:24 +1000 Subject: [PATCH] Update usage of createItems --- .changeset/hot-olives-reply.md | 24 ++ docs/tutorials/initial-data.md | 281 ------------------ packages/keystone/README.md | 45 --- packages/keystone/lib/Keystone/index.js | 39 --- packages/keystone/tests/Keystone.test.js | 189 ------------ packages/server-side-graphql-client/index.js | 2 +- .../lib/server-side-graphql-client.js | 90 +----- .../tests/index.test.js | 20 +- 8 files changed, 47 insertions(+), 643 deletions(-) create mode 100644 .changeset/hot-olives-reply.md diff --git a/.changeset/hot-olives-reply.md b/.changeset/hot-olives-reply.md new file mode 100644 index 00000000000..e3faf7f81c0 --- /dev/null +++ b/.changeset/hot-olives-reply.md @@ -0,0 +1,24 @@ +--- +'@keystonejs/keystone': major +--- + +Removed the `keystone.createItems` method. This has been replaced with the `createItems` function in `@keystonejs/server-side-graphql-client`. + +If you have examples like: + +``` +keystone.createItems({ + User: [{ name: 'Ticiana' }, { name: 'Lauren' }], +}); +``` + +You will need to change this to: + +``` +const { createItems } = require('@keystonejs/server-side-graphql-client'); +createItems({ + keystone, + listName: 'User', + items: [{ data: { name: 'Ticiana' } }, {data: { name: 'Lauren' } }] +}) +``` \ No newline at end of file diff --git a/docs/tutorials/initial-data.md b/docs/tutorials/initial-data.md index a3279ff0f5f..6436bceef13 100644 --- a/docs/tutorials/initial-data.md +++ b/docs/tutorials/initial-data.md @@ -74,284 +74,3 @@ module.exports = { ``` > **Tip:** A similar setup can be achieved by running the Keystone CLI `yarn create keystone-app` and selecting `Starter (Users + Authentication)`. This starter project has a `User` list, `PasswordAuthStrategy` and seeding of the database already configured. For now, we will proceed manually. - -## Creating items - -The `createItems` method requires an object where keys are list keys, and values -are arrays of items to insert. For example: - -```javascript -keystone.createItems({ - User: [ - { name: 'John Duck', email: 'john@duck.com', password: 'dolphins' }, - { name: 'Barry', email: 'bartduisters@bartduisters.com', password: 'dolphins' }, - ], -}); -``` - -> **Note:** The format of the data must match the schema setup with calls to `keystone.createList()`. As an example in our schema the `email` field has `isUnique: true`, therefore it would not be possible for the above code to have the same email for each user that should be generated. - -Example on how to `seed` the data upon database connection: - -```javascript -const keystone = new Keystone({ - adapter: new MongooseAdapter(), - onConnect: async keystone => { - await keystone.createItems({ - User: [ - { name: 'John Duck', email: 'john@duck.com', password: 'dolphins' }, - { name: 'Barry', email: 'bartduisters@bartduisters.com', password: 'dolphins' }, - ], - }); - }, -}); -``` - -Start the application and visit the Admin UI, two users are available on startup. - -> **Note:** In this example the same two users would be generated _every_ startup. Since email should be unique this will cause a duplicate error to show up. To avoid this, clear the database before starting Keystone. - -## Relationships - -It is possible to create relationships between items while seeding the database -by using the Keystone query syntax. - -### Single relationships - -Add the `Relationship` field to the imports: - -```javascript -const { Text, Checkbox, Password, Relationship } = require('@keystonejs/fields'); -``` - -Create a list with a relationship to another list: - -```javascript -keystone.createList('Post', { - fields: { - title: { - type: Text, - }, - author: { - type: Relationship, - ref: 'User', - }, - }, -}); -``` - -Example on how to seed an item with a relationship: - -```javascript -Post: [ - { - title: 'Hello World', - author: { where: { name: 'John Duck' } }, - }, -], -``` - -The full example: - -```javascript -const keystone = new Keystone({ - adapter: new MongooseAdapter(), - onConnect: async keystone => { - await keystone.createItems({ - User: [ - { name: 'John Duck', email: 'john@duck.com', password: 'dolphins' }, - { name: 'Barry', email: 'bartduisters@bartduisters.com', password: 'dolphins' }, - ], - Post: [ - { - title: 'Hello World', - author: { where: { name: 'John Duck' } }, - }, - ], - }); - }, -}); -``` - -Upon insertion, Keystone will resolve the `{ where: { name: 'John Duck' } }` query -against the `User` list, ultimately setting the `author` field to the ID of the -_first_ `User` that is found. - -> **Note:** An error is thrown if no items match the query. - -Clear the database, then start Keystone and visit the Admin UI to see that two users are generated and one post is generated. The post has an `author` named `John Duck`. In the database `author` will be the ID of the user with name John Duck. - -### Many relationships - -A user can have many posts, add the `to-many` relationship field `posts` to the `User`: - -```javascript -keystone.createList('User', { - fields: { - name: { type: Text }, - email: { - type: Text, - isUnique: true, - }, - isAdmin: { type: Checkbox }, - password: { - type: Password, - }, - posts: { - type: Relationship, - ref: 'Post', - many: true, - }, - }, -}); -``` - -There are two ways to write the query for `to-many` relationships: - -1. _Single Relation syntax_ uses the same query as a Single Relationship, but - instead of picking only the first item found, it will pick _all_ the items - found to match the query. This could be 0, 1, or _n_ items. -2. _Array Relation syntax_ allows to explicitly set multiple queries to match. - -#### Single relation syntax example - -To get all posts where the `title` field contains the word `React`: - -```javascript -posts: { - where: { - title_contains: 'React'; - } -} -``` - -In action: - -```javascript -const keystone = new Keystone({ - adapter: new MongooseAdapter(), - onConnect: async keystone => { - await keystone.createItems({ - User: [ - { - name: 'John Duck', - email: 'john@duck.com', - password: 'dolphins', - posts: { where: { title_contains: 'React' } }, - }, - { - name: 'Barry', - email: 'bartduisters@bartduisters.com', - password: 'dolphins', - isAdmin: true, - }, - ], - Post: [ - { title: 'Hello Everyone' }, - { title: 'Talking about React' }, - { title: 'React is the Best' }, - { title: 'Keystone Rocks' }, - ], - }); - }, -}); -``` - -Clear the database, start the Keystone application and visit the Admin UI. Take a look at the user `John Duck`, he has two posts associated with him (there were two posts with the word `React` in the `title`). - -#### Array relation syntax example - -```javascript -const keystone = new Keystone({ - adapter: new MongooseAdapter(), - onConnect: async keystone => { - await keystone.createItems({ - User: [ - { - name: 'John Duck', - email: 'john@duck.com', - password: 'dolphins', - posts: { where: { title_contains: 'React' } }, - }, - { - name: 'Barry', - email: 'bartduisters@bartduisters.com', - password: 'dolphins', - isAdmin: true, - }, - ], - Post: [ - { title: 'Hello Everyone' }, - { title: 'Talking about React' }, - { title: 'React is the Best' }, - { title: 'Keystone Rocks' }, - ], - }); - }, -}); -``` - -> **Note:** When using the Array Relation syntax, If any of the queries do not match any items, an Error will be thrown. - -Clear the database, start Keystone and visit the Admin UI. Take a look at both users, they each now have two posts associated with them. `John Duck` has the posts that contain `React` in the title. `Barry` has the posts that matched any of the queries in the array. - -> **Note:** When looking at the posts, there are _no_ associated users! To have both the user associated with the post as well is called `back reference`, this will be handled in a later chapter. - -## Keystone query syntax - -The entire power of [Keystone Query Syntax](https://www.keystonejs.com/guides/intro-to-graphql#filter-limit-and-sorting) is supported. - -If you need the 3rd item that matches the query, you'd use a query like: - -```javascript -keystone.createItems({ - User: [ - { name: 'Jed' }, - { name: 'Lauren' }, - { name: 'Jess' }, - { name: 'Lauren' }, - { name: 'John' }, - ], - Post: [ - { - title: 'Hello World', - author: { - where: { - name_starts_with: 'J', - skip: 2, - }, - }, - }, - ], -}); -``` - -This will match all users whose name starts with `'J'`, skipping the first two matches, -ultimately matching against `'John'`. - -## Error handling - -If an error occurs during insertion, data may be left in an inconsistent state. -We highly encourage you to take regular backups of your data, especially before -calling `createItems()`. - -If an error occurs during the relationship resolution phase (see -_[Relationships](#relationships)_), any inserted items will be automatically -deleted for you, leaving the data in a consistent state. - -## Limitations - -`Keystone::createItems()` does not provide the full functionality that the -GraphQL endpoint does. - -Limitations include: - -- You cannot update existing items in the database -- You cannot delete existing items in the database - - - -When these limitations apply to your task at hand, we recommend using the -GraphQL API instead. It is more verbose, but much more powerful. diff --git a/packages/keystone/README.md b/packages/keystone/README.md index bd205f16ba6..eb53a9a8091 100644 --- a/packages/keystone/README.md +++ b/packages/keystone/README.md @@ -144,7 +144,6 @@ _**Default:**_ `['public']` | --------------------- | ---------------------------------------------------------------------------- | | `connect` | Manually connect to Adapters. | | `createAuthStrategy` | Creates a new authentication middleware instance. | -| `createItems` | Add items to a `Keystone` list. | | `createList` | Add a list to the `Keystone` schema. | | `disconnect` | Disconnect from all adapters. | | `extendGraphQLSchema` | Extend keystones generated schema with custom types, queries, and mutations. | @@ -188,50 +187,6 @@ Creates a new authentication middleware instance. See: const authStrategy = keystone.createAuthStrategy({...}); ``` -### `createItems(items)` - -Allows bulk creation of items. This method's primary use is intended for migration scripts, or initial seeding of databases. - -```javascript -keystone.createItems({ - User: [{ name: 'Ticiana' }, { name: 'Lauren' }], - Post: [ - { - title: 'Hello World', - author: { where: { name: 'Ticiana' } }, - }, - ], -}); -``` - -The `author` field of the `Post` list would have the following configuration: - -```javascript -keystone.createList('Post', { - fields: { - author: { type: Relationship, ref: 'User' }, - }, -}); -``` - -#### Config - -| Option | Type | Description | -| ----------- | -------- | ------------------------------------------------------------------------------- | -| `[listKey]` | `Object` | An object where keys are list keys, and values are an array of items to insert. | - -_Note_: The format of the data must match the lists and fields setup with `keystone.createList()` - -It is possible to create relationships at insertion using the Keystone query syntax. - -E.g. `author: { where: { name: 'Ticiana' } }` - -Upon insertion, Keystone will resolve the `{ where: { name: 'Ticiana' } }` query -against the `User` list, ultimately setting the `author` field to the ID of the -_first_ `User` that is found. - -Note an error is thrown if no items match the query. - ### `createList(listKey, config)` Registers a new list with Keystone and returns a `Keystone` list object. See: diff --git a/packages/keystone/lib/Keystone/index.js b/packages/keystone/lib/Keystone/index.js index 2a8aa1c2691..f11895f4a74 100644 --- a/packages/keystone/lib/Keystone/index.js +++ b/packages/keystone/lib/Keystone/index.js @@ -23,11 +23,6 @@ const { const { SessionManager } = require('@keystonejs/session'); const { AppVersionProvider, appVersionMiddleware } = require('@keystonejs/app-version'); -const { - unmergeRelationships, - createRelationships, - mergeRelationships, -} = require('./relationship-utils'); const { List } = require('../ListTypes'); const { DEFAULT_DIST_DIR } = require('../../constants'); const { CustomProvider, ListAuthProvider, ListCRUDProvider } = require('../providers'); @@ -567,40 +562,6 @@ module.exports = class Keystone { return ['scalar Upload', ...this.getTypeDefs({ schemaName }).map(t => print(t))].join('\n'); } - createItem(listKey, itemData) { - return this.lists[listKey].adapter.create(itemData); - } - - async createItems(itemsToCreate) { - // 1. Split it apart - const { relationships, data } = unmergeRelationships(this.lists, itemsToCreate); - // 2. Create the items - // NOTE: Only works if all relationships fields are non-"required" - const createdItems = await resolveAllKeys( - mapKeys(data, (items, listKey) => - Promise.all(items.map(itemData => this.createItem(listKey, itemData))) - ) - ); - - let createdRelationships; - try { - // 3. Create the relationships - createdRelationships = await createRelationships(this.lists, relationships, createdItems); - } catch (error) { - // 3.5. If creation of relationships didn't work, unwind the createItems - Promise.all( - Object.entries(createdItems).map(([listKey, items]) => - Promise.all(items.map(({ id }) => this.lists[listKey].adapter.delete(id))) - ) - ); - // Re-throw the error now that we've cleaned up - throw error; - } - - // 4. Merge the data back together again - return mergeRelationships(createdItems, createdRelationships); - } - async _prepareMiddlewares({ dev, apps, distDir, pinoOptions, cors }) { return flattenDeep([ this.appVersion.addVersionToHttpHeaders && appVersionMiddleware(this.appVersion.version), diff --git a/packages/keystone/tests/Keystone.test.js b/packages/keystone/tests/Keystone.test.js index cf72a87688c..4c1dde8a97a 100644 --- a/packages/keystone/tests/Keystone.test.js +++ b/packages/keystone/tests/Keystone.test.js @@ -1,8 +1,6 @@ const isPromise = require('p-is-promise'); const Keystone = require('../lib/Keystone'); const { List } = require('../lib/ListTypes'); -const { Text, Relationship } = require('@keystonejs/fields'); - class MockFieldAdapter {} class MockFieldImplementation { @@ -242,193 +240,6 @@ describe('Keystone.extendGraphQLSchema()', () => { }); }); -describe('Keystone.createItems()', () => { - const lists = { - User: { - key: 'User', - _fields: { - name: { type: Text }, - posts: { type: Relationship, many: true, ref: 'Post' }, - }, - adapter: { - create: jest.fn(), - update: jest.fn(), - delete: jest.fn(), - itemsQuery: jest.fn(), - }, - }, - Post: { - key: 'Post', - _fields: { - title: { type: Text }, - author: { type: Relationship, ref: 'User' }, - }, - adapter: { - create: jest.fn(), - update: jest.fn(), - delete: jest.fn(), - itemsQuery: jest.fn(), - }, - }, - }; - - function setupMocks() { - const created = {}; - - // Create mocks - let id = 1; - Object.keys(lists).forEach(listKey => { - lists[listKey].adapter.create.mockImplementation(input => { - const newItem = { id: id++, ...input }; - created[listKey] = created[listKey] || []; - created[listKey].push(newItem); - return newItem; - }); - - // Update mocks - lists[listKey].adapter.update.mockImplementation((_, data) => data); - }); - - // Query mocks - lists.User.adapter.itemsQuery.mockImplementation(({ where: { name } }) => - created.User.filter(item => item.name === name) - ); - lists.Post.adapter.itemsQuery.mockImplementation(({ where: { title } }) => - created.Post.filter(item => item.title === title) - ); - } - - beforeEach(() => { - // Reset call counts, etc, back to normal - lists.User.adapter.itemsQuery.mockReset(); - lists.User.adapter.create.mockReset(); - lists.User.adapter.update.mockReset(); - lists.User.adapter.delete.mockReset(); - lists.Post.adapter.itemsQuery.mockReset(); - lists.Post.adapter.create.mockReset(); - lists.Post.adapter.update.mockReset(); - lists.Post.adapter.delete.mockReset(); - }); - - test('creates items', async () => { - const keystone = new Keystone({ - adapter: new MockAdapter(), - cookieSecret: 'secretForTesting', - }); - - // mock the lists - keystone.lists = lists; - - setupMocks(); - - await keystone.createItems({ - User: [{ name: 'Jess' }, { name: 'Lauren' }], - Post: [{ title: 'Hello world' }, { title: 'Goodbye' }], - }); - - expect(keystone.lists.User.adapter.create).toHaveBeenCalledWith({ - name: 'Jess', - }); - expect(keystone.lists.User.adapter.create).toHaveBeenCalledWith({ - name: 'Lauren', - }); - expect(keystone.lists.Post.adapter.create).toHaveBeenCalledWith({ - title: 'Hello world', - }); - expect(keystone.lists.Post.adapter.create).toHaveBeenCalledWith({ - title: 'Goodbye', - }); - }); - - test('returns the created items', async () => { - const keystone = new Keystone({ - adapter: new MockAdapter(), - cookieSecret: 'secretForTesting', - }); - - // mock the lists - keystone.lists = lists; - - setupMocks(); - - const createdItems = await keystone.createItems({ - User: [{ name: 'Jess' }, { name: 'Lauren' }], - Post: [{ title: 'Hello world' }, { title: 'Goodbye' }], - }); - - expect(createdItems).toEqual({ - User: [ - { id: 1, name: 'Jess' }, - { id: 2, name: 'Lauren' }, - ], - Post: [ - { id: 3, title: 'Hello world' }, - { id: 4, title: 'Goodbye' }, - ], - }); - }); - - test('creates items and adds in relationships', async () => { - const keystone = new Keystone({ - adapter: new MockAdapter(), - cookieSecret: 'secretForTesting', - }); - - // mock the lists - keystone.lists = lists; - - setupMocks(); - - const createdItems = await keystone.createItems({ - User: [{ name: 'Jess' }, { name: 'Lauren' }], - Post: [ - { title: 'Hello world', author: { where: { name: 'Lauren' } } }, - { title: 'Goodbye', author: { where: { name: 'Jess' } } }, - ], - }); - - expect(createdItems).toEqual({ - User: [ - { id: 1, name: 'Jess' }, - { id: 2, name: 'Lauren' }, - ], - Post: [ - { id: 3, title: 'Hello world', author: 2 }, - { id: 4, title: 'Goodbye', author: 1 }, - ], - }); - }); - - test('deletes created items when relationships fail', async () => { - const keystone = new Keystone({ - adapter: new MockAdapter(), - cookieSecret: 'secretForTesting', - }); - - // mock the lists - keystone.lists = lists; - - setupMocks(); - - try { - await keystone.createItems({ - User: [{ name: 'Jess' }, { name: 'Lauren' }], - Post: [ - { title: 'Hello world', author: { where: { name: 'Not Real' } } }, - { title: 'Goodbye', author: { where: { name: 'No Go' } } }, - ], - }); - } catch (error) { - // ignore - } finally { - expect(keystone.lists.User.adapter.delete).toHaveBeenCalledWith(1); - expect(keystone.lists.User.adapter.delete).toHaveBeenCalledWith(2); - expect(keystone.lists.Post.adapter.delete).toHaveBeenCalledWith(3); - expect(keystone.lists.Post.adapter.delete).toHaveBeenCalledWith(4); - } - }); -}); - describe('keystone.prepare()', () => { test('returns a Promise', () => { const config = { diff --git a/packages/server-side-graphql-client/index.js b/packages/server-side-graphql-client/index.js index 7b4d2a6b4a3..daa104234d8 100644 --- a/packages/server-side-graphql-client/index.js +++ b/packages/server-side-graphql-client/index.js @@ -8,7 +8,7 @@ const { updateItems, deleteItem, deleteItems, -} = require("./lib/server-side-graphql-client"); +} = require('./lib/server-side-graphql-client'); module.exports = { runCustomQuery, diff --git a/packages/server-side-graphql-client/lib/server-side-graphql-client.js b/packages/server-side-graphql-client/lib/server-side-graphql-client.js index c81c11210d7..f10cc5c4865 100644 --- a/packages/server-side-graphql-client/lib/server-side-graphql-client.js +++ b/packages/server-side-graphql-client/lib/server-side-graphql-client.js @@ -2,11 +2,7 @@ const runQuery = async ({ keystone, query, variables, context }) => { const { data, errors } = await keystone.executeGraphQL({ context: context || - keystone.createContext({ - schemaName: "public", - authentication: {}, - skipAccessControl: true, - }), + keystone.createContext({ schemaName: 'public', authentication: {}, skipAccessControl: true }), query, variables, @@ -15,14 +11,7 @@ const runQuery = async ({ keystone, query, variables, context }) => { return data; }; -const _runChunkedMutation = async ({ - keystone, - query, - gqlName, - pageSize, - items, - context, -}) => { +const _runChunkedMutation = async ({ keystone, query, gqlName, pageSize, items, context }) => { if (pageSize <= 0) pageSize = 1; const chunks = items.reduce((accum, item, index) => { @@ -38,9 +27,7 @@ const _runChunkedMutation = async ({ }, []); const result = await Promise.all( - chunks.map((chunk) => - runQuery({ query, variables: { items: chunk }, keystone, context }) - ) + chunks.map(chunk => runQuery({ query, variables: { items: chunk }, keystone, context })) ); /* @@ -48,30 +35,17 @@ const _runChunkedMutation = async ({ * We need to combine all objects into one array keyed by the `createUsers`, such that, the output is: [{id: '123', name: 'aman'}, {id: '456', name: 'Mike'}] */ - return [].concat(...result.map((item) => item[gqlName])); + return [].concat(...result.map(item => item[gqlName])); }; -const createItem = async ({ - keystone, - listKey, - item, - returnFields = `id`, - context, -}) => { - const { createMutationName, createInputName } = keystone.lists[ - listKey - ].gqlNames; +const createItem = async ({ keystone, listKey, item, returnFields = `id`, context }) => { + const { createMutationName, createInputName } = keystone.lists[listKey].gqlNames; const query = `mutation ($item: ${createInputName}){ ${createMutationName}(data: $item) { ${returnFields} } }`; - const result = await runQuery({ - keystone, - query, - variables: { item }, - context, - }); + const result = await runQuery({ keystone, query, variables: { item }, context }); return result[createMutationName]; }; @@ -83,9 +57,7 @@ const createItems = async ({ returnFields = `id`, context, }) => { - const { createManyMutationName, createManyInputName } = keystone.lists[ - listKey - ].gqlNames; + const { createManyMutationName, createManyInputName } = keystone.lists[listKey].gqlNames; const query = `mutation ($items: [${createManyInputName}]){ ${createManyMutationName}(data: $items) { ${returnFields} } @@ -101,22 +73,11 @@ const createItems = async ({ }); }; -const getItem = async ({ - keystone, - listKey, - itemId, - returnFields = `id`, - context, -}) => { +const getItem = async ({ keystone, listKey, itemId, returnFields = `id`, context }) => { const { itemQueryName } = keystone.lists[listKey].gqlNames; const query = `query ($id: ID!) { ${itemQueryName}(where: { id: $id }) { ${returnFields} } }`; - const result = await runQuery({ - keystone, - query, - variables: { id: itemId }, - context, - }); + const result = await runQuery({ keystone, query, variables: { id: itemId }, context }); return result[itemQueryName]; }; @@ -153,16 +114,8 @@ const getItems = async ({ return allItems; }; -const updateItem = async ({ - keystone, - listKey, - item, - returnFields = `id`, - context, -}) => { - const { updateMutationName, updateInputName } = keystone.lists[ - listKey - ].gqlNames; +const updateItem = async ({ keystone, listKey, item, returnFields = `id`, context }) => { + const { updateMutationName, updateInputName } = keystone.lists[listKey].gqlNames; const query = `mutation ($id: ID!, $data: ${updateInputName}){ ${updateMutationName}(id: $id, data: $data) { ${returnFields} } @@ -186,9 +139,7 @@ const updateItems = async ({ returnFields = `id`, context, }) => { - const { updateManyMutationName, updateManyInputName } = keystone.lists[ - listKey - ].gqlNames; + const { updateManyMutationName, updateManyInputName } = keystone.lists[listKey].gqlNames; const query = `mutation ($items: [${updateManyInputName}]){ ${updateManyMutationName}(data: $items) { ${returnFields} } @@ -203,25 +154,14 @@ const updateItems = async ({ }); }; -const deleteItem = async ({ - keystone, - listKey, - itemId, - returnFields = `id`, - context, -}) => { +const deleteItem = async ({ keystone, listKey, itemId, returnFields = `id`, context }) => { const { deleteMutationName } = keystone.lists[listKey].gqlNames; const query = `mutation ($id: ID!){ ${deleteMutationName}(id: $id) { ${returnFields} } }`; - const result = await runQuery({ - keystone, - query, - variables: { id: itemId }, - context, - }); + const result = await runQuery({ keystone, query, variables: { id: itemId }, context }); return result[deleteMutationName]; }; diff --git a/packages/server-side-graphql-client/tests/index.test.js b/packages/server-side-graphql-client/tests/index.test.js index 3714cc2f789..49a73878dae 100644 --- a/packages/server-side-graphql-client/tests/index.test.js +++ b/packages/server-side-graphql-client/tests/index.test.js @@ -12,10 +12,7 @@ const { updateItems, } = require('../index'); -const testData = [ - { data: { name: 'test', age: 30 } }, - { data: { name: 'test2', age: 40 } }, -]; +const testData = [{ data: { name: 'test', age: 30 } }, { data: { name: 'test2', age: 40 } }]; const schemaName = 'testing'; const seedDb = ({ keystone }) => @@ -29,7 +26,7 @@ const seedDb = ({ keystone }) => function setupKeystone(adapterName) { return setupServer({ adapterName, - createLists: (keystone) => { + createLists: keystone => { keystone.createList('Test', { fields: { name: { type: Text }, @@ -85,7 +82,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => context: keystone.createContext({ schemaName }), }); - expect(allItems).toEqual(testData.map((x) => x.data)); + expect(allItems).toEqual(testData.map(x => x.data)); }) ); }); @@ -116,10 +113,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => const items = await updateItems({ keystone, listKey: 'Test', - items: seedItems.map((item, i) => ({ - id: item.id, - data: { name: `update-${i}` }, - })), + items: seedItems.map((item, i) => ({ id: item.id, data: { name: `update-${i}` } })), returnFields: 'name, age', context: keystone.createContext({ schemaName }), }); @@ -167,11 +161,11 @@ multiAdapterRunners().map(({ runner, adapterName }) => keystone, listKey: 'Test', returnFields: 'name age', - items: items.map((item) => item.id), + items: items.map(item => item.id), context: keystone.createContext({ schemaName }), }); - expect(deletedItems).toEqual(testData.map((d) => d.data)); + expect(deletedItems).toEqual(testData.map(d => d.data)); // Get all the items back from db const allItems = await getItems({ @@ -198,7 +192,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => context: keystone.createContext({ schemaName }), }); - expect(allItems).toEqual(testData.map((x) => x.data)); + expect(allItems).toEqual(testData.map(x => x.data)); }) ); test(