@payloadcms/graphql 3.0.0-beta.10 → 3.0.0-beta.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +54 -0
- package/dist/bin/generateSchema.d.ts +3 -0
- package/dist/bin/generateSchema.d.ts.map +1 -0
- package/dist/bin/generateSchema.js +10 -0
- package/dist/bin/generateSchema.js.map +1 -0
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.d.ts.map +1 -0
- package/dist/bin/index.js +17 -0
- package/dist/bin/index.js.map +1 -0
- package/dist/exports/types.d.ts +4 -0
- package/dist/exports/types.d.ts.map +1 -0
- package/dist/exports/types.js +5 -0
- package/dist/exports/types.js.map +1 -0
- package/dist/exports/utilities.d.ts +3 -0
- package/dist/exports/utilities.d.ts.map +1 -0
- package/dist/exports/utilities.js +4 -0
- package/dist/exports/utilities.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/packages/graphql-query-complexity/QueryComplexity.d.ts +51 -0
- package/dist/packages/graphql-query-complexity/QueryComplexity.d.ts.map +1 -0
- package/dist/packages/graphql-query-complexity/QueryComplexity.js +270 -0
- package/dist/packages/graphql-query-complexity/QueryComplexity.js.map +1 -0
- package/dist/packages/graphql-query-complexity/createComplexityRule.d.ts +5 -0
- package/dist/packages/graphql-query-complexity/createComplexityRule.d.ts.map +1 -0
- package/dist/packages/graphql-query-complexity/createComplexityRule.js +8 -0
- package/dist/packages/graphql-query-complexity/createComplexityRule.js.map +1 -0
- package/dist/packages/graphql-query-complexity/estimators/fieldExtensions/index.d.ts +3 -0
- package/dist/packages/graphql-query-complexity/estimators/fieldExtensions/index.d.ts.map +1 -0
- package/dist/packages/graphql-query-complexity/estimators/fieldExtensions/index.js +14 -0
- package/dist/packages/graphql-query-complexity/estimators/fieldExtensions/index.js.map +1 -0
- package/dist/packages/graphql-query-complexity/estimators/simple/index.d.ts +5 -0
- package/dist/packages/graphql-query-complexity/estimators/simple/index.d.ts.map +1 -0
- package/dist/packages/graphql-query-complexity/estimators/simple/index.js +8 -0
- package/dist/packages/graphql-query-complexity/estimators/simple/index.js.map +1 -0
- package/dist/packages/graphql-query-complexity/index.d.ts +4 -0
- package/dist/packages/graphql-query-complexity/index.d.ts.map +1 -0
- package/dist/packages/graphql-query-complexity/index.js +5 -0
- package/dist/packages/graphql-query-complexity/index.js.map +1 -0
- package/dist/packages/graphql-type-json/index.d.ts +4 -0
- package/dist/packages/graphql-type-json/index.d.ts.map +1 -0
- package/dist/packages/graphql-type-json/index.js +63 -0
- package/dist/packages/graphql-type-json/index.js.map +1 -0
- package/dist/resolvers/auth/access.d.ts +2 -3
- package/dist/resolvers/auth/access.d.ts.map +1 -1
- package/dist/resolvers/auth/access.js +3 -5
- package/dist/resolvers/auth/access.js.map +1 -1
- package/dist/resolvers/auth/forgotPassword.d.ts +2 -3
- package/dist/resolvers/auth/forgotPassword.d.ts.map +1 -1
- package/dist/resolvers/auth/forgotPassword.js +4 -5
- package/dist/resolvers/auth/forgotPassword.js.map +1 -1
- package/dist/resolvers/auth/init.d.ts +1 -2
- package/dist/resolvers/auth/init.d.ts.map +1 -1
- package/dist/resolvers/auth/init.js +2 -4
- package/dist/resolvers/auth/init.js.map +1 -1
- package/dist/resolvers/auth/login.d.ts +2 -3
- package/dist/resolvers/auth/login.d.ts.map +1 -1
- package/dist/resolvers/auth/login.js +4 -6
- package/dist/resolvers/auth/login.js.map +1 -1
- package/dist/resolvers/auth/logout.d.ts +2 -3
- package/dist/resolvers/auth/logout.d.ts.map +1 -1
- package/dist/resolvers/auth/logout.js +2 -5
- package/dist/resolvers/auth/logout.js.map +1 -1
- package/dist/resolvers/auth/me.d.ts +2 -3
- package/dist/resolvers/auth/me.d.ts.map +1 -1
- package/dist/resolvers/auth/me.js +4 -4
- package/dist/resolvers/auth/me.js.map +1 -1
- package/dist/resolvers/auth/refresh.d.ts +2 -3
- package/dist/resolvers/auth/refresh.d.ts.map +1 -1
- package/dist/resolvers/auth/refresh.js +4 -13
- package/dist/resolvers/auth/refresh.js.map +1 -1
- package/dist/resolvers/auth/resetPassword.d.ts +2 -3
- package/dist/resolvers/auth/resetPassword.d.ts.map +1 -1
- package/dist/resolvers/auth/resetPassword.js +8 -7
- package/dist/resolvers/auth/resetPassword.js.map +1 -1
- package/dist/resolvers/auth/unlock.d.ts +2 -3
- package/dist/resolvers/auth/unlock.d.ts.map +1 -1
- package/dist/resolvers/auth/unlock.js +4 -5
- package/dist/resolvers/auth/unlock.js.map +1 -1
- package/dist/resolvers/auth/verifyEmail.d.ts +2 -3
- package/dist/resolvers/auth/verifyEmail.d.ts.map +1 -1
- package/dist/resolvers/auth/verifyEmail.js +8 -6
- package/dist/resolvers/auth/verifyEmail.js.map +1 -1
- package/dist/resolvers/collections/count.d.ts +12 -0
- package/dist/resolvers/collections/count.d.ts.map +1 -0
- package/dist/resolvers/collections/count.js +22 -0
- package/dist/resolvers/collections/count.js.map +1 -0
- package/dist/resolvers/collections/create.d.ts +5 -8
- package/dist/resolvers/collections/create.d.ts.map +1 -1
- package/dist/resolvers/collections/create.js +2 -3
- package/dist/resolvers/collections/create.js.map +1 -1
- package/dist/resolvers/collections/delete.d.ts +6 -6
- package/dist/resolvers/collections/delete.d.ts.map +1 -1
- package/dist/resolvers/collections/delete.js +12 -6
- package/dist/resolvers/collections/delete.js.map +1 -1
- package/dist/resolvers/collections/docAccess.d.ts +1 -2
- package/dist/resolvers/collections/docAccess.d.ts.map +1 -1
- package/dist/resolvers/collections/docAccess.js +1 -2
- package/dist/resolvers/collections/docAccess.js.map +1 -1
- package/dist/resolvers/collections/duplicate.d.ts +4 -6
- package/dist/resolvers/collections/duplicate.d.ts.map +1 -1
- package/dist/resolvers/collections/duplicate.js +3 -3
- package/dist/resolvers/collections/duplicate.js.map +1 -1
- package/dist/resolvers/collections/find.d.ts +2 -4
- package/dist/resolvers/collections/find.d.ts.map +1 -1
- package/dist/resolvers/collections/find.js +16 -6
- package/dist/resolvers/collections/find.js.map +1 -1
- package/dist/resolvers/collections/findByID.d.ts +4 -6
- package/dist/resolvers/collections/findByID.d.ts.map +1 -1
- package/dist/resolvers/collections/findByID.js +10 -3
- package/dist/resolvers/collections/findByID.js.map +1 -1
- package/dist/resolvers/collections/findVersionByID.d.ts +2 -5
- package/dist/resolvers/collections/findVersionByID.d.ts.map +1 -1
- package/dist/resolvers/collections/findVersionByID.js +3 -4
- package/dist/resolvers/collections/findVersionByID.js.map +1 -1
- package/dist/resolvers/collections/findVersions.d.ts +3 -4
- package/dist/resolvers/collections/findVersions.d.ts.map +1 -1
- package/dist/resolvers/collections/findVersions.js +12 -6
- package/dist/resolvers/collections/findVersions.js.map +1 -1
- package/dist/resolvers/collections/restoreVersion.d.ts +3 -3
- package/dist/resolvers/collections/restoreVersion.d.ts.map +1 -1
- package/dist/resolvers/collections/restoreVersion.js +3 -3
- package/dist/resolvers/collections/restoreVersion.js.map +1 -1
- package/dist/resolvers/collections/update.d.ts +6 -7
- package/dist/resolvers/collections/update.d.ts.map +1 -1
- package/dist/resolvers/collections/update.js +12 -6
- package/dist/resolvers/collections/update.js.map +1 -1
- package/dist/resolvers/globals/docAccess.d.ts +1 -2
- package/dist/resolvers/globals/docAccess.d.ts.map +1 -1
- package/dist/resolvers/globals/docAccess.js +1 -2
- package/dist/resolvers/globals/docAccess.js.map +1 -1
- package/dist/resolvers/globals/findOne.d.ts +2 -2
- package/dist/resolvers/globals/findOne.d.ts.map +1 -1
- package/dist/resolvers/globals/findOne.js +8 -5
- package/dist/resolvers/globals/findOne.js.map +1 -1
- package/dist/resolvers/globals/findVersionByID.d.ts +2 -2
- package/dist/resolvers/globals/findVersionByID.d.ts.map +1 -1
- package/dist/resolvers/globals/findVersionByID.js +8 -5
- package/dist/resolvers/globals/findVersionByID.js.map +1 -1
- package/dist/resolvers/globals/findVersions.d.ts +2 -2
- package/dist/resolvers/globals/findVersions.d.ts.map +1 -1
- package/dist/resolvers/globals/findVersions.js +2 -3
- package/dist/resolvers/globals/findVersions.js.map +1 -1
- package/dist/resolvers/globals/index.d.ts +5 -5
- package/dist/resolvers/globals/index.d.ts.map +1 -1
- package/dist/resolvers/globals/index.js +5 -5
- package/dist/resolvers/globals/index.js.map +1 -1
- package/dist/resolvers/globals/restoreVersion.d.ts +3 -2
- package/dist/resolvers/globals/restoreVersion.d.ts.map +1 -1
- package/dist/resolvers/globals/restoreVersion.js +3 -3
- package/dist/resolvers/globals/restoreVersion.js.map +1 -1
- package/dist/resolvers/globals/update.d.ts +5 -6
- package/dist/resolvers/globals/update.d.ts.map +1 -1
- package/dist/resolvers/globals/update.js +8 -5
- package/dist/resolvers/globals/update.js.map +1 -1
- package/dist/resolvers/types.d.ts +1 -1
- package/dist/resolvers/types.d.ts.map +1 -1
- package/dist/resolvers/types.js.map +1 -1
- package/dist/schema/buildFallbackLocaleInputType.d.ts +2 -3
- package/dist/schema/buildFallbackLocaleInputType.d.ts.map +1 -1
- package/dist/schema/buildFallbackLocaleInputType.js +2 -3
- package/dist/schema/buildFallbackLocaleInputType.js.map +1 -1
- package/dist/schema/buildLocaleInputType.d.ts +2 -3
- package/dist/schema/buildLocaleInputType.d.ts.map +1 -1
- package/dist/schema/buildLocaleInputType.js +2 -3
- package/dist/schema/buildLocaleInputType.js.map +1 -1
- package/dist/schema/buildMutationInputType.d.ts +1 -2
- package/dist/schema/buildMutationInputType.d.ts.map +1 -1
- package/dist/schema/buildMutationInputType.js +62 -19
- package/dist/schema/buildMutationInputType.js.map +1 -1
- package/dist/schema/buildObjectType.d.ts +3 -4
- package/dist/schema/buildObjectType.d.ts.map +1 -1
- package/dist/schema/buildObjectType.js +200 -72
- package/dist/schema/buildObjectType.js.map +1 -1
- package/dist/schema/buildPaginatedListType.d.ts +1 -2
- package/dist/schema/buildPaginatedListType.d.ts.map +1 -1
- package/dist/schema/buildPaginatedListType.js +1 -2
- package/dist/schema/buildPaginatedListType.js.map +1 -1
- package/dist/schema/buildPoliciesType.d.ts +2 -2
- package/dist/schema/buildPoliciesType.d.ts.map +1 -1
- package/dist/schema/buildPoliciesType.js +7 -5
- package/dist/schema/buildPoliciesType.js.map +1 -1
- package/dist/schema/buildWhereInputType.d.ts +3 -3
- package/dist/schema/buildWhereInputType.d.ts.map +1 -1
- package/dist/schema/buildWhereInputType.js +6 -7
- package/dist/schema/buildWhereInputType.js.map +1 -1
- package/dist/schema/fieldToWhereInputSchemaMap.d.ts +2 -2
- package/dist/schema/fieldToWhereInputSchemaMap.d.ts.map +1 -1
- package/dist/schema/fieldToWhereInputSchemaMap.js +32 -9
- package/dist/schema/fieldToWhereInputSchemaMap.js.map +1 -1
- package/dist/schema/initCollections.d.ts +3 -4
- package/dist/schema/initCollections.d.ts.map +1 -1
- package/dist/schema/initCollections.js +81 -47
- package/dist/schema/initCollections.js.map +1 -1
- package/dist/schema/initGlobals.d.ts +3 -4
- package/dist/schema/initGlobals.d.ts.map +1 -1
- package/dist/schema/initGlobals.js +26 -20
- package/dist/schema/initGlobals.js.map +1 -1
- package/dist/schema/isFieldNullable.d.ts +2 -3
- package/dist/schema/isFieldNullable.d.ts.map +1 -1
- package/dist/schema/isFieldNullable.js +2 -3
- package/dist/schema/isFieldNullable.js.map +1 -1
- package/dist/schema/operators.d.ts +1 -2
- package/dist/schema/operators.d.ts.map +1 -1
- package/dist/schema/operators.js +1 -2
- package/dist/schema/operators.js.map +1 -1
- package/dist/schema/recursivelyBuildNestedPaths.d.ts +3 -3
- package/dist/schema/recursivelyBuildNestedPaths.d.ts.map +1 -1
- package/dist/schema/recursivelyBuildNestedPaths.js +3 -4
- package/dist/schema/recursivelyBuildNestedPaths.js.map +1 -1
- package/dist/schema/withNullableType.d.ts +2 -3
- package/dist/schema/withNullableType.d.ts.map +1 -1
- package/dist/schema/withNullableType.js +1 -2
- package/dist/schema/withNullableType.js.map +1 -1
- package/dist/schema/withOperators.d.ts +1 -1
- package/dist/schema/withOperators.d.ts.map +1 -1
- package/dist/schema/withOperators.js +13 -8
- package/dist/schema/withOperators.js.map +1 -1
- package/dist/utilities/combineParentName.d.ts +1 -2
- package/dist/utilities/combineParentName.d.ts.map +1 -1
- package/dist/utilities/combineParentName.js +2 -3
- package/dist/utilities/combineParentName.js.map +1 -1
- package/dist/utilities/formatName.d.ts +1 -2
- package/dist/utilities/formatName.d.ts.map +1 -1
- package/dist/utilities/formatName.js +1 -2
- package/dist/utilities/formatName.js.map +1 -1
- package/dist/utilities/formatName.spec.js +1 -1
- package/dist/utilities/formatName.spec.js.map +1 -1
- package/dist/utilities/formatOptions.d.ts +2 -3
- package/dist/utilities/formatOptions.d.ts.map +1 -1
- package/dist/utilities/formatOptions.js +2 -3
- package/dist/utilities/formatOptions.js.map +1 -1
- package/dist/utilities/groupOrTabHasRequiredSubfield.d.ts +1 -1
- package/dist/utilities/groupOrTabHasRequiredSubfield.d.ts.map +1 -1
- package/dist/utilities/groupOrTabHasRequiredSubfield.js +1 -1
- package/dist/utilities/groupOrTabHasRequiredSubfield.js.map +1 -1
- package/dist/utilities/wrapCustomResolver.d.ts +1 -1
- package/dist/utilities/wrapCustomResolver.d.ts.map +1 -1
- package/dist/utilities/wrapCustomResolver.js +1 -1
- package/dist/utilities/wrapCustomResolver.js.map +1 -1
- package/package.json +37 -24
- package/dist/utilities/getCheckIfLocaleObject.d.ts +0 -5
- package/dist/utilities/getCheckIfLocaleObject.d.ts.map +0 -1
- package/dist/utilities/getCheckIfLocaleObject.js +0 -3
- package/dist/utilities/getCheckIfLocaleObject.js.map +0 -1
- package/dist/utilities/uppercase.d.ts +0 -3
- package/dist/utilities/uppercase.d.ts.map +0 -1
- package/dist/utilities/uppercase.js +0 -11
- package/dist/utilities/uppercase.js.map +0 -1
- package/src/index.ts +0 -126
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig, Field, GlobalConfig, SanitizedConfig } from 'payload
|
|
1
|
+
import type { CollectionConfig, Field, GlobalConfig, SanitizedConfig } from 'payload';
|
|
2
2
|
import { GraphQLObjectType } from 'graphql';
|
|
3
3
|
type OperationType = 'create' | 'delete' | 'read' | 'readVersions' | 'unlock' | 'update';
|
|
4
4
|
type AccessScopes = 'docAccess' | undefined;
|
|
@@ -24,6 +24,6 @@ type BuildPolicyType = {
|
|
|
24
24
|
type: 'global';
|
|
25
25
|
});
|
|
26
26
|
export declare function buildPolicyType(args: BuildPolicyType): GraphQLObjectType;
|
|
27
|
-
export
|
|
27
|
+
export declare function buildPoliciesType(config: SanitizedConfig): GraphQLObjectType;
|
|
28
28
|
export {};
|
|
29
29
|
//# sourceMappingURL=buildPoliciesType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildPoliciesType.d.ts","sourceRoot":"","sources":["../../src/schema/buildPoliciesType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,KAAK,EACL,YAAY,EAEZ,eAAe,EAEhB,MAAM,
|
|
1
|
+
{"version":3,"file":"buildPoliciesType.d.ts","sourceRoot":"","sources":["../../src/schema/buildPoliciesType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,KAAK,EACL,YAAY,EAEZ,eAAe,EAEhB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAkC,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAM3E,KAAK,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,cAAc,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAExF,KAAK,YAAY,GAAG,WAAW,GAAG,SAAS,CAAA;AA8E3C,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,KAAK,EAAE,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,KAAK,EAAE,YAAY,CAAA;CACpB,CAAA;AACD,eAAO,MAAM,iBAAiB,SAAU,iBAAiB;;;;CA4BxD,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GAAG,CACA;IACE,MAAM,EAAE,gBAAgB,CAAA;IACxB,IAAI,EAAE,YAAY,CAAA;CACnB,GACD;IACE,MAAM,EAAE,YAAY,CAAA;IACpB,IAAI,EAAE,QAAQ,CAAA;CACf,CACJ,CAAA;AACD,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,iBAAiB,CAyDxE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,iBAAiB,CAyC5E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLBoolean, GraphQLNonNull, GraphQLObjectType } from 'graphql';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import formatName from '../utilities/formatName.js';
|
|
2
|
+
import { toWords } from 'payload';
|
|
3
|
+
import { GraphQLJSONObject } from '../packages/graphql-type-json/index.js';
|
|
4
|
+
import { formatName } from '../utilities/formatName.js';
|
|
5
5
|
const buildFields = (label, fieldsToBuild)=>fieldsToBuild.reduce((builtFields, field)=>{
|
|
6
6
|
const includeField = !field.hidden && field.type !== 'ui';
|
|
7
7
|
if (includeField) {
|
|
@@ -99,7 +99,9 @@ export function buildPolicyType(args) {
|
|
|
99
99
|
const { type, entity, scope, typeSuffix } = args;
|
|
100
100
|
const { slug, fields, graphQL, versions } = entity;
|
|
101
101
|
let operations = [];
|
|
102
|
-
if (graphQL === false)
|
|
102
|
+
if (graphQL === false) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
103
105
|
if (type === 'collection') {
|
|
104
106
|
operations = [
|
|
105
107
|
'create',
|
|
@@ -143,7 +145,7 @@ export function buildPolicyType(args) {
|
|
|
143
145
|
})
|
|
144
146
|
});
|
|
145
147
|
}
|
|
146
|
-
export
|
|
148
|
+
export function buildPoliciesType(config) {
|
|
147
149
|
const fields = {
|
|
148
150
|
canAccessAdmin: {
|
|
149
151
|
type: new GraphQLNonNull(GraphQLBoolean)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/buildPoliciesType.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload/types'\n\nimport { GraphQLBoolean, GraphQLNonNull, GraphQLObjectType } from 'graphql'\nimport { GraphQLJSONObject } from 'graphql-type-json'\nimport { toWords } from 'payload/utilities'\n\nimport formatName from '../utilities/formatName.js'\n\ntype OperationType = 'create' | 'delete' | 'read' | 'readVersions' | 'unlock' | 'update'\n\ntype AccessScopes = 'docAccess' | undefined\n\ntype ObjectTypeFields = {\n [key in 'fields' | OperationType]?: { type: GraphQLObjectType }\n}\n\nconst buildFields = (label, fieldsToBuild) =>\n fieldsToBuild.reduce((builtFields, field) => {\n const includeField = !field.hidden && field.type !== 'ui'\n if (includeField) {\n if (field.name) {\n const fieldName = formatName(field.name)\n\n const objectTypeFields: ObjectTypeFields = ['create', 'read', 'update', 'delete'].reduce(\n (operations, operation) => {\n const capitalizedOperation = operation.charAt(0).toUpperCase() + operation.slice(1)\n\n return {\n ...operations,\n [operation]: {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}_${capitalizedOperation}`,\n fields: {\n permission: {\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n },\n }),\n },\n }\n },\n {},\n )\n\n if (field.fields) {\n objectTypeFields.fields = {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}_Fields`,\n fields: buildFields(`${label}_${fieldName}`, field.fields),\n }),\n }\n }\n\n return {\n ...builtFields,\n [field.name]: {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}`,\n fields: objectTypeFields,\n }),\n },\n }\n }\n\n if (!field.name && field.fields) {\n const subFields = buildFields(label, field.fields)\n\n return {\n ...builtFields,\n ...subFields,\n }\n }\n\n if (field.type === 'tabs') {\n return field.tabs.reduce(\n (fieldsWithTabFields, tab) => {\n return {\n ...fieldsWithTabFields,\n ...buildFields(label, tab.fields),\n }\n },\n { ...builtFields },\n )\n }\n }\n return builtFields\n }, {})\n\ntype BuildEntityPolicy = {\n entityFields: Field[]\n name: string\n operations: OperationType[]\n scope: AccessScopes\n}\nexport const buildEntityPolicy = (args: BuildEntityPolicy) => {\n const { name, entityFields, operations, scope } = args\n\n const fieldsTypeName = toWords(`${name}-${scope || ''}-Fields`, true)\n const fields = {\n fields: {\n type: new GraphQLObjectType({\n name: fieldsTypeName,\n fields: buildFields(fieldsTypeName, entityFields),\n }),\n },\n }\n\n operations.forEach((operation) => {\n const operationTypeName = toWords(`${name}-${operation}-${scope || 'Access'}`, true)\n\n fields[operation] = {\n type: new GraphQLObjectType({\n name: operationTypeName,\n fields: {\n permission: { type: new GraphQLNonNull(GraphQLBoolean) },\n where: { type: GraphQLJSONObject },\n },\n }),\n }\n })\n\n return fields\n}\n\ntype BuildPolicyType = {\n scope?: AccessScopes\n typeSuffix?: string\n} & (\n | {\n entity: CollectionConfig\n type: 'collection'\n }\n | {\n entity: GlobalConfig\n type: 'global'\n }\n)\nexport function buildPolicyType(args: BuildPolicyType): GraphQLObjectType {\n const { type, entity, scope, typeSuffix } = args\n const { slug, fields, graphQL, versions } = entity\n\n let operations = []\n\n if (graphQL === false) return null\n\n if (type === 'collection') {\n operations = ['create', 'read', 'update', 'delete']\n\n if (\n entity.auth &&\n typeof entity.auth === 'object' &&\n typeof entity.auth.maxLoginAttempts !== 'undefined' &&\n entity.auth.maxLoginAttempts !== 0\n ) {\n operations.push('unlock')\n }\n\n if (versions) {\n operations.push('readVersions')\n }\n\n const collectionTypeName = formatName(`${slug}${typeSuffix || ''}`)\n\n return new GraphQLObjectType({\n name: collectionTypeName,\n fields: buildEntityPolicy({\n name: slug,\n entityFields: fields,\n operations,\n scope,\n }),\n })\n }\n\n // else create global type\n operations = ['read', 'update']\n\n if (entity.versions) {\n operations.push('readVersions')\n }\n\n const globalTypeName = formatName(`${global?.graphQL?.name || slug}${typeSuffix || ''}`)\n\n return new GraphQLObjectType({\n name: globalTypeName,\n fields: buildEntityPolicy({\n name: entity.graphQL ? entity?.graphQL?.name || slug : slug,\n entityFields: entity.fields,\n operations,\n scope,\n }),\n })\n}\n\nexport default function buildPoliciesType(config: SanitizedConfig): GraphQLObjectType {\n const fields = {\n canAccessAdmin: {\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n }\n\n Object.values(config.collections).forEach((collection: SanitizedCollectionConfig) => {\n if (collection.graphQL === false) {\n return\n }\n const collectionPolicyType = buildPolicyType({\n type: 'collection',\n entity: collection,\n typeSuffix: 'Access',\n })\n\n fields[formatName(collection.slug)] = {\n type: collectionPolicyType,\n }\n })\n\n Object.values(config.globals).forEach((global: SanitizedGlobalConfig) => {\n if (global.graphQL === false) {\n return\n }\n const globalPolicyType = buildPolicyType({\n type: 'global',\n entity: global,\n typeSuffix: 'Access',\n })\n\n fields[formatName(global.slug)] = {\n type: globalPolicyType,\n }\n })\n\n return new GraphQLObjectType({\n name: 'Access',\n fields,\n })\n}\n"],"names":["GraphQLBoolean","GraphQLNonNull","GraphQLObjectType","GraphQLJSONObject","toWords","formatName","buildFields","label","fieldsToBuild","reduce","builtFields","field","includeField","hidden","type","name","fieldName","objectTypeFields","operations","operation","capitalizedOperation","charAt","toUpperCase","slice","fields","permission","subFields","tabs","fieldsWithTabFields","tab","buildEntityPolicy","args","entityFields","scope","fieldsTypeName","forEach","operationTypeName","where","buildPolicyType","entity","typeSuffix","slug","graphQL","versions","auth","maxLoginAttempts","push","collectionTypeName","globalTypeName","global","buildPoliciesType","config","canAccessAdmin","Object","values","collections","collection","collectionPolicyType","globals","globalPolicyType"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;YACAe;QACF;IACF;AACF;AAEA,eAAe,SAASiB,kBAAkBC,MAAuB;IAC/D,MAAM3B,SAAS;QACb4B,gBAAgB;YACdtC,MAAM,IAAIb,eAAeD;QAC3B;IACF;IAEAqD,OAAOC,MAAM,CAACH,OAAOI,WAAW,EAAEpB,OAAO,CAAC,CAACqB;QACzC,IAAIA,WAAWd,OAAO,KAAK,OAAO;YAChC;QACF;QACA,MAAMe,uBAAuBnB,gBAAgB;YAC3CxB,MAAM;YACNyB,QAAQiB;YACRhB,YAAY;QACd;QAEAhB,MAAM,CAACnB,WAAWmD,WAAWf,IAAI,EAAE,GAAG;YACpC3B,MAAM2C;QACR;IACF;IAEAJ,OAAOC,MAAM,CAACH,OAAOO,OAAO,EAAEvB,OAAO,CAAC,CAACc;QACrC,IAAIA,QAAOP,OAAO,KAAK,OAAO;YAC5B;QACF;QACA,MAAMiB,mBAAmBrB,gBAAgB;YACvCxB,MAAM;YACNyB,QAAQU;YACRT,YAAY;QACd;QAEAhB,MAAM,CAACnB,WAAW4C,QAAOR,IAAI,EAAE,GAAG;YAChC3B,MAAM6C;QACR;IACF;IAEA,OAAO,IAAIzD,kBAAkB;QAC3Ba,MAAM;QACNS;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/schema/buildPoliciesType.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport { GraphQLBoolean, GraphQLNonNull, GraphQLObjectType } from 'graphql'\nimport { toWords } from 'payload'\n\nimport { GraphQLJSONObject } from '../packages/graphql-type-json/index.js'\nimport { formatName } from '../utilities/formatName.js'\n\ntype OperationType = 'create' | 'delete' | 'read' | 'readVersions' | 'unlock' | 'update'\n\ntype AccessScopes = 'docAccess' | undefined\n\ntype ObjectTypeFields = {\n [key in 'fields' | OperationType]?: { type: GraphQLObjectType }\n}\n\nconst buildFields = (label, fieldsToBuild) =>\n fieldsToBuild.reduce((builtFields, field) => {\n const includeField = !field.hidden && field.type !== 'ui'\n if (includeField) {\n if (field.name) {\n const fieldName = formatName(field.name)\n\n const objectTypeFields: ObjectTypeFields = ['create', 'read', 'update', 'delete'].reduce(\n (operations, operation) => {\n const capitalizedOperation = operation.charAt(0).toUpperCase() + operation.slice(1)\n\n return {\n ...operations,\n [operation]: {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}_${capitalizedOperation}`,\n fields: {\n permission: {\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n },\n }),\n },\n }\n },\n {},\n )\n\n if (field.fields) {\n objectTypeFields.fields = {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}_Fields`,\n fields: buildFields(`${label}_${fieldName}`, field.fields),\n }),\n }\n }\n\n return {\n ...builtFields,\n [field.name]: {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}`,\n fields: objectTypeFields,\n }),\n },\n }\n }\n\n if (!field.name && field.fields) {\n const subFields = buildFields(label, field.fields)\n\n return {\n ...builtFields,\n ...subFields,\n }\n }\n\n if (field.type === 'tabs') {\n return field.tabs.reduce(\n (fieldsWithTabFields, tab) => {\n return {\n ...fieldsWithTabFields,\n ...buildFields(label, tab.fields),\n }\n },\n { ...builtFields },\n )\n }\n }\n return builtFields\n }, {})\n\ntype BuildEntityPolicy = {\n entityFields: Field[]\n name: string\n operations: OperationType[]\n scope: AccessScopes\n}\nexport const buildEntityPolicy = (args: BuildEntityPolicy) => {\n const { name, entityFields, operations, scope } = args\n\n const fieldsTypeName = toWords(`${name}-${scope || ''}-Fields`, true)\n const fields = {\n fields: {\n type: new GraphQLObjectType({\n name: fieldsTypeName,\n fields: buildFields(fieldsTypeName, entityFields),\n }),\n },\n }\n\n operations.forEach((operation) => {\n const operationTypeName = toWords(`${name}-${operation}-${scope || 'Access'}`, true)\n\n fields[operation] = {\n type: new GraphQLObjectType({\n name: operationTypeName,\n fields: {\n permission: { type: new GraphQLNonNull(GraphQLBoolean) },\n where: { type: GraphQLJSONObject },\n },\n }),\n }\n })\n\n return fields\n}\n\ntype BuildPolicyType = {\n scope?: AccessScopes\n typeSuffix?: string\n} & (\n | {\n entity: CollectionConfig\n type: 'collection'\n }\n | {\n entity: GlobalConfig\n type: 'global'\n }\n)\nexport function buildPolicyType(args: BuildPolicyType): GraphQLObjectType {\n const { type, entity, scope, typeSuffix } = args\n const { slug, fields, graphQL, versions } = entity\n\n let operations = []\n\n if (graphQL === false) {\n return null\n }\n\n if (type === 'collection') {\n operations = ['create', 'read', 'update', 'delete']\n\n if (\n entity.auth &&\n typeof entity.auth === 'object' &&\n typeof entity.auth.maxLoginAttempts !== 'undefined' &&\n entity.auth.maxLoginAttempts !== 0\n ) {\n operations.push('unlock')\n }\n\n if (versions) {\n operations.push('readVersions')\n }\n\n const collectionTypeName = formatName(`${slug}${typeSuffix || ''}`)\n\n return new GraphQLObjectType({\n name: collectionTypeName,\n fields: buildEntityPolicy({\n name: slug,\n entityFields: fields,\n operations,\n scope,\n }),\n })\n }\n\n // else create global type\n operations = ['read', 'update']\n\n if (entity.versions) {\n operations.push('readVersions')\n }\n\n const globalTypeName = formatName(`${global?.graphQL?.name || slug}${typeSuffix || ''}`)\n\n return new GraphQLObjectType({\n name: globalTypeName,\n fields: buildEntityPolicy({\n name: entity.graphQL ? entity?.graphQL?.name || slug : slug,\n entityFields: entity.fields,\n operations,\n scope,\n }),\n })\n}\n\nexport function buildPoliciesType(config: SanitizedConfig): GraphQLObjectType {\n const fields = {\n canAccessAdmin: {\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n }\n\n Object.values(config.collections).forEach((collection: SanitizedCollectionConfig) => {\n if (collection.graphQL === false) {\n return\n }\n const collectionPolicyType = buildPolicyType({\n type: 'collection',\n entity: collection,\n typeSuffix: 'Access',\n })\n\n fields[formatName(collection.slug)] = {\n type: collectionPolicyType,\n }\n })\n\n Object.values(config.globals).forEach((global: SanitizedGlobalConfig) => {\n if (global.graphQL === false) {\n return\n }\n const globalPolicyType = buildPolicyType({\n type: 'global',\n entity: global,\n typeSuffix: 'Access',\n })\n\n fields[formatName(global.slug)] = {\n type: globalPolicyType,\n }\n })\n\n return new GraphQLObjectType({\n name: 'Access',\n fields,\n })\n}\n"],"names":["GraphQLBoolean","GraphQLNonNull","GraphQLObjectType","toWords","GraphQLJSONObject","formatName","buildFields","label","fieldsToBuild","reduce","builtFields","field","includeField","hidden","type","name","fieldName","objectTypeFields","operations","operation","capitalizedOperation","charAt","toUpperCase","slice","fields","permission","subFields","tabs","fieldsWithTabFields","tab","buildEntityPolicy","args","entityFields","scope","fieldsTypeName","forEach","operationTypeName","where","buildPolicyType","entity","typeSuffix","slug","graphQL","versions","auth","maxLoginAttempts","push","collectionTypeName","globalTypeName","global","buildPoliciesType","config","canAccessAdmin","Object","values","collections","collection","collectionPolicyType","globals","globalPolicyType"],"mappings":"AASA,SAASA,cAAc,EAAEC,cAAc,EAAEC,iBAAiB,QAAQ,UAAS;AAC3E,SAASC,OAAO,QAAQ,UAAS;AAEjC,SAASC,iBAAiB,QAAQ,yCAAwC;AAC1E,SAASC,UAAU,QAAQ,6BAA4B;AAUvD,MAAMC,cAAc,CAACC,OAAOC,gBAC1BA,cAAcC,MAAM,CAAC,CAACC,aAAaC;QACjC,MAAMC,eAAe,CAACD,MAAME,MAAM,IAAIF,MAAMG,IAAI,KAAK;QACrD,IAAIF,cAAc;YAChB,IAAID,MAAMI,IAAI,EAAE;gBACd,MAAMC,YAAYX,WAAWM,MAAMI,IAAI;gBAEvC,MAAME,mBAAqC;oBAAC;oBAAU;oBAAQ;oBAAU;iBAAS,CAACR,MAAM,CACtF,CAACS,YAAYC;oBACX,MAAMC,uBAAuBD,UAAUE,MAAM,CAAC,GAAGC,WAAW,KAAKH,UAAUI,KAAK,CAAC;oBAEjF,OAAO;wBACL,GAAGL,UAAU;wBACb,CAACC,UAAU,EAAE;4BACXL,MAAM,IAAIZ,kBAAkB;gCAC1Ba,MAAM,CAAC,EAAER,MAAM,CAAC,EAAES,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;IACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Field } from 'payload
|
|
1
|
+
import type { Field } from 'payload';
|
|
2
2
|
import { GraphQLInputObjectType } from 'graphql';
|
|
3
3
|
type Args = {
|
|
4
4
|
fields: Field[];
|
|
@@ -19,6 +19,6 @@ type Args = {
|
|
|
19
19
|
* directly searchable. Instead, we need to build a chained pathname
|
|
20
20
|
* using dot notation so MongoDB can properly search nested paths.
|
|
21
21
|
*/
|
|
22
|
-
declare const buildWhereInputType: ({ name, fields, parentName }: Args) => GraphQLInputObjectType;
|
|
23
|
-
export
|
|
22
|
+
export declare const buildWhereInputType: ({ name, fields, parentName }: Args) => GraphQLInputObjectType;
|
|
23
|
+
export {};
|
|
24
24
|
//# sourceMappingURL=buildWhereInputType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildWhereInputType.d.ts","sourceRoot":"","sources":["../../src/schema/buildWhereInputType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildWhereInputType.d.ts","sourceRoot":"","sources":["../../src/schema/buildWhereInputType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAsB,MAAM,SAAS,CAAA;AAExD,OAAO,EAAE,sBAAsB,EAAe,MAAM,SAAS,CAAA;AAQ7D,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,iCAAkC,IAAI,KAAG,sBAgFxE,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import formatName from '../utilities/formatName.js';
|
|
5
|
-
import fieldToSchemaMap from './fieldToWhereInputSchemaMap.js';
|
|
1
|
+
import { GraphQLInputObjectType, GraphQLList } from 'graphql';
|
|
2
|
+
import { flattenTopLevelFields } from 'payload';
|
|
3
|
+
import { fieldAffectsData, fieldHasSubFields, fieldIsPresentationalOnly } from 'payload/shared';
|
|
4
|
+
import { formatName } from '../utilities/formatName.js';
|
|
5
|
+
import { fieldToSchemaMap } from './fieldToWhereInputSchemaMap.js';
|
|
6
6
|
import { withOperators } from './withOperators.js';
|
|
7
7
|
/** This does as the function name suggests. It builds a where GraphQL input type
|
|
8
8
|
* for all the fields which are passed to the function.
|
|
@@ -17,7 +17,7 @@ import { withOperators } from './withOperators.js';
|
|
|
17
17
|
* 2. Relationships, groups, repeaters and flex content are not
|
|
18
18
|
* directly searchable. Instead, we need to build a chained pathname
|
|
19
19
|
* using dot notation so MongoDB can properly search nested paths.
|
|
20
|
-
*/ const buildWhereInputType = ({ name, fields, parentName })=>{
|
|
20
|
+
*/ export const buildWhereInputType = ({ name, fields, parentName })=>{
|
|
21
21
|
// This is the function that builds nested paths for all
|
|
22
22
|
// field types with nested paths.
|
|
23
23
|
const idField = flattenTopLevelFields(fields).find((field)=>fieldAffectsData(field) && field.name === 'id');
|
|
@@ -82,6 +82,5 @@ import { withOperators } from './withOperators.js';
|
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
};
|
|
85
|
-
export default buildWhereInputType;
|
|
86
85
|
|
|
87
86
|
//# sourceMappingURL=buildWhereInputType.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/buildWhereInputType.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/schema/buildWhereInputType.ts"],"sourcesContent":["import type { Field, FieldAffectingData } from 'payload'\n\nimport { GraphQLInputObjectType, GraphQLList } from 'graphql'\nimport { flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData, fieldHasSubFields, fieldIsPresentationalOnly } from 'payload/shared'\n\nimport { formatName } from '../utilities/formatName.js'\nimport { fieldToSchemaMap } from './fieldToWhereInputSchemaMap.js'\nimport { withOperators } from './withOperators.js'\n\ntype Args = {\n fields: Field[]\n name: string\n parentName: string\n}\n\n/** This does as the function name suggests. It builds a where GraphQL input type\n * for all the fields which are passed to the function.\n * Each field has different operators which may be valid for a where input type.\n * For example, a text field may have a \"contains\" operator, but a number field\n * may not.\n *\n * buildWhereInputType is similar to buildObjectType and operates\n * on a field basis with a few distinct differences.\n *\n * 1. Everything needs to be a GraphQLInputObjectType or scalar / enum\n * 2. Relationships, groups, repeaters and flex content are not\n * directly searchable. Instead, we need to build a chained pathname\n * using dot notation so MongoDB can properly search nested paths.\n */\nexport const buildWhereInputType = ({ name, fields, parentName }: Args): GraphQLInputObjectType => {\n // This is the function that builds nested paths for all\n // field types with nested paths.\n\n const idField = flattenTopLevelFields(fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n const fieldTypes = fields.reduce((schema, field) => {\n if (!fieldIsPresentationalOnly(field) && !field.hidden) {\n const getFieldSchema = fieldToSchemaMap({\n parentName,\n })[field.type]\n\n if (getFieldSchema) {\n const fieldSchema = getFieldSchema(field)\n\n if (fieldHasSubFields(field) || field.type === 'tabs') {\n return {\n ...schema,\n ...fieldSchema.reduce(\n (subFields, subField) => ({\n ...subFields,\n [formatName(subField.key)]: subField.type,\n }),\n {},\n ),\n }\n }\n\n return {\n ...schema,\n [formatName(field.name)]: fieldSchema,\n }\n }\n }\n\n return schema\n }, {})\n\n if (!idField) {\n fieldTypes.id = {\n type: withOperators({ name: 'id', type: 'text' } as FieldAffectingData, parentName),\n }\n }\n\n const fieldName = formatName(name)\n\n const recursiveFields = {\n AND: {\n type: new GraphQLList(\n new GraphQLInputObjectType({\n name: `${fieldName}_where_and`,\n fields: () => ({\n ...fieldTypes,\n ...recursiveFields,\n }),\n }),\n ),\n },\n OR: {\n type: new GraphQLList(\n new GraphQLInputObjectType({\n name: `${fieldName}_where_or`,\n fields: () => ({\n ...fieldTypes,\n ...recursiveFields,\n }),\n }),\n ),\n },\n }\n\n return new GraphQLInputObjectType({\n name: `${fieldName}_where`,\n fields: {\n ...fieldTypes,\n ...recursiveFields,\n },\n })\n}\n"],"names":["GraphQLInputObjectType","GraphQLList","flattenTopLevelFields","fieldAffectsData","fieldHasSubFields","fieldIsPresentationalOnly","formatName","fieldToSchemaMap","withOperators","buildWhereInputType","name","fields","parentName","idField","find","field","fieldTypes","reduce","schema","hidden","getFieldSchema","type","fieldSchema","subFields","subField","key","id","fieldName","recursiveFields","AND","OR"],"mappings":"AAEA,SAASA,sBAAsB,EAAEC,WAAW,QAAQ,UAAS;AAC7D,SAASC,qBAAqB,QAAQ,UAAS;AAC/C,SAASC,gBAAgB,EAAEC,iBAAiB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAE/F,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,gBAAgB,QAAQ,kCAAiC;AAClE,SAASC,aAAa,QAAQ,qBAAoB;AAQlD;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,sBAAsB,CAAC,EAAEC,IAAI,EAAEC,MAAM,EAAEC,UAAU,EAAQ;IACpE,wDAAwD;IACxD,iCAAiC;IAEjC,MAAMC,UAAUX,sBAAsBS,QAAQG,IAAI,CAChD,CAACC,QAAUZ,iBAAiBY,UAAUA,MAAML,IAAI,KAAK;IAGvD,MAAMM,aAAaL,OAAOM,MAAM,CAAC,CAACC,QAAQH;QACxC,IAAI,CAACV,0BAA0BU,UAAU,CAACA,MAAMI,MAAM,EAAE;YACtD,MAAMC,iBAAiBb,iBAAiB;gBACtCK;YACF,EAAE,CAACG,MAAMM,IAAI,CAAC;YAEd,IAAID,gBAAgB;gBAClB,MAAME,cAAcF,eAAeL;gBAEnC,IAAIX,kBAAkBW,UAAUA,MAAMM,IAAI,KAAK,QAAQ;oBACrD,OAAO;wBACL,GAAGH,MAAM;wBACT,GAAGI,YAAYL,MAAM,CACnB,CAACM,WAAWC,WAAc,CAAA;gCACxB,GAAGD,SAAS;gCACZ,CAACjB,WAAWkB,SAASC,GAAG,EAAE,EAAED,SAASH,IAAI;4BAC3C,CAAA,GACA,CAAC,EACF;oBACH;gBACF;gBAEA,OAAO;oBACL,GAAGH,MAAM;oBACT,CAACZ,WAAWS,MAAML,IAAI,EAAE,EAAEY;gBAC5B;YACF;QACF;QAEA,OAAOJ;IACT,GAAG,CAAC;IAEJ,IAAI,CAACL,SAAS;QACZG,WAAWU,EAAE,GAAG;YACdL,MAAMb,cAAc;gBAAEE,MAAM;gBAAMW,MAAM;YAAO,GAAyBT;QAC1E;IACF;IAEA,MAAMe,YAAYrB,WAAWI;IAE7B,MAAMkB,kBAAkB;QACtBC,KAAK;YACHR,MAAM,IAAIpB,YACR,IAAID,uBAAuB;gBACzBU,MAAM,CAAC,EAAEiB,UAAU,UAAU,CAAC;gBAC9BhB,QAAQ,IAAO,CAAA;wBACb,GAAGK,UAAU;wBACb,GAAGY,eAAe;oBACpB,CAAA;YACF;QAEJ;QACAE,IAAI;YACFT,MAAM,IAAIpB,YACR,IAAID,uBAAuB;gBACzBU,MAAM,CAAC,EAAEiB,UAAU,SAAS,CAAC;gBAC7BhB,QAAQ,IAAO,CAAA;wBACb,GAAGK,UAAU;wBACb,GAAGY,eAAe;oBACpB,CAAA;YACF;QAEJ;IACF;IAEA,OAAO,IAAI5B,uBAAuB;QAChCU,MAAM,CAAC,EAAEiB,UAAU,MAAM,CAAC;QAC1BhB,QAAQ;YACN,GAAGK,UAAU;YACb,GAAGY,eAAe;QACpB;IACF;AACF,EAAC"}
|
|
@@ -2,6 +2,6 @@ type Args = {
|
|
|
2
2
|
nestedFieldName?: string;
|
|
3
3
|
parentName: string;
|
|
4
4
|
};
|
|
5
|
-
declare const fieldToSchemaMap: ({ nestedFieldName, parentName }: Args) => any;
|
|
6
|
-
export
|
|
5
|
+
export declare const fieldToSchemaMap: ({ nestedFieldName, parentName }: Args) => any;
|
|
6
|
+
export {};
|
|
7
7
|
//# sourceMappingURL=fieldToWhereInputSchemaMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldToWhereInputSchemaMap.d.ts","sourceRoot":"","sources":["../../src/schema/fieldToWhereInputSchemaMap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fieldToWhereInputSchemaMap.d.ts","sourceRoot":"","sources":["../../src/schema/fieldToWhereInputSchemaMap.ts"],"names":[],"mappings":"AA8BA,KAAK,IAAI,GAAG;IACV,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,gBAAgB,oCAAqC,IAAI,KAAG,GA+HvE,CAAA"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { GraphQLEnumType, GraphQLInputObjectType } from 'graphql';
|
|
2
|
-
import
|
|
3
|
-
import combineParentName from '../utilities/combineParentName.js';
|
|
4
|
-
import formatName from '../utilities/formatName.js';
|
|
5
|
-
import recursivelyBuildNestedPaths from './recursivelyBuildNestedPaths.js';
|
|
2
|
+
import { GraphQLJSON } from '../packages/graphql-type-json/index.js';
|
|
3
|
+
import { combineParentName } from '../utilities/combineParentName.js';
|
|
4
|
+
import { formatName } from '../utilities/formatName.js';
|
|
5
|
+
import { recursivelyBuildNestedPaths } from './recursivelyBuildNestedPaths.js';
|
|
6
6
|
import { withOperators } from './withOperators.js';
|
|
7
|
-
const
|
|
8
|
-
const fieldToSchemaMap = ({ nestedFieldName, parentName })=>({
|
|
7
|
+
export const fieldToSchemaMap = ({ nestedFieldName, parentName })=>({
|
|
9
8
|
array: (field)=>recursivelyBuildNestedPaths({
|
|
10
9
|
field,
|
|
11
10
|
nestedFieldName2: nestedFieldName,
|
|
@@ -95,10 +94,34 @@ const fieldToSchemaMap = ({ nestedFieldName, parentName })=>({
|
|
|
95
94
|
textarea: (field)=>({
|
|
96
95
|
type: withOperators(field, parentName)
|
|
97
96
|
}),
|
|
98
|
-
upload: (field)=>
|
|
97
|
+
upload: (field)=>{
|
|
98
|
+
if (Array.isArray(field.relationTo)) {
|
|
99
|
+
return {
|
|
100
|
+
type: new GraphQLInputObjectType({
|
|
101
|
+
name: `${combineParentName(parentName, field.name)}_Relation`,
|
|
102
|
+
fields: {
|
|
103
|
+
relationTo: {
|
|
104
|
+
type: new GraphQLEnumType({
|
|
105
|
+
name: `${combineParentName(parentName, field.name)}_Relation_RelationTo`,
|
|
106
|
+
values: field.relationTo.reduce((values, relation)=>({
|
|
107
|
+
...values,
|
|
108
|
+
[formatName(relation)]: {
|
|
109
|
+
value: relation
|
|
110
|
+
}
|
|
111
|
+
}), {})
|
|
112
|
+
})
|
|
113
|
+
},
|
|
114
|
+
value: {
|
|
115
|
+
type: GraphQLJSON
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
99
122
|
type: withOperators(field, parentName)
|
|
100
|
-
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
101
125
|
});
|
|
102
|
-
export default fieldToSchemaMap;
|
|
103
126
|
|
|
104
127
|
//# sourceMappingURL=fieldToWhereInputSchemaMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/fieldToWhereInputSchemaMap.ts"],"sourcesContent":["import type {\n ArrayField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SelectField,\n TabsField,\n
|
|
1
|
+
{"version":3,"sources":["../../src/schema/fieldToWhereInputSchemaMap.ts"],"sourcesContent":["import type {\n ArrayField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport { GraphQLEnumType, GraphQLInputObjectType } from 'graphql'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { recursivelyBuildNestedPaths } from './recursivelyBuildNestedPaths.js'\nimport { withOperators } from './withOperators.js'\n\ntype Args = {\n nestedFieldName?: string\n parentName: string\n}\n\nexport const fieldToSchemaMap = ({ nestedFieldName, parentName }: Args): any => ({\n array: (field: ArrayField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n checkbox: (field: CheckboxField) => ({\n type: withOperators(field, parentName),\n }),\n code: (field: CodeField) => ({\n type: withOperators(field, parentName),\n }),\n collapsible: (field: CollapsibleField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n date: (field: DateField) => ({\n type: withOperators(field, parentName),\n }),\n email: (field: EmailField) => ({\n type: withOperators(field, parentName),\n }),\n group: (field: GroupField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n json: (field: JSONField) => ({\n type: withOperators(field, parentName),\n }),\n number: (field: NumberField) => ({\n type: withOperators(field, parentName),\n }),\n point: (field: PointField) => ({\n type: withOperators(field, parentName),\n }),\n radio: (field: RadioField) => ({\n type: withOperators(field, parentName),\n }),\n relationship: (field: RelationshipField) => {\n if (Array.isArray(field.relationTo)) {\n return {\n type: new GraphQLInputObjectType({\n name: `${combineParentName(parentName, field.name)}_Relation`,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Relation_RelationTo`,\n values: field.relationTo.reduce(\n (values, relation) => ({\n ...values,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n }),\n }\n }\n\n return {\n type: withOperators(field, parentName),\n }\n },\n richText: (field: RichTextField) => ({\n type: withOperators(field, parentName),\n }),\n row: (field: RowField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n select: (field: SelectField) => ({\n type: withOperators(field, parentName),\n }),\n tabs: (field: TabsField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n text: (field: TextField) => ({\n type: withOperators(field, parentName),\n }),\n textarea: (field: TextareaField) => ({\n type: withOperators(field, parentName),\n }),\n upload: (field: UploadField) => {\n if (Array.isArray(field.relationTo)) {\n return {\n type: new GraphQLInputObjectType({\n name: `${combineParentName(parentName, field.name)}_Relation`,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Relation_RelationTo`,\n values: field.relationTo.reduce(\n (values, relation) => ({\n ...values,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n }),\n }\n }\n\n return {\n type: withOperators(field, parentName),\n }\n },\n})\n"],"names":["GraphQLEnumType","GraphQLInputObjectType","GraphQLJSON","combineParentName","formatName","recursivelyBuildNestedPaths","withOperators","fieldToSchemaMap","nestedFieldName","parentName","array","field","nestedFieldName2","checkbox","type","code","collapsible","date","email","group","json","number","point","radio","relationship","Array","isArray","relationTo","name","fields","values","reduce","relation","value","richText","row","select","tabs","text","textarea","upload"],"mappings":"AAsBA,SAASA,eAAe,EAAEC,sBAAsB,QAAQ,UAAS;AAEjE,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,2BAA2B,QAAQ,mCAAkC;AAC9E,SAASC,aAAa,QAAQ,qBAAoB;AAOlD,OAAO,MAAMC,mBAAmB,CAAC,EAAEC,eAAe,EAAEC,UAAU,EAAQ,GAAW,CAAA;QAC/EC,OAAO,CAACC,QACNN,4BAA4B;gBAC1BM;gBACAC,kBAAkBJ;gBAClBC;YACF;QACFI,UAAU,CAACF,QAA0B,CAAA;gBACnCG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA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+1,8 @@
|
|
|
1
|
-
import type { GraphQLInfo } from 'payload
|
|
2
|
-
import type { SanitizedConfig } from 'payload/types';
|
|
1
|
+
import type { GraphQLInfo, SanitizedConfig } from 'payload';
|
|
3
2
|
type InitCollectionsGraphQLArgs = {
|
|
4
3
|
config: SanitizedConfig;
|
|
5
4
|
graphqlResult: GraphQLInfo;
|
|
6
5
|
};
|
|
7
|
-
declare function
|
|
8
|
-
export
|
|
6
|
+
export declare function initCollections({ config, graphqlResult }: InitCollectionsGraphQLArgs): void;
|
|
7
|
+
export {};
|
|
9
8
|
//# sourceMappingURL=initCollections.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initCollections.d.ts","sourceRoot":"","sources":["../../src/schema/initCollections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initCollections.d.ts","sourceRoot":"","sources":["../../src/schema/initCollections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,WAAW,EAEX,eAAe,EAChB,MAAM,SAAS,CAAA;AAyChB,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,eAAe,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;CAC3B,CAAA;AACD,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,0BAA0B,GAAG,IAAI,CAkd3F"}
|
|
@@ -1,37 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import createResolver from '../resolvers/collections/create.js';
|
|
15
|
-
import getDeleteResolver from '../resolvers/collections/delete.js';
|
|
1
|
+
import { GraphQLBoolean, GraphQLInt, GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql';
|
|
2
|
+
import { buildVersionCollectionFields, flattenTopLevelFields, formatNames, toWords } from 'payload';
|
|
3
|
+
import { fieldAffectsData } from 'payload/shared';
|
|
4
|
+
import { forgotPassword } from '../resolvers/auth/forgotPassword.js';
|
|
5
|
+
import { init } from '../resolvers/auth/init.js';
|
|
6
|
+
import { login } from '../resolvers/auth/login.js';
|
|
7
|
+
import { logout } from '../resolvers/auth/logout.js';
|
|
8
|
+
import { me } from '../resolvers/auth/me.js';
|
|
9
|
+
import { refresh } from '../resolvers/auth/refresh.js';
|
|
10
|
+
import { resetPassword } from '../resolvers/auth/resetPassword.js';
|
|
11
|
+
import { unlock } from '../resolvers/auth/unlock.js';
|
|
12
|
+
import { verifyEmail } from '../resolvers/auth/verifyEmail.js';
|
|
13
|
+
import { countResolver } from '../resolvers/collections/count.js';
|
|
14
|
+
import { createResolver } from '../resolvers/collections/create.js';
|
|
15
|
+
import { getDeleteResolver } from '../resolvers/collections/delete.js';
|
|
16
16
|
import { docAccessResolver } from '../resolvers/collections/docAccess.js';
|
|
17
|
-
import duplicateResolver from '../resolvers/collections/duplicate.js';
|
|
18
|
-
import findResolver from '../resolvers/collections/find.js';
|
|
19
|
-
import findByIDResolver from '../resolvers/collections/findByID.js';
|
|
20
|
-
import findVersionByIDResolver from '../resolvers/collections/findVersionByID.js';
|
|
21
|
-
import findVersionsResolver from '../resolvers/collections/findVersions.js';
|
|
22
|
-
import restoreVersionResolver from '../resolvers/collections/restoreVersion.js';
|
|
23
|
-
import updateResolver from '../resolvers/collections/update.js';
|
|
24
|
-
import formatName from '../utilities/formatName.js';
|
|
17
|
+
import { duplicateResolver } from '../resolvers/collections/duplicate.js';
|
|
18
|
+
import { findResolver } from '../resolvers/collections/find.js';
|
|
19
|
+
import { findByIDResolver } from '../resolvers/collections/findByID.js';
|
|
20
|
+
import { findVersionByIDResolver } from '../resolvers/collections/findVersionByID.js';
|
|
21
|
+
import { findVersionsResolver } from '../resolvers/collections/findVersions.js';
|
|
22
|
+
import { restoreVersionResolver } from '../resolvers/collections/restoreVersion.js';
|
|
23
|
+
import { updateResolver } from '../resolvers/collections/update.js';
|
|
24
|
+
import { formatName } from '../utilities/formatName.js';
|
|
25
25
|
import { buildMutationInputType, getCollectionIDType } from './buildMutationInputType.js';
|
|
26
|
-
import buildObjectType from './buildObjectType.js';
|
|
27
|
-
import buildPaginatedListType from './buildPaginatedListType.js';
|
|
26
|
+
import { buildObjectType } from './buildObjectType.js';
|
|
27
|
+
import { buildPaginatedListType } from './buildPaginatedListType.js';
|
|
28
28
|
import { buildPolicyType } from './buildPoliciesType.js';
|
|
29
|
-
import buildWhereInputType from './buildWhereInputType.js';
|
|
30
|
-
function
|
|
29
|
+
import { buildWhereInputType } from './buildWhereInputType.js';
|
|
30
|
+
export function initCollections({ config, graphqlResult }) {
|
|
31
31
|
Object.keys(graphqlResult.collections).forEach((slug)=>{
|
|
32
32
|
const collection = graphqlResult.collections[slug];
|
|
33
33
|
const { config: collectionConfig, config: { fields, graphQL = {}, versions } } = collection;
|
|
34
|
-
if (!graphQL)
|
|
34
|
+
if (!graphQL) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
35
37
|
let singularName;
|
|
36
38
|
let pluralName;
|
|
37
39
|
const fromSlug = formatNames(collection.config.slug);
|
|
@@ -162,6 +164,30 @@ function initCollectionsGraphQL({ config, graphqlResult }) {
|
|
|
162
164
|
},
|
|
163
165
|
resolve: findResolver(collection)
|
|
164
166
|
};
|
|
167
|
+
graphqlResult.Query.fields[`count${pluralName}`] = {
|
|
168
|
+
type: new GraphQLObjectType({
|
|
169
|
+
name: `count${pluralName}`,
|
|
170
|
+
fields: {
|
|
171
|
+
totalDocs: {
|
|
172
|
+
type: GraphQLInt
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
args: {
|
|
177
|
+
draft: {
|
|
178
|
+
type: GraphQLBoolean
|
|
179
|
+
},
|
|
180
|
+
where: {
|
|
181
|
+
type: collection.graphQL.whereInputType
|
|
182
|
+
},
|
|
183
|
+
...config.localization ? {
|
|
184
|
+
locale: {
|
|
185
|
+
type: graphqlResult.types.localeInputType
|
|
186
|
+
}
|
|
187
|
+
} : {}
|
|
188
|
+
},
|
|
189
|
+
resolve: countResolver(collection)
|
|
190
|
+
};
|
|
165
191
|
graphqlResult.Query.fields[`docAccess${singularName}`] = {
|
|
166
192
|
type: buildPolicyType({
|
|
167
193
|
type: 'collection',
|
|
@@ -319,13 +345,16 @@ function initCollectionsGraphQL({ config, graphqlResult }) {
|
|
|
319
345
|
args: {
|
|
320
346
|
id: {
|
|
321
347
|
type: versionIDType
|
|
348
|
+
},
|
|
349
|
+
draft: {
|
|
350
|
+
type: GraphQLBoolean
|
|
322
351
|
}
|
|
323
352
|
},
|
|
324
353
|
resolve: restoreVersionResolver(collection)
|
|
325
354
|
};
|
|
326
355
|
}
|
|
327
356
|
if (collectionConfig.auth) {
|
|
328
|
-
const authFields = collectionConfig.auth.disableLocalStrategy ? [] : [
|
|
357
|
+
const authFields = collectionConfig.auth.disableLocalStrategy || collectionConfig.auth.loginWithUsername && !collectionConfig.auth.loginWithUsername.allowEmailLogin && !collectionConfig.auth.loginWithUsername.requireEmail ? [] : [
|
|
329
358
|
{
|
|
330
359
|
name: 'email',
|
|
331
360
|
type: 'email',
|
|
@@ -357,6 +386,9 @@ function initCollectionsGraphQL({ config, graphqlResult }) {
|
|
|
357
386
|
exp: {
|
|
358
387
|
type: GraphQLInt
|
|
359
388
|
},
|
|
389
|
+
strategy: {
|
|
390
|
+
type: GraphQLString
|
|
391
|
+
},
|
|
360
392
|
token: {
|
|
361
393
|
type: GraphQLString
|
|
362
394
|
},
|
|
@@ -381,16 +413,14 @@ function initCollectionsGraphQL({ config, graphqlResult }) {
|
|
|
381
413
|
refreshedToken: {
|
|
382
414
|
type: GraphQLString
|
|
383
415
|
},
|
|
416
|
+
strategy: {
|
|
417
|
+
type: GraphQLString
|
|
418
|
+
},
|
|
384
419
|
user: {
|
|
385
420
|
type: collection.graphQL.JWT
|
|
386
421
|
}
|
|
387
422
|
}
|
|
388
423
|
}),
|
|
389
|
-
args: {
|
|
390
|
-
token: {
|
|
391
|
-
type: GraphQLString
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
424
|
resolve: refresh(collection)
|
|
395
425
|
};
|
|
396
426
|
graphqlResult.Mutation.fields[`logout${singularName}`] = {
|
|
@@ -398,14 +428,23 @@ function initCollectionsGraphQL({ config, graphqlResult }) {
|
|
|
398
428
|
resolve: logout(collection)
|
|
399
429
|
};
|
|
400
430
|
if (!collectionConfig.auth.disableLocalStrategy) {
|
|
431
|
+
const authArgs = {};
|
|
432
|
+
const canLoginWithEmail = !collectionConfig.auth.loginWithUsername || collectionConfig.auth.loginWithUsername?.allowEmailLogin;
|
|
433
|
+
const canLoginWithUsername = collectionConfig.auth.loginWithUsername;
|
|
434
|
+
if (canLoginWithEmail) {
|
|
435
|
+
authArgs['email'] = {
|
|
436
|
+
type: new GraphQLNonNull(GraphQLString)
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
if (canLoginWithUsername) {
|
|
440
|
+
authArgs['username'] = {
|
|
441
|
+
type: new GraphQLNonNull(GraphQLString)
|
|
442
|
+
};
|
|
443
|
+
}
|
|
401
444
|
if (collectionConfig.auth.maxLoginAttempts > 0) {
|
|
402
445
|
graphqlResult.Mutation.fields[`unlock${singularName}`] = {
|
|
403
446
|
type: new GraphQLNonNull(GraphQLBoolean),
|
|
404
|
-
args:
|
|
405
|
-
email: {
|
|
406
|
-
type: new GraphQLNonNull(GraphQLString)
|
|
407
|
-
}
|
|
408
|
-
},
|
|
447
|
+
args: authArgs,
|
|
409
448
|
resolve: unlock(collection)
|
|
410
449
|
};
|
|
411
450
|
}
|
|
@@ -425,9 +464,7 @@ function initCollectionsGraphQL({ config, graphqlResult }) {
|
|
|
425
464
|
}
|
|
426
465
|
}),
|
|
427
466
|
args: {
|
|
428
|
-
|
|
429
|
-
type: GraphQLString
|
|
430
|
-
},
|
|
467
|
+
...authArgs,
|
|
431
468
|
password: {
|
|
432
469
|
type: GraphQLString
|
|
433
470
|
}
|
|
@@ -440,12 +477,10 @@ function initCollectionsGraphQL({ config, graphqlResult }) {
|
|
|
440
477
|
disableEmail: {
|
|
441
478
|
type: GraphQLBoolean
|
|
442
479
|
},
|
|
443
|
-
email: {
|
|
444
|
-
type: new GraphQLNonNull(GraphQLString)
|
|
445
|
-
},
|
|
446
480
|
expiration: {
|
|
447
481
|
type: GraphQLInt
|
|
448
|
-
}
|
|
482
|
+
},
|
|
483
|
+
...authArgs
|
|
449
484
|
},
|
|
450
485
|
resolve: forgotPassword(collection)
|
|
451
486
|
};
|
|
@@ -484,6 +519,5 @@ function initCollectionsGraphQL({ config, graphqlResult }) {
|
|
|
484
519
|
}
|
|
485
520
|
});
|
|
486
521
|
}
|
|
487
|
-
export default initCollectionsGraphQL;
|
|
488
522
|
|
|
489
523
|
//# sourceMappingURL=initCollections.js.map
|