From f403654103048d8fa20e7f7b388556c83107995e Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 29 May 2020 18:22:18 +1100 Subject: [PATCH 1/4] Formatted CRUD provider typedefs --- packages/keystone/lib/providers/listCRUD.js | 349 +++++++++++--------- 1 file changed, 194 insertions(+), 155 deletions(-) diff --git a/packages/keystone/lib/providers/listCRUD.js b/packages/keystone/lib/providers/listCRUD.js index b9ddba81030..36366d2974e 100644 --- a/packages/keystone/lib/providers/listCRUD.js +++ b/packages/keystone/lib/providers/listCRUD.js @@ -13,161 +13,200 @@ class ListCRUDProvider { getTypes({ schemaName }) { return unique([ ...flatten(this.lists.map(list => list.getGqlTypes({ schemaName }))), - `"""NOTE: Can be JSON, or a Boolean/Int/String - Why not a union? GraphQL doesn't support a union including a scalar - (https://github.com/facebook/graphql/issues/215)""" - scalar JSON`, - `type _ListAccess { - """Access Control settings for the currently logged in (or anonymous) - user when performing 'create' operations. - NOTE: 'create' can only return a Boolean. - It is not possible to specify a declarative Where clause for this - operation""" - create: Boolean - - """Access Control settings for the currently logged in (or anonymous) - user when performing 'read' operations.""" - read: JSON - - """Access Control settings for the currently logged in (or anonymous) - user when performing 'update' operations.""" - update: JSON - - """Access Control settings for the currently logged in (or anonymous) - user when performing 'delete' operations.""" - delete: JSON - - """Access Control settings for the currently logged in (or anonymous) - user when performing 'auth' operations.""" - auth: JSON - }`, - `type _ListQueries { - """Single-item query name.""" - item: String - - """All-items query name.""" - list: String - - """List metadata query name.""" - meta: String - }`, - `type _ListMutations { - """Create mutation name.""" - create: String - - """Create many mutation name.""" - createMany: String - - """Update mutation name.""" - update: String - - """Update many mutation name.""" - updateMany: String - - """Delete mutation name.""" - delete: String - - """Delete many mutation name.""" - deleteMany: String - }`, - `type _ListInputTypes { - """Input type for matching multiple items.""" - whereInput: String - - """Input type for matching a unique item.""" - whereUniqueInput: String - - """Create mutation input type name.""" - createInput: String - - """Create many mutation input type name.""" - createManyInput: String - - """Update mutation name input.""" - updateInput: String - - """Update many mutation name input.""" - updateManyInput: String - }`, - `type _ListSchemaFields { - """ The path of the field in its list. """ - path: String - - """The name of the field in its list.""" - name: String @deprecated(reason: "Use \`path\` instead") - - """The field type (ie, Checkbox, Text, etc)""" - type: String - }`, - `type _ListSchemaRelatedFields { - """The typename as used in GraphQL queries""" - type: String - - """A list of GraphQL field names""" - fields: [String] - }`, - `type _ListSchema { - """The typename as used in GraphQL queries""" - type: String - - """Top level GraphQL query names which either return this type, or - provide aggregate information about this type""" - queries: _ListQueries - - """Top-level GraphQL mutation names""" - mutations: _ListMutations - - """Top-level GraphQL input types""" - inputTypes: _ListInputTypes - - """Information about fields defined on this list. """ - fields(where: _ListSchemaFieldsInput): [_ListSchemaFields] - - """Information about fields on other types which return this type, or - provide aggregate information about this type""" - relatedFields: [_ListSchemaRelatedFields] - }`, - `type _ListMeta { - """ The Keystone list key """ - key: String - - """The Keystone List name""" - name: String @deprecated(reason: "Use \`key\` instead") - - """The list's user-facing description""" - description: String - - """The list's display name in the Admin UI""" - label: String - - """The list's singular display name""" - singular: String - - """The list's plural display name""" - plural: String - - """The list's data path""" - path: String - - """Access control configuration for the currently authenticated - request""" - access: _ListAccess - - """Information on the generated GraphQL schema""" - schema: _ListSchema - }`, - `type _QueryMeta { - count: Int - }`, - `input ${this.gqlNames.listsMetaInput} { - key: String - - """Whether this is an auxiliary helper list.""" - auxiliary: Boolean - }`, - `input _ListSchemaFieldsInput { - type: String - }`, + ` + """ + NOTE: Can be JSON, or a Boolean/Int/String + Why not a union? GraphQL doesn't support a union including a scalar + (https://github.com/facebook/graphql/issues/215) + """ + scalar JSON + `, + ` + type _ListAccess { + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'create' operations. + NOTE: 'create' can only return a Boolean. + It is not possible to specify a declarative Where clause for this + operation + """ + create: Boolean + + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'read' operations. + """ + read: JSON + + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'update' operations. + """ + update: JSON + + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'delete' operations. + """ + delete: JSON + + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'auth' operations. + """ + auth: JSON + } + `, + ` + type _ListQueries { + "Single-item query name" + item: String + + "All-items query name" + list: String + + "List metadata query name" + meta: String + } + `, + ` + type _ListMutations { + "Create mutation name" + create: String + + "Create many mutation name" + createMany: String + + "Update mutation name" + update: String + + "Update many mutation name" + updateMany: String + + "Delete mutation name" + delete: String + + "Delete many mutation name" + deleteMany: String + } + `, + ` + type _ListInputTypes { + "Input type for matching multiple items" + whereInput: String + + "Input type for matching a unique item" + whereUniqueInput: String + + "Create mutation input type name" + createInput: String + + "Create many mutation input type name" + createManyInput: String + + "Update mutation name input" + updateInput: String + + "Update many mutation name input" + updateManyInput: String + } + `, + ` + type _ListSchemaFields { + "The path of the field in its list" + path: String + + "The name of the field in its list" + name: String @deprecated(reason: "Use \`path\` instead") + + "The field type (ie, Checkbox, Text, etc)" + type: String + } + `, + ` + type _ListSchemaRelatedFields { + "The typename as used in GraphQL queries" + type: String + + "A list of GraphQL field names" + fields: [String] + } + `, + ` + type _ListSchema { + "The typename as used in GraphQL queries" + type: String + + """ + Top level GraphQL query names which either return this type, or + provide aggregate information about this type + """ + queries: _ListQueries + + "Top-level GraphQL mutation names" + mutations: _ListMutations + + "Top-level GraphQL input types" + inputTypes: _ListInputTypes + + "Information about fields defined on this list" + fields(where: _ListSchemaFieldsInput): [_ListSchemaFields] + + """ + Information about fields on other types which return this type, or + provide aggregate information about this type + """ + relatedFields: [_ListSchemaRelatedFields] + } + `, + ` + type _ListMeta { + "The Keystone list key" + key: String + + "The Keystone List name" + name: String @deprecated(reason: "Use \`key\` instead") + + "The list's user-facing description" + description: String + + "The list's display name in the Admin UI" + label: String + + "The list's singular display name" + singular: String + + "The list's plural display name" + plural: String + + "The list's data path" + path: String + + "Access control configuration for the currently authenticated request" + access: _ListAccess + + "Information on the generated GraphQL schema" + schema: _ListSchema + } + `, + ` + type _QueryMeta { + count: Int + } + `, + ` + input ${this.gqlNames.listsMetaInput} { + key: String + + "Whether this is an auxiliary helper list" + auxiliary: Boolean + } + `, + ` + input _ListSchemaFieldsInput { + type: String + } + `, ]); } getQueries({ schemaName }) { From fda2279a6395a7dd5a0ddba034424004b29db8f7 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 29 May 2020 18:39:03 +1100 Subject: [PATCH 2/4] Moved CRUD types to their own file --- packages/keystone/lib/providers/listCRUD.js | 203 +----------------- .../keystone/lib/providers/listCRUDTypes.js | 202 +++++++++++++++++ 2 files changed, 211 insertions(+), 194 deletions(-) create mode 100644 packages/keystone/lib/providers/listCRUDTypes.js diff --git a/packages/keystone/lib/providers/listCRUD.js b/packages/keystone/lib/providers/listCRUD.js index 36366d2974e..df375db13a5 100644 --- a/packages/keystone/lib/providers/listCRUD.js +++ b/packages/keystone/lib/providers/listCRUD.js @@ -1,6 +1,8 @@ const { GraphQLJSON } = require('graphql-type-json'); const { flatten, objMerge, unique } = require('@keystonejs/utils'); +const { _getListCRUDTypes } = require('./listCRUDTypes'); + class ListCRUDProvider { constructor({ metaPrefix = 'ks' } = {}) { this.lists = []; @@ -13,202 +15,10 @@ class ListCRUDProvider { getTypes({ schemaName }) { return unique([ ...flatten(this.lists.map(list => list.getGqlTypes({ schemaName }))), - ` - """ - NOTE: Can be JSON, or a Boolean/Int/String - Why not a union? GraphQL doesn't support a union including a scalar - (https://github.com/facebook/graphql/issues/215) - """ - scalar JSON - `, - ` - type _ListAccess { - """ - Access Control settings for the currently logged in (or anonymous) - user when performing 'create' operations. - NOTE: 'create' can only return a Boolean. - It is not possible to specify a declarative Where clause for this - operation - """ - create: Boolean - - """ - Access Control settings for the currently logged in (or anonymous) - user when performing 'read' operations. - """ - read: JSON - - """ - Access Control settings for the currently logged in (or anonymous) - user when performing 'update' operations. - """ - update: JSON - - """ - Access Control settings for the currently logged in (or anonymous) - user when performing 'delete' operations. - """ - delete: JSON - - """ - Access Control settings for the currently logged in (or anonymous) - user when performing 'auth' operations. - """ - auth: JSON - } - `, - ` - type _ListQueries { - "Single-item query name" - item: String - - "All-items query name" - list: String - - "List metadata query name" - meta: String - } - `, - ` - type _ListMutations { - "Create mutation name" - create: String - - "Create many mutation name" - createMany: String - - "Update mutation name" - update: String - - "Update many mutation name" - updateMany: String - - "Delete mutation name" - delete: String - - "Delete many mutation name" - deleteMany: String - } - `, - ` - type _ListInputTypes { - "Input type for matching multiple items" - whereInput: String - - "Input type for matching a unique item" - whereUniqueInput: String - - "Create mutation input type name" - createInput: String - - "Create many mutation input type name" - createManyInput: String - - "Update mutation name input" - updateInput: String - - "Update many mutation name input" - updateManyInput: String - } - `, - ` - type _ListSchemaFields { - "The path of the field in its list" - path: String - - "The name of the field in its list" - name: String @deprecated(reason: "Use \`path\` instead") - - "The field type (ie, Checkbox, Text, etc)" - type: String - } - `, - ` - type _ListSchemaRelatedFields { - "The typename as used in GraphQL queries" - type: String - - "A list of GraphQL field names" - fields: [String] - } - `, - ` - type _ListSchema { - "The typename as used in GraphQL queries" - type: String - - """ - Top level GraphQL query names which either return this type, or - provide aggregate information about this type - """ - queries: _ListQueries - - "Top-level GraphQL mutation names" - mutations: _ListMutations - - "Top-level GraphQL input types" - inputTypes: _ListInputTypes - - "Information about fields defined on this list" - fields(where: _ListSchemaFieldsInput): [_ListSchemaFields] - - """ - Information about fields on other types which return this type, or - provide aggregate information about this type - """ - relatedFields: [_ListSchemaRelatedFields] - } - `, - ` - type _ListMeta { - "The Keystone list key" - key: String - - "The Keystone List name" - name: String @deprecated(reason: "Use \`key\` instead") - - "The list's user-facing description" - description: String - - "The list's display name in the Admin UI" - label: String - - "The list's singular display name" - singular: String - - "The list's plural display name" - plural: String - - "The list's data path" - path: String - - "Access control configuration for the currently authenticated request" - access: _ListAccess - - "Information on the generated GraphQL schema" - schema: _ListSchema - } - `, - ` - type _QueryMeta { - count: Int - } - `, - ` - input ${this.gqlNames.listsMetaInput} { - key: String - - "Whether this is an auxiliary helper list" - auxiliary: Boolean - } - `, - ` - input _ListSchemaFieldsInput { - type: String - } - `, + ..._getListCRUDTypes(this.gqlNames) ]); } + getQueries({ schemaName }) { // Aux lists are only there for typing and internal operations, they should // not have any GraphQL operations performed on them @@ -219,10 +29,12 @@ class ListCRUDProvider { ${this.gqlNames.listsMeta}(where: ${this.gqlNames.listsMetaInput}): [_ListMeta]`, ]; } + getMutations({ schemaName }) { const firstClassLists = this.lists.filter(list => !list.isAuxList); return flatten(firstClassLists.map(list => list.getGqlMutations({ schemaName }))); } + getSubscriptions({}) { return []; } @@ -296,6 +108,7 @@ class ListCRUDProvider { _ListSchema: listSchemaResolver, }; } + getQueryResolvers({ schemaName }) { const firstClassLists = this.lists.filter(list => !list.isAuxList); return { @@ -316,6 +129,7 @@ class ListCRUDProvider { .map(list => list.listMeta(context)), }; } + getMutationResolvers({ schemaName }) { const firstClassLists = this.lists.filter(list => !list.isAuxList); return { @@ -323,6 +137,7 @@ class ListCRUDProvider { ...objMerge(firstClassLists.map(list => list.gqlMutationResolvers({ schemaName }))), }; } + getSubscriptionResolvers({}) { return {}; } diff --git a/packages/keystone/lib/providers/listCRUDTypes.js b/packages/keystone/lib/providers/listCRUDTypes.js new file mode 100644 index 00000000000..e1df7e5cfc4 --- /dev/null +++ b/packages/keystone/lib/providers/listCRUDTypes.js @@ -0,0 +1,202 @@ +/** + * Helper function to get the static GraphQL Type definitions for the CRUD provider. + * @param {Object} gqlNames CRUD provider GraphQL type names + */ +const _getListCRUDTypes = ({ listsMetaInput }) => [ + ` + """ + NOTE: Can be JSON, or a Boolean/Int/String + Why not a union? GraphQL doesn't support a union including a scalar + (https://github.com/facebook/graphql/issues/215) + """ + scalar JSON + `, + ` + type _ListAccess { + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'create' operations. + NOTE: 'create' can only return a Boolean. + It is not possible to specify a declarative Where clause for this + operation + """ + create: Boolean + + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'read' operations. + """ + read: JSON + + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'update' operations. + """ + update: JSON + + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'delete' operations. + """ + delete: JSON + + """ + Access Control settings for the currently logged in (or anonymous) + user when performing 'auth' operations. + """ + auth: JSON + } + `, + ` + type _ListQueries { + "Single-item query name" + item: String + + "All-items query name" + list: String + + "List metadata query name" + meta: String + } + `, + ` + type _ListMutations { + "Create mutation name" + create: String + + "Create many mutation name" + createMany: String + + "Update mutation name" + update: String + + "Update many mutation name" + updateMany: String + + "Delete mutation name" + delete: String + + "Delete many mutation name" + deleteMany: String + } + `, + ` + type _ListInputTypes { + "Input type for matching multiple items" + whereInput: String + + "Input type for matching a unique item" + whereUniqueInput: String + + "Create mutation input type name" + createInput: String + + "Create many mutation input type name" + createManyInput: String + + "Update mutation name input" + updateInput: String + + "Update many mutation name input" + updateManyInput: String + } + `, + ` + type _ListSchemaFields { + "The path of the field in its list" + path: String + + "The name of the field in its list" + name: String @deprecated(reason: "Use \`path\` instead") + + "The field type (ie, Checkbox, Text, etc)" + type: String + } + `, + ` + type _ListSchemaRelatedFields { + "The typename as used in GraphQL queries" + type: String + + "A list of GraphQL field names" + fields: [String] + } + `, + ` + type _ListSchema { + "The typename as used in GraphQL queries" + type: String + + """ + Top level GraphQL query names which either return this type, or + provide aggregate information about this type + """ + queries: _ListQueries + + "Top-level GraphQL mutation names" + mutations: _ListMutations + + "Top-level GraphQL input types" + inputTypes: _ListInputTypes + + "Information about fields defined on this list" + fields(where: _ListSchemaFieldsInput): [_ListSchemaFields] + + """ + Information about fields on other types which return this type, or + provide aggregate information about this type + """ + relatedFields: [_ListSchemaRelatedFields] + } + `, + ` + type _ListMeta { + "The Keystone list key" + key: String + + "The Keystone List name" + name: String @deprecated(reason: "Use \`key\` instead") + + "The list's user-facing description" + description: String + + "The list's display name in the Admin UI" + label: String + + "The list's singular display name" + singular: String + + "The list's plural display name" + plural: String + + "The list's data path" + path: String + + "Access control configuration for the currently authenticated request" + access: _ListAccess + + "Information on the generated GraphQL schema" + schema: _ListSchema + } + `, + ` + type _QueryMeta { + count: Int + } + `, + ` + input ${listsMetaInput} { + key: String + + "Whether this is an auxiliary helper list" + auxiliary: Boolean + } + `, + ` + input _ListSchemaFieldsInput { + type: String + } + `, +]; + +module.exports = { _getListCRUDTypes }; From 1dba466edaf2d6d37189b9aabe258a840b7d4978 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 29 May 2020 18:43:19 +1100 Subject: [PATCH 3/4] Formatting --- packages/keystone/lib/providers/listCRUD.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/keystone/lib/providers/listCRUD.js b/packages/keystone/lib/providers/listCRUD.js index df375db13a5..3a5f17406d7 100644 --- a/packages/keystone/lib/providers/listCRUD.js +++ b/packages/keystone/lib/providers/listCRUD.js @@ -15,7 +15,7 @@ class ListCRUDProvider { getTypes({ schemaName }) { return unique([ ...flatten(this.lists.map(list => list.getGqlTypes({ schemaName }))), - ..._getListCRUDTypes(this.gqlNames) + ..._getListCRUDTypes(this.gqlNames), ]); } From 2e64001aa572b59f8846ca4d4dcceef7fcc3030a Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sat, 30 May 2020 00:01:24 +1100 Subject: [PATCH 4/4] Removed underscore --- packages/keystone/lib/providers/listCRUD.js | 4 ++-- packages/keystone/lib/providers/listCRUDTypes.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/keystone/lib/providers/listCRUD.js b/packages/keystone/lib/providers/listCRUD.js index 3a5f17406d7..3b2cc0d1f64 100644 --- a/packages/keystone/lib/providers/listCRUD.js +++ b/packages/keystone/lib/providers/listCRUD.js @@ -1,7 +1,7 @@ const { GraphQLJSON } = require('graphql-type-json'); const { flatten, objMerge, unique } = require('@keystonejs/utils'); -const { _getListCRUDTypes } = require('./listCRUDTypes'); +const { getListCRUDTypes } = require('./listCRUDTypes'); class ListCRUDProvider { constructor({ metaPrefix = 'ks' } = {}) { @@ -15,7 +15,7 @@ class ListCRUDProvider { getTypes({ schemaName }) { return unique([ ...flatten(this.lists.map(list => list.getGqlTypes({ schemaName }))), - ..._getListCRUDTypes(this.gqlNames), + ...getListCRUDTypes(this.gqlNames), ]); } diff --git a/packages/keystone/lib/providers/listCRUDTypes.js b/packages/keystone/lib/providers/listCRUDTypes.js index e1df7e5cfc4..978ad0c2b89 100644 --- a/packages/keystone/lib/providers/listCRUDTypes.js +++ b/packages/keystone/lib/providers/listCRUDTypes.js @@ -2,7 +2,7 @@ * Helper function to get the static GraphQL Type definitions for the CRUD provider. * @param {Object} gqlNames CRUD provider GraphQL type names */ -const _getListCRUDTypes = ({ listsMetaInput }) => [ +const getListCRUDTypes = ({ listsMetaInput }) => [ ` """ NOTE: Can be JSON, or a Boolean/Int/String @@ -199,4 +199,4 @@ const _getListCRUDTypes = ({ listsMetaInput }) => [ `, ]; -module.exports = { _getListCRUDTypes }; +module.exports = { getListCRUDTypes };