Skip to content

Commit

Permalink
Replace listName with listKey
Browse files Browse the repository at this point in the history
  • Loading branch information
singhArmani committed Jul 28, 2020
1 parent d238fee commit 461cf01
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 84 deletions.
6 changes: 3 additions & 3 deletions api-tests/access-control/authed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ multiAdapterRunners().map(({ before, after, adapterName }) =>

items = {};
const context = keystone.createContext({ schemaName: 'internal' });
for (const [listName, _items] of Object.entries(initialData)) {
items[listName] = await createItems({
for (const [listKey, _items] of Object.entries(initialData)) {
items[listKey] = await createItems({
keystone,
listName,
listKey,
items: _items.map(x => ({ data: x })),
returnFields: 'id, name',
context,
Expand Down
12 changes: 6 additions & 6 deletions api-tests/auth-header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
runner(setupKeystone, async ({ keystone, app }) => {
// seed the db
const context = keystone.createContext({ schemaName, skipAccessControl: true });
for (const [listName, items] of Object.entries(initialData)) {
await createItems({ keystone, listName, items, context });
for (const [listKey, items] of Object.entries(initialData)) {
await createItems({ keystone, listKey, items, context });
}
const { data, errors } = await networkedGraphqlRequest({
app,
Expand All @@ -109,8 +109,8 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
'Allows access with bearer token',
runner(setupKeystone, async ({ keystone, app }) => {
const context = keystone.createContext({ schemaName, skipAccessControl: true });
for (const [listName, items] of Object.entries(initialData)) {
await createItems({ keystone, listName, items, context });
for (const [listKey, items] of Object.entries(initialData)) {
await createItems({ keystone, listKey, items, context });
}
const { token } = await login(
app,
Expand All @@ -137,8 +137,8 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
'Allows access with cookie',
runner(setupKeystone, async ({ keystone, app }) => {
const context = keystone.createContext({ schemaName, skipAccessControl: true });
for (const [listName, items] of Object.entries(initialData)) {
await createItems({ keystone, listName, items, context });
for (const [listKey, items] of Object.entries(initialData)) {
await createItems({ keystone, listKey, items, context });
}
const { token } = await login(
app,
Expand Down
8 changes: 4 additions & 4 deletions api-tests/fields.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ describe('Fields', () => {
multiAdapterRunners().map(({ runner, adapterName }) =>
describe(`${adapterName} adapter`, () => {
testModules.map(require).forEach(mod => {
const listName = 'test';
const listKey = 'test';
const keystoneTestWrapper = (testFn = () => {}) =>
runner(
() => {
const createLists = keystone => {
// Create a list with all the fields required for testing
const fields = mod.getTestFields();

keystone.createList(listName, { fields });
keystone.createList(listKey, { fields });
};
return setupServer({ adapterName, createLists });
},
Expand All @@ -29,11 +29,11 @@ describe('Fields', () => {
const context = keystone.createContext({ schemaName: 'testing' });
await createItems({
keystone,
listName,
listKey,
items: mod.initItems().map(x => ({ data: x })),
context,
});
return testFn({ keystone, listName, adapterName, ...rest });
return testFn({ keystone, listKey, adapterName, ...rest });
}
);

Expand Down
6 changes: 3 additions & 3 deletions api-tests/required.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ describe('Test isRequired flag for all field types', () => {
testModules.map(require).forEach(mod => {
describe(`Test isRequired flag for module: ${mod.name}`, () => {
const type = mod.type;
const listName = 'Test';
const listKey = 'Test';
const keystoneTestWrapper = (testFn = () => {}) =>
runner(
() =>
setupServer({
adapterName,
createLists: keystone => {
if (type.type === 'Select') {
keystone.createList(listName, {
keystone.createList(listKey, {
fields: {
name: { type: Text },
testField: {
Expand All @@ -33,7 +33,7 @@ describe('Test isRequired flag for all field types', () => {
},
});
} else {
keystone.createList(listName, {
keystone.createList(listKey, {
fields: {
name: { type: Text },
testField: { type, isRequired: true },
Expand Down
2 changes: 1 addition & 1 deletion demo-projects/blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const keystone = new Keystone({
const users = await keystone.lists.User.adapter.findAll();
if (!users.length) {
const initialData = require('./initialData');
await createItems({ keystone, listName: 'User', items: initialData.User });
await createItems({ keystone, listKey: 'User', items: initialData.User });
}
},
});
Expand Down
8 changes: 4 additions & 4 deletions demo-projects/meetup/initialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ async function seedData(intitialData, keystone) {
* 2. Insert the data with the required relationships using connect
*/

const { createUsers: users } = await createItems({
const users = await createItems({
keystone,
listName: 'User',
listKey: 'User',
items: initialData['User'].map(x => ({ data: x })),
// name field is required for connect query for setting up Organiser list
returnFields: 'id, name',
});

await Promise.all(
['Event', 'Talk', 'Rsvp', 'Sponsor'].map(list =>
createItems({ keystone, listName: list, items: intitialData[list].map(x => ({ data: x })) })
createItems({ keystone, listKey: list, items: intitialData[list].map(x => ({ data: x })) })
)
);

Expand All @@ -59,7 +59,7 @@ async function seedData(intitialData, keystone) {
.map(createOrganisers(users));

// Run the GraphQL query to insert all the organisers
await createItems({ keystone, listName: 'Organiser', items: organisers });
await createItems({ keystone, listKey: 'Organiser', items: organisers });
}

function createOrganisers(users) {
Expand Down
36 changes: 18 additions & 18 deletions packages/server-side-graphql-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const { createItem } = require('@keystonejs/server-side-graphql-client');

const user = await createItem({
keystone,
listName: 'User',
listKey: 'User',
item: { name: 'Alice' },
returnFields: `id name`,
});
Expand All @@ -47,7 +47,7 @@ These utilities can be used for a wide range of specific use-cases, some more co

```js
const seedUsers = async usersData => {
await createItems({ keystone, listName: 'User', items: usersData });
await createItems({ keystone, listKey: 'User', items: usersData });
};
```

Expand All @@ -67,7 +67,7 @@ keystone.createList('Page', {
const pageToCopy = resolvedData.copy
? await getItem({
keystone,
listName: 'Page',
listKey: 'Page',
itemId: resolvedData.copy,
returnFields: 'name, content',
})
Expand Down Expand Up @@ -101,7 +101,7 @@ The following config options are common to all server-side graphQL functions.
| Properties | Type | Default | Description |
| -------------- | ---------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `keystone` | `Keystone` | (required) | Keystone instance. |
| `listName` | `String` | (required) | Keystone list name. |
| `listKey` | `String` | (required) | Keystone list name. |
| `returnFields` | `String` | `id` | A graphQL fragment of fields to return. Must match the graphQL return type. |
| `context` | `Object` | N/A | An Apollo [`context` object](https://www.apollographql.com/docs/apollo-server/data/resolvers/#the-context-argument). See the [server side graphQL docs](/docs/discussions/server-side-graphql.md) for more details. |

Expand All @@ -124,7 +124,7 @@ keystone.createList('User', {
const addUser = async userInput => {
const user = await createItem({
keystone,
listName: 'User',
listKey: 'User',
item: userInput,
returnFields: `name, email`,
});
Expand All @@ -140,7 +140,7 @@ addUser({ name: 'keystone user', email: '[email protected]' });

| Properties | Type | Default | Description |
| ---------- | ------------------------------- | ---------- | ----------------------- |
| `item` | GraphQL `[listName]CreateInput` | (required) | The item to be created. |
| `item` | GraphQL `[listKey]CreateInput` | (required) | The item to be created. |

### `createItems`

Expand Down Expand Up @@ -168,7 +168,7 @@ const dummyUsers = [
const addUsers = async () => {
const users = await createItems({
keystone,
listName: 'User',
listKey: 'User',
items: dummyUsers,
returnFields: `name`,
});
Expand All @@ -183,7 +183,7 @@ addUsers();

| Properties | Type | Default | Description |
| ---------- | -------------------------------- | ---------- | ---------------------------------------------------------------------------------------------- |
| `items` | GraphQL `[listName]sCreateInput` | (required) | The array of objects to be created. |
| `items` | GraphQL `[listKey]sCreateInput` | (required) | The array of objects to be created. |
| `pageSize` | `Number` | 500 | The create mutation batch size. This is useful when you have large set of data to be inserted. |

### `getItem`
Expand All @@ -205,7 +205,7 @@ keystone.createList('User', {
const getUser = async ({ itemId }) => {
const user = await getItem({
keystone,
listName: 'User',
listKey: 'User',
itemId,
returnFields: 'id, name',
});
Expand Down Expand Up @@ -239,10 +239,10 @@ keystone.createList('User', {
});

const getUsers = async () => {
const allUsers = await getItems({ keystone, listName: 'User', returnFields: 'name' });
const allUsers = await getItems({ keystone, listKey: 'User', returnFields: 'name' });
const someUsers = await getItems({
keystone,
listName: 'User',
listKey: 'User',
returnFields: 'name',
where: { name: 'user1' },
});
Expand All @@ -258,7 +258,7 @@ getUsers();

| Properties | Type | Default | Description |
| ---------- | ------------------------------ | ------- | ---------------------------------------------------------------------------------------------------------- |
| `where` | GraphQL `[listName]WhereInput` | `{}` | Limit results to items matching [where clause](https://www.keystonejs.com/guides/intro-to-graphql/#where). |
| `where` | GraphQL `[listKey]WhereInput` | `{}` | Limit results to items matching [where clause](https://www.keystonejs.com/guides/intro-to-graphql/#where). |
| `pageSize` | `Number` | 500 | The query batch size. Useful when retrieving a large set of data. |

### `updateItem`
Expand All @@ -280,7 +280,7 @@ keystone.createList('User', {
const updateUser = async updateUser => {
const updatedUser = await updateItem({
keystone,
listName: 'User',
listKey: 'User',
item: updateUser,
returnFields: 'name',
});
Expand All @@ -295,7 +295,7 @@ updateUser({ id: '123', data: { name: 'newName' } });

| Properties | Type | Default | Description |
| ---------- | ------------------------------- | ---------- | ----------------------- |
| `item` | GraphQL `[listName]UpdateInput` | (required) | The item to be updated. |
| `item` | GraphQL `[listKey]UpdateInput` | (required) | The item to be updated. |

### `updateItems`

Expand All @@ -316,7 +316,7 @@ keystone.createList('User', {
const updateUsers = async (updateUsers) => {
const users = await updateItems({
keystone,
listName: 'User',
listKey: 'User',
items: updateUsers,
returnFields: 'name'
});
Expand All @@ -336,7 +336,7 @@ updateUsers([
| Properties | Type | Default | Description |
| ---------- | -------------------------------- | ---------- | ----------------------------- |
| `items` | GraphQL `[listName]sUpdateInput` | (required) | Array of items to be updated. |
| `items` | GraphQL `[listKey]sUpdateInput` | (required) | Array of items to be updated. |
### `deleteItem`
Expand All @@ -355,7 +355,7 @@ keystone.createList('User', {
});

const deleteUser = async itemId => {
const user = await deleteItem({ keystone, listName: 'User', itemId });
const user = await deleteItem({ keystone, listKey: 'User', itemId });
console.log(user); // { id: '123' }
};
deleteUser('123');
Expand Down Expand Up @@ -386,7 +386,7 @@ keystone.createList('User', {
});

const deletedUsers = async items => {
const users = await deleteItems({ keystone, listName: 'User', items });
const users = await deleteItems({ keystone, listKey: 'User', items });
console.log(users); // [{id: '123'}, {id: '456'}]
};
deletedUsers(['123', '456']);
Expand Down
Loading

0 comments on commit 461cf01

Please sign in to comment.