Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce code complexity #8301

Merged
merged 4 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
30 changes: 16 additions & 14 deletions packages/core/src/lib/context/itemAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import {
import { executeGraphQLFieldToRootVal } from './executeGraphQLFieldToRootVal';
import { executeGraphQLFieldWithSelection } from './executeGraphQLFieldWithSelection';

// this is generally incorrect because types are open in TS but is correct in the specific usage here.
// (i mean it's not really any more incorrect than TS is generally is but let's ignore that)
const objectEntriesButUsingKeyof: <T extends Record<string, any>>(
obj: T
) => [keyof T, T[keyof T]][] = Object.entries as any;

export function getDbAPIFactory(
gqlNames: GqlNames,
schema: GraphQLSchema
Expand All @@ -32,7 +26,8 @@ export function getDbAPIFactory(
}
return executeGraphQLFieldToRootVal(field);
};
const api = {

const fcache = {
findOne: f('query', gqlNames.itemQueryName),
findMany: f('query', gqlNames.listQueryName),
count: f('query', gqlNames.listQueryCountName),
Expand All @@ -43,13 +38,20 @@ export function getDbAPIFactory(
deleteOne: f('mutation', gqlNames.deleteMutationName),
deleteMany: f('mutation', gqlNames.deleteManyMutationName),
};
return (context: KeystoneContext) =>
Object.fromEntries(
objectEntriesButUsingKeyof(api).map(([key, impl]) => [
key,
(args: Record<string, any>) => impl(args, context),
])
) as Record<keyof typeof api, any>;

return (context: KeystoneContext) => {
return {
findOne: (args: Record<string, any>) => fcache.findOne(args, context),
findMany: (args: Record<string, any>) => fcache.findMany(args, context),
count: (args: Record<string, any>) => fcache.count(args, context),
createOne: (args: Record<string, any>) => fcache.createOne(args, context),
createMany: (args: Record<string, any>) => fcache.createMany(args, context),
updateOne: (args: Record<string, any>) => fcache.updateOne(args, context),
updateMany: (args: Record<string, any>) => fcache.updateMany(args, context),
deleteOne: (args: Record<string, any>) => fcache.deleteOne(args, context),
deleteMany: (args: Record<string, any>) => fcache.deleteMany(args, context),
};
};
}

export function itemAPIForList(
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/types/config/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export type CommonFieldConfig<ListTypeInfo extends BaseListTypeInfo> = {
update?: boolean;
};
};
// Disabled by default...
isFilterable?: boolean | ((args: FilterOrderArgs<ListTypeInfo>) => MaybePromise<boolean>);
isOrderable?: boolean | ((args: FilterOrderArgs<ListTypeInfo>) => MaybePromise<boolean>);
};
2 changes: 1 addition & 1 deletion scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function fetchData(tag) {
const changes = {};
for (const commit of revs) {
let { user, pull } = await getInfo({ repo: 'keystonejs/keystone', commit });
pull = pull || gitCommitDescription(commit).match(/#([0-9]+)/)[1];
pull = pull || gitCommitDescription(commit).match(/#([0-9]+)/)?.[1]
Copy link
Member Author

@dcousens dcousens Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but this is a minor fix for the upcoming release notes


console.error(`commit ${commit}, user ${user}, pull #${pull}`);
const change = { commit, user, pull };
Expand Down