Skip to content

Commit

Permalink
Fix yarn lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
singhArmani committed Jul 29, 2020
1 parent 54f56f0 commit c40b816
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 121 deletions.
3 changes: 1 addition & 2 deletions api-tests/access-control/authed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const expectNamedArray = (data, errors, name, values) => {

multiAdapterRunners().map(({ before, after, adapterName }) =>
describe(`Adapter: ${adapterName}`, () => {
let keystone,
items = {};
let keystone, items;
beforeAll(async () => {
const _before = await before(setupKeystone);
keystone = _before.keystone;
Expand Down
2 changes: 1 addition & 1 deletion packages/server-side-graphql-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
updateItems,
deleteItem,
deleteItems,
} = require("./lib/server-side-graphql-client");
} = require('./lib/server-side-graphql-client');

module.exports = {
runCustomQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {
Expand All @@ -38,40 +27,25 @@ 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 }))
);

/*
* The result is of the format: [{createUsers: [{id: '123', name: 'aman'}]}, {createUsers: [{id: '456', name: 'mike'}]}].
* 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];
};

Expand All @@ -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} }
Expand All @@ -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];
};

Expand Down Expand Up @@ -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} }
Expand All @@ -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} }
Expand All @@ -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];
};

Expand Down
15 changes: 6 additions & 9 deletions packages/server-side-graphql-client/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) =>
Expand All @@ -29,7 +26,7 @@ const seedDb = ({ keystone }) =>
function setupKeystone(adapterName) {
return setupServer({
adapterName,
createLists: (keystone) => {
createLists: keystone => {
keystone.createList('Test', {
fields: {
name: { type: Text },
Expand Down Expand Up @@ -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));
})
);
});
Expand Down Expand Up @@ -167,11 +164,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({
Expand All @@ -198,7 +195,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(
Expand Down
Loading

0 comments on commit c40b816

Please sign in to comment.