Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
gqlAuxMutationResolvers() {
// TODO: Obey the same ACL rules based on parent type
return objMerge(this.fields.map(field => field.gqlAuxMutationResolvers()));
}
...objMerge(this.listsArray.map(list => list.gqlAuxFieldResolvers({ schemaName }))),
...objMerge(this.listsArray.map(list => list.gqlFieldResolvers({ schemaName }))),
JSON: GraphQLJSON,
_QueryMeta: queryMetaResolver,
_ListMeta: listMetaResolver,
_ListAccess: listAccessResolver,
_ListSchema: listSchemaResolver,
Query: {
// Order is also important here, any TypeQuery's defined by types
// shouldn't be able to override list-level queries
...objMerge(firstClassLists.map(list => list.gqlAuxQueryResolvers())),
...objMerge(firstClassLists.map(list => list.gqlQueryResolvers({ schemaName }))),
...objMerge(
this.appVersion.access[schemaName]
? [{ appVersion: () => this.appVersion.version }]
: []
),
// And the Keystone meta queries must always be available
_ksListsMeta: (_, args, context) =>
this.listsArray
.filter(list => list.access[schemaName].read)
.map(list => list.listMeta(context)),
...objMerge(
this._extendedQueries
.filter(({ access }) => access[schemaName])
.map(customResolver('query'))
),
},
// TODO: Change to a native JSON type
document: {
type: Text,
schemaDoc: 'The serialized Slate.js Document structure',
},
// Used to do reverse lookups of Document -> Original Item
from: {
type: Relationship,
ref: `${listConfig.listKey}.${path}`,
schemaDoc: 'A reference back to the item this document belongs to',
},
// Gather up all the fields which blocks want to specify
// (note: They may be Relationships to Aux Lists themselves!)
...objMerge(blockInstances.map(block => block.getFieldDefinitions())),
},
hooks: {
async resolveInput({ resolvedData, ...args }) {
// This method will get called twice;
// 1. The incoming graphql request data
// 2. Registering the back link in the `from` field
// We only want to handle the first case, so we bail early otherwise
if (!resolvedData.document) {
return resolvedData;
}
// TODO: Remove JSON.parse once using native JSON type
const documentObj = JSON.parse(resolvedData.document);
const { document } = await processSerialised(documentObj, blockInstances, args);
return {
...resolvedData,
const simpleTokenizer = (listAdapter, query, queryKey, path) => {
// NOTE: We slice the last path segment off because we're interested in the
// related list, not the field on the related list. ie, if the path is
// ['posts', 'comments', 'author', 'name'],
// the field is 'name', and the related list is the one at
// ['posts', 'comments', 'author']
const refListAdapter = getRelatedListAdapterFromQueryPath(listAdapter, path.slice(0, -1));
const simpleQueryConditions = {
...objMerge(
refListAdapter.fieldAdapters.map(fieldAdapter =>
fieldAdapter.getQueryConditions(fieldAdapter.dbPath)
)
),
};
if (queryKey in simpleQueryConditions) {
return { matchTerm: simpleQueryConditions[queryKey](query[queryKey], query) };
}
if (queryKey in modifierConditions) {
return {
postJoinPipeline: [modifierConditions[queryKey](query[queryKey], query, refListAdapter)],
};
}
// Nothing found, return an empty operation
gqlFieldResolvers({ schemaName }) {
const schemaAccess = this.access[schemaName];
if (!schemaAccess.read) {
return {};
}
const fieldResolvers = {
// TODO: The `_label_` output field currently circumvents access control
_label_: this.labelResolver,
...objMerge(
this.fields
.filter(field => field.access[schemaName].read)
.map(field =>
// Get the resolvers for the (possibly multiple) output fields and wrap each with list-specific modifiers
mapKeys(field.gqlOutputFieldResolvers({ schemaName }), innerResolver =>
this._wrapFieldResolver(field, innerResolver)
)
)
),
};
return { [this.gqlNames.outputTypeName]: fieldResolvers };
}
gqlAuxQueryResolvers() {
// TODO: Obey the same ACL rules based on parent type
return objMerge(this.fields.map(field => field.gqlAuxQueryResolvers()));
}
// Order of spreading is important here - we don't want user-defined types
// to accidentally override important things like `Query`.
...objMerge(this.listsArray.map(list => list.gqlAuxFieldResolvers({ schemaName }))),
...objMerge(this.listsArray.map(list => list.gqlFieldResolvers({ schemaName }))),
JSON: GraphQLJSON,
_QueryMeta: queryMetaResolver,
_ListMeta: listMetaResolver,
_ListAccess: listAccessResolver,
_ListSchema: listSchemaResolver,
Query: {
// Order is also important here, any TypeQuery's defined by types
// shouldn't be able to override list-level queries
...objMerge(firstClassLists.map(list => list.gqlAuxQueryResolvers())),
...objMerge(firstClassLists.map(list => list.gqlQueryResolvers({ schemaName }))),
...objMerge(
this.appVersion.access[schemaName]
? [{ appVersion: () => this.appVersion.version }]
: []
),
// And the Keystone meta queries must always be available
_ksListsMeta: (_, args, context) =>
this.listsArray
.filter(list => list.access[schemaName].read)
.map(list => list.listMeta(context)),
...objMerge(
this._extendedQueries
.filter(({ access }) => access[schemaName])
.map(customResolver('query'))
),
gqlAuxFieldResolvers({ schemaName }) {
const schemaAccess = this.access[schemaName];
if (
schemaAccess.read ||
schemaAccess.create ||
schemaAccess.update ||
schemaAccess.delete ||
schemaAccess.auth
) {
return objMerge(this.fields.map(field => field.gqlAuxFieldResolvers({ schemaName })));
}
return {};
}