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

Remove legacy keystone.createContext #5250

Merged
merged 2 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/cold-lamps-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone-legacy': major
---

Removed legacy method `keystone.createContext()`.
117 changes: 0 additions & 117 deletions packages/keystone/lib/Keystone/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
const { gql } = require('apollo-server-express');
const memoize = require('micro-memoize');
const { GraphQLUpload } = require('graphql-upload');
const { objMerge, flatten, unique, filterValues } = require('@keystone-next/utils-legacy');
const {
validateFieldAccessControl,
validateListAccessControl,
validateAuthAccessControl,
} = require('@keystone-next/access-control-legacy');

const { List } = require('../ListTypes');
const { ListCRUDProvider } = require('../providers');
Expand Down Expand Up @@ -41,117 +35,6 @@ module.exports = class Keystone {
}
}

_getAccessControlContext({ schemaName, authentication, skipAccessControl }) {
if (skipAccessControl) {
return {
getListAccessControlForUser: () => true,
getFieldAccessControlForUser: () => true,
getAuthAccessControlForUser: () => true,
};
}
// memoizing to avoid requests that hit the same type multiple times.
// We do it within the request callback so we can resolve it based on the
// request info (like who's logged in right now, etc)
const getListAccessControlForUser = memoize(
async (
access,
listKey,
originalInput,
operation,
{ gqlName, itemId, itemIds, context } = {}
) => {
return validateListAccessControl({
access: access[schemaName],
args: {
originalInput,
operation,
authentication: authentication && authentication.item ? authentication : {},
listKey,
gqlName,
itemId,
itemIds,
context,
},
});
},
{ isPromise: true }
);

const getFieldAccessControlForUser = memoize(
async (
access,
listKey,
fieldKey,
originalInput,
existingItem,
operation,
{ gqlName, itemId, itemIds, context } = {}
) => {
return validateFieldAccessControl({
access: access[schemaName],
args: {
originalInput,
existingItem,
operation,
authentication: authentication && authentication.item ? authentication : {},
fieldKey,
listKey,
gqlName,
itemId,
itemIds,
context,
},
});
},
{ isPromise: true }
);

const getAuthAccessControlForUser = memoize(
async (access, listKey, { gqlName, context } = {}) => {
return validateAuthAccessControl({
access: access[schemaName],
args: {
authentication: authentication && authentication.item ? authentication : {},
listKey,
gqlName,
context,
operation: 'auth',
},
});
},
{ isPromise: true }
);

return {
getListAccessControlForUser,
getFieldAccessControlForUser,
getAuthAccessControlForUser,
};
}

createContext({ schemaName = 'public', authentication = {}, skipAccessControl = false } = {}) {
const context = {
schemaName,
authedItem: authentication.item,
authedListKey: authentication.listKey,
...this._getAccessControlContext({ schemaName, authentication, skipAccessControl }),
totalResults: 0,
maxTotalResults: this.queryLimits.maxTotalResults,
};
// Locally bind the values we use as defaults into an object to make
// JS behave the way we want.
const defaults = { schemaName, authentication, skipAccessControl, context };
context.createContext = ({
schemaName = defaults.schemaName,
authentication = defaults.authentication,
skipAccessControl = defaults.skipAccessControl,
} = {}) => this.createContext({ schemaName, authentication, skipAccessControl });
context.sudo = () =>
this.createContext({ schemaName, authentication, skipAccessControl: true });
context.gqlNames = listKey => this.lists[listKey].gqlNames;
return context;
}

createList(key, config, { isAuxList = false } = {}) {
const { getListByKey, adapter } = this;
const isReservedName = !isAuxList && key[0] === '_';
Expand Down
1 change: 0 additions & 1 deletion packages/keystone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"falsey": "^1.0.0",
"graphql-type-json": "^0.3.2",
"graphql-upload": "^11.0.0",
"micro-memoize": "^4.0.9",
"p-waterfall": "^2.1.1",
"pino": "^6.11.2",
"pluralize": "^8.0.0",
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9625,11 +9625,6 @@ methods@^1.1.2, methods@~1.1.2:
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=

micro-memoize@^4.0.9:
version "4.0.9"
resolved "https://registry.yarnpkg.com/micro-memoize/-/micro-memoize-4.0.9.tgz#b44a38c9dffbee1cefc2fd139bc8947952268b62"
integrity sha512-Z2uZi/IUMGQDCXASdujXRqrXXEwSY0XffUrAOllhqzQI3wpUyZbiZTiE2JuYC0HSG2G7DbCS5jZmsEKEGZuemg==

micro@^9.3.2:
version "9.3.4"
resolved "https://registry.yarnpkg.com/micro/-/micro-9.3.4.tgz#745a494e53c8916f64fb6a729f8cbf2a506b35ad"
Expand Down