@payloadcms/graphql 3.0.0-alpha.47 → 3.0.0-alpha.49
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/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -17
- package/dist/index.js.map +1 -1
- package/dist/resolvers/auth/access.d.ts +1 -1
- package/dist/resolvers/auth/access.d.ts.map +1 -1
- package/dist/resolvers/auth/access.js +1 -1
- package/dist/resolvers/auth/access.js.map +1 -1
- package/dist/resolvers/auth/forgotPassword.d.ts.map +1 -1
- package/dist/resolvers/auth/forgotPassword.js.map +1 -1
- package/dist/resolvers/auth/init.d.ts.map +1 -1
- package/dist/resolvers/auth/init.js.map +1 -1
- package/dist/resolvers/auth/login.d.ts.map +1 -1
- package/dist/resolvers/auth/login.js +3 -3
- package/dist/resolvers/auth/login.js.map +1 -1
- package/dist/resolvers/auth/logout.d.ts.map +1 -1
- package/dist/resolvers/auth/logout.js +1 -1
- package/dist/resolvers/auth/logout.js.map +1 -1
- package/dist/resolvers/auth/me.d.ts.map +1 -1
- package/dist/resolvers/auth/me.js.map +1 -1
- package/dist/resolvers/auth/refresh.d.ts.map +1 -1
- package/dist/resolvers/auth/refresh.js +3 -3
- package/dist/resolvers/auth/refresh.js.map +1 -1
- package/dist/resolvers/auth/resetPassword.d.ts.map +1 -1
- package/dist/resolvers/auth/resetPassword.js +3 -3
- package/dist/resolvers/auth/resetPassword.js.map +1 -1
- package/dist/resolvers/auth/unlock.d.ts.map +1 -1
- package/dist/resolvers/auth/unlock.js.map +1 -1
- package/dist/resolvers/auth/verifyEmail.d.ts.map +1 -1
- package/dist/resolvers/auth/verifyEmail.js.map +1 -1
- package/dist/resolvers/collections/create.d.ts +1 -1
- package/dist/resolvers/collections/create.d.ts.map +1 -1
- package/dist/resolvers/collections/create.js.map +1 -1
- package/dist/resolvers/collections/delete.d.ts.map +1 -1
- package/dist/resolvers/collections/delete.js.map +1 -1
- package/dist/resolvers/collections/docAccess.d.ts +1 -1
- package/dist/resolvers/collections/docAccess.d.ts.map +1 -1
- package/dist/resolvers/collections/docAccess.js +2 -2
- package/dist/resolvers/collections/docAccess.js.map +1 -1
- package/dist/resolvers/collections/duplicate.d.ts +13 -0
- package/dist/resolvers/collections/duplicate.d.ts.map +1 -0
- package/dist/resolvers/collections/duplicate.js +22 -0
- package/dist/resolvers/collections/duplicate.js.map +1 -0
- package/dist/resolvers/collections/find.d.ts.map +1 -1
- package/dist/resolvers/collections/find.js.map +1 -1
- package/dist/resolvers/collections/findByID.d.ts.map +1 -1
- package/dist/resolvers/collections/findByID.js.map +1 -1
- package/dist/resolvers/collections/findVersionByID.d.ts +1 -1
- package/dist/resolvers/collections/findVersionByID.d.ts.map +1 -1
- package/dist/resolvers/collections/findVersionByID.js.map +1 -1
- package/dist/resolvers/collections/findVersions.d.ts +1 -1
- package/dist/resolvers/collections/findVersions.d.ts.map +1 -1
- package/dist/resolvers/collections/findVersions.js.map +1 -1
- package/dist/resolvers/collections/restoreVersion.d.ts.map +1 -1
- package/dist/resolvers/collections/restoreVersion.js.map +1 -1
- package/dist/resolvers/collections/update.d.ts.map +1 -1
- package/dist/resolvers/collections/update.js.map +1 -1
- package/dist/resolvers/globals/docAccess.d.ts +1 -1
- package/dist/resolvers/globals/docAccess.d.ts.map +1 -1
- package/dist/resolvers/globals/docAccess.js.map +1 -1
- package/dist/resolvers/globals/findOne.d.ts.map +1 -1
- package/dist/resolvers/globals/findOne.js.map +1 -1
- package/dist/resolvers/globals/findVersionByID.d.ts.map +1 -1
- package/dist/resolvers/globals/findVersionByID.js.map +1 -1
- package/dist/resolvers/globals/findVersions.d.ts.map +1 -1
- package/dist/resolvers/globals/findVersions.js.map +1 -1
- package/dist/resolvers/globals/restoreVersion.d.ts.map +1 -1
- package/dist/resolvers/globals/restoreVersion.js.map +1 -1
- package/dist/resolvers/globals/update.d.ts +1 -1
- package/dist/resolvers/globals/update.d.ts.map +1 -1
- package/dist/resolvers/globals/update.js.map +1 -1
- package/dist/resolvers/types.d.ts +2 -2
- package/dist/resolvers/types.d.ts.map +1 -1
- package/dist/resolvers/types.js.map +1 -1
- package/dist/schema/buildFallbackLocaleInputType.d.ts +1 -1
- package/dist/schema/buildFallbackLocaleInputType.d.ts.map +1 -1
- package/dist/schema/buildFallbackLocaleInputType.js.map +1 -1
- package/dist/schema/buildLocaleInputType.d.ts +1 -1
- package/dist/schema/buildLocaleInputType.d.ts.map +1 -1
- package/dist/schema/buildLocaleInputType.js.map +1 -1
- package/dist/schema/buildMutationInputType.d.ts +6 -6
- package/dist/schema/buildMutationInputType.d.ts.map +1 -1
- package/dist/schema/buildMutationInputType.js +9 -9
- package/dist/schema/buildMutationInputType.js.map +1 -1
- package/dist/schema/buildObjectType.d.ts +5 -5
- package/dist/schema/buildObjectType.d.ts.map +1 -1
- package/dist/schema/buildObjectType.js +15 -15
- package/dist/schema/buildObjectType.js.map +1 -1
- package/dist/schema/buildPoliciesType.d.ts +1 -1
- package/dist/schema/buildPoliciesType.d.ts.map +1 -1
- package/dist/schema/buildPoliciesType.js +4 -4
- package/dist/schema/buildPoliciesType.js.map +1 -1
- package/dist/schema/buildWhereInputType.d.ts +1 -1
- package/dist/schema/buildWhereInputType.d.ts.map +1 -1
- package/dist/schema/buildWhereInputType.js +1 -1
- package/dist/schema/buildWhereInputType.js.map +1 -1
- package/dist/schema/fieldToWhereInputSchemaMap.js.map +1 -1
- package/dist/schema/initCollections.d.ts.map +1 -1
- package/dist/schema/initCollections.js +99 -89
- package/dist/schema/initCollections.js.map +1 -1
- package/dist/schema/initGlobals.d.ts.map +1 -1
- package/dist/schema/initGlobals.js +33 -32
- package/dist/schema/initGlobals.js.map +1 -1
- package/dist/schema/recursivelyBuildNestedPaths.d.ts.map +1 -1
- package/dist/schema/recursivelyBuildNestedPaths.js +2 -2
- package/dist/schema/recursivelyBuildNestedPaths.js.map +1 -1
- package/dist/schema/withNullableType.d.ts.map +1 -1
- 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 +3 -3
- package/dist/schema/withOperators.js.map +1 -1
- package/dist/utilities/wrapCustomResolver.d.ts.map +1 -1
- package/dist/utilities/wrapCustomResolver.js.map +1 -1
- package/package.json +4 -6
- package/src/index.ts +19 -19
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */ import { GraphQLBoolean, GraphQLInt, GraphQLNonNull, GraphQLString } from 'graphql';
|
|
2
|
-
import
|
|
2
|
+
import pluralize from 'pluralize';
|
|
3
|
+
const { singular } = pluralize;
|
|
3
4
|
import { toWords } from 'payload/utilities';
|
|
4
5
|
import { buildVersionGlobalFields } from 'payload/versions';
|
|
5
|
-
import { buildMutationInputType } from './buildMutationInputType.js';
|
|
6
|
-
import buildObjectType from './buildObjectType.js';
|
|
7
|
-
import buildPaginatedListType from './buildPaginatedListType.js';
|
|
8
|
-
import { buildPolicyType } from './buildPoliciesType.js';
|
|
9
|
-
import buildWhereInputType from './buildWhereInputType.js';
|
|
10
|
-
import formatName from '../utilities/formatName.js';
|
|
11
6
|
import { docAccessResolver } from '../resolvers/globals/docAccess.js';
|
|
12
7
|
import findOneResolver from '../resolvers/globals/findOne.js';
|
|
13
8
|
import findVersionByIDResolver from '../resolvers/globals/findVersionByID.js';
|
|
14
9
|
import findVersionsResolver from '../resolvers/globals/findVersions.js';
|
|
15
10
|
import restoreVersionResolver from '../resolvers/globals/restoreVersion.js';
|
|
16
11
|
import updateResolver from '../resolvers/globals/update.js';
|
|
12
|
+
import formatName from '../utilities/formatName.js';
|
|
13
|
+
import { buildMutationInputType } from './buildMutationInputType.js';
|
|
14
|
+
import buildObjectType from './buildObjectType.js';
|
|
15
|
+
import buildPaginatedListType from './buildPaginatedListType.js';
|
|
16
|
+
import { buildPolicyType } from './buildPoliciesType.js';
|
|
17
|
+
import buildWhereInputType from './buildWhereInputType.js';
|
|
17
18
|
function initGlobalsGraphQL({ config, graphqlResult }) {
|
|
18
19
|
Object.keys(graphqlResult.globals.config).forEach((slug)=>{
|
|
19
20
|
const global = graphqlResult.globals.config[slug];
|
|
@@ -26,23 +27,24 @@ function initGlobalsGraphQL({ config, graphqlResult }) {
|
|
|
26
27
|
if (!graphqlResult.globals.graphQL) graphqlResult.globals.graphQL = {};
|
|
27
28
|
const updateMutationInputType = buildMutationInputType({
|
|
28
29
|
name: formattedName,
|
|
30
|
+
config,
|
|
29
31
|
fields,
|
|
30
|
-
parentName: formattedName,
|
|
31
32
|
graphqlResult,
|
|
32
|
-
|
|
33
|
+
parentName: formattedName
|
|
33
34
|
});
|
|
34
35
|
graphqlResult.globals.graphQL[slug] = {
|
|
35
|
-
mutationInputType: updateMutationInputType ? new GraphQLNonNull(updateMutationInputType) : null,
|
|
36
36
|
type: buildObjectType({
|
|
37
37
|
name: formattedName,
|
|
38
|
+
config,
|
|
38
39
|
fields,
|
|
39
40
|
forceNullable: forceNullableObjectType,
|
|
40
|
-
parentName: formattedName,
|
|
41
41
|
graphqlResult,
|
|
42
|
-
|
|
43
|
-
})
|
|
42
|
+
parentName: formattedName
|
|
43
|
+
}),
|
|
44
|
+
mutationInputType: updateMutationInputType ? new GraphQLNonNull(updateMutationInputType) : null
|
|
44
45
|
};
|
|
45
46
|
graphqlResult.Query.fields[formattedName] = {
|
|
47
|
+
type: graphqlResult.globals.graphQL[slug].type,
|
|
46
48
|
args: {
|
|
47
49
|
draft: {
|
|
48
50
|
type: GraphQLBoolean
|
|
@@ -56,10 +58,10 @@ function initGlobalsGraphQL({ config, graphqlResult }) {
|
|
|
56
58
|
}
|
|
57
59
|
} : {}
|
|
58
60
|
},
|
|
59
|
-
resolve: findOneResolver(global)
|
|
60
|
-
type: graphqlResult.globals.graphQL[slug].type
|
|
61
|
+
resolve: findOneResolver(global)
|
|
61
62
|
};
|
|
62
63
|
graphqlResult.Mutation.fields[`update${formattedName}`] = {
|
|
64
|
+
type: graphqlResult.globals.graphQL[slug].type,
|
|
63
65
|
args: {
|
|
64
66
|
...updateMutationInputType ? {
|
|
65
67
|
data: {
|
|
@@ -75,17 +77,16 @@ function initGlobalsGraphQL({ config, graphqlResult }) {
|
|
|
75
77
|
}
|
|
76
78
|
} : {}
|
|
77
79
|
},
|
|
78
|
-
resolve: updateResolver(global)
|
|
79
|
-
type: graphqlResult.globals.graphQL[slug].type
|
|
80
|
+
resolve: updateResolver(global)
|
|
80
81
|
};
|
|
81
82
|
graphqlResult.Query.fields[`docAccess${formattedName}`] = {
|
|
82
|
-
resolve: docAccessResolver(global),
|
|
83
83
|
type: buildPolicyType({
|
|
84
|
+
type: 'global',
|
|
84
85
|
entity: global,
|
|
85
86
|
scope: 'docAccess',
|
|
86
|
-
type: 'global',
|
|
87
87
|
typeSuffix: 'DocAccess'
|
|
88
|
-
})
|
|
88
|
+
}),
|
|
89
|
+
resolve: docAccessResolver(global)
|
|
89
90
|
};
|
|
90
91
|
if (global.versions) {
|
|
91
92
|
const idType = config.db.defaultIDType === 'number' ? GraphQLInt : GraphQLString;
|
|
@@ -97,24 +98,25 @@ function initGlobalsGraphQL({ config, graphqlResult }) {
|
|
|
97
98
|
},
|
|
98
99
|
{
|
|
99
100
|
name: 'createdAt',
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
type: 'date',
|
|
102
|
+
label: 'Created At'
|
|
102
103
|
},
|
|
103
104
|
{
|
|
104
105
|
name: 'updatedAt',
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
type: 'date',
|
|
107
|
+
label: 'Updated At'
|
|
107
108
|
}
|
|
108
109
|
];
|
|
109
110
|
graphqlResult.globals.graphQL[slug].versionType = buildObjectType({
|
|
110
111
|
name: `${formattedName}Version`,
|
|
112
|
+
config,
|
|
111
113
|
fields: versionGlobalFields,
|
|
112
114
|
forceNullable: forceNullableObjectType,
|
|
113
|
-
parentName: `${formattedName}Version`,
|
|
114
115
|
graphqlResult,
|
|
115
|
-
|
|
116
|
+
parentName: `${formattedName}Version`
|
|
116
117
|
});
|
|
117
118
|
graphqlResult.Query.fields[`version${formatName(formattedName)}`] = {
|
|
119
|
+
type: graphqlResult.globals.graphQL[slug].versionType,
|
|
118
120
|
args: {
|
|
119
121
|
id: {
|
|
120
122
|
type: idType
|
|
@@ -128,10 +130,10 @@ function initGlobalsGraphQL({ config, graphqlResult }) {
|
|
|
128
130
|
}
|
|
129
131
|
} : {}
|
|
130
132
|
},
|
|
131
|
-
resolve: findVersionByIDResolver(global)
|
|
132
|
-
type: graphqlResult.globals.graphQL[slug].versionType
|
|
133
|
+
resolve: findVersionByIDResolver(global)
|
|
133
134
|
};
|
|
134
135
|
graphqlResult.Query.fields[`versions${formattedName}`] = {
|
|
136
|
+
type: buildPaginatedListType(`versions${formatName(formattedName)}`, graphqlResult.globals.graphQL[slug].versionType),
|
|
135
137
|
args: {
|
|
136
138
|
where: {
|
|
137
139
|
type: buildWhereInputType({
|
|
@@ -158,17 +160,16 @@ function initGlobalsGraphQL({ config, graphqlResult }) {
|
|
|
158
160
|
type: GraphQLString
|
|
159
161
|
}
|
|
160
162
|
},
|
|
161
|
-
resolve: findVersionsResolver(global)
|
|
162
|
-
type: buildPaginatedListType(`versions${formatName(formattedName)}`, graphqlResult.globals.graphQL[slug].versionType)
|
|
163
|
+
resolve: findVersionsResolver(global)
|
|
163
164
|
};
|
|
164
165
|
graphqlResult.Mutation.fields[`restoreVersion${formatName(formattedName)}`] = {
|
|
166
|
+
type: graphqlResult.globals.graphQL[slug].type,
|
|
165
167
|
args: {
|
|
166
168
|
id: {
|
|
167
169
|
type: idType
|
|
168
170
|
}
|
|
169
171
|
},
|
|
170
|
-
resolve: restoreVersionResolver(global)
|
|
171
|
-
type: graphqlResult.globals.graphQL[slug].type
|
|
172
|
+
resolve: restoreVersionResolver(global)
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
175
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/initGlobals.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { GraphQLBoolean, GraphQLInt, GraphQLNonNull, GraphQLString } from 'graphql'\nimport { singular } from 'pluralize'\nimport { toWords } from 'payload/utilities'\nimport { buildVersionGlobalFields } from 'payload/versions'\n\nimport type { GraphQLInfo } from 'payload/config'\nimport type { Field, SanitizedConfig, SanitizedGlobalConfig } from 'payload/types'\n\nimport { buildMutationInputType } from './buildMutationInputType.js'\nimport buildObjectType from './buildObjectType.js'\nimport buildPaginatedListType from './buildPaginatedListType.js'\nimport { buildPolicyType } from './buildPoliciesType.js'\nimport buildWhereInputType from './buildWhereInputType.js'\nimport formatName from '../utilities/formatName.js'\nimport { docAccessResolver } from '../resolvers/globals/docAccess.js'\nimport findOneResolver from '../resolvers/globals/findOne.js'\nimport findVersionByIDResolver from '../resolvers/globals/findVersionByID.js'\nimport findVersionsResolver from '../resolvers/globals/findVersions.js'\nimport restoreVersionResolver from '../resolvers/globals/restoreVersion.js'\nimport updateResolver from '../resolvers/globals/update.js'\n\ntype InitGlobalsGraphQLArgs = {\n config: SanitizedConfig\n graphqlResult: GraphQLInfo\n}\nfunction initGlobalsGraphQL({ config, graphqlResult }: InitGlobalsGraphQLArgs): void {\n Object.keys(graphqlResult.globals.config).forEach((slug) => {\n const global: SanitizedGlobalConfig = graphqlResult.globals.config[slug]\n const { fields, graphQL, versions } = global\n\n if (graphQL === false) {\n return\n }\n\n const formattedName = graphQL?.name ? graphQL.name : singular(toWords(global.slug, true))\n\n const forceNullableObjectType = Boolean(versions?.drafts)\n\n if (!graphqlResult.globals.graphQL) graphqlResult.globals.graphQL = {}\n\n const updateMutationInputType = buildMutationInputType({\n name: formattedName,\n fields,\n parentName: formattedName,\n graphqlResult,\n config,\n })\n graphqlResult.globals.graphQL[slug] = {\n mutationInputType: updateMutationInputType\n ? new GraphQLNonNull(updateMutationInputType)\n : null,\n type: buildObjectType({\n name: formattedName,\n fields,\n forceNullable: forceNullableObjectType,\n parentName: formattedName,\n graphqlResult,\n config,\n }),\n }\n\n graphqlResult.Query.fields[formattedName] = {\n args: {\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findOneResolver(global),\n type: graphqlResult.globals.graphQL[slug].type,\n }\n\n graphqlResult.Mutation.fields[`update${formattedName}`] = {\n args: {\n ...(updateMutationInputType\n ? { data: { type: graphqlResult.globals.graphQL[slug].mutationInputType } }\n : {}),\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: updateResolver(global),\n type: graphqlResult.globals.graphQL[slug].type,\n }\n\n graphqlResult.Query.fields[`docAccess${formattedName}`] = {\n resolve: docAccessResolver(global),\n type: buildPolicyType({\n entity: global,\n scope: 'docAccess',\n type: 'global',\n typeSuffix: 'DocAccess',\n }),\n }\n\n if (global.versions) {\n const idType = config.db.defaultIDType === 'number' ? GraphQLInt : GraphQLString\n\n const versionGlobalFields: Field[] = [\n ...buildVersionGlobalFields(global),\n {\n name: 'id',\n type: config.db.defaultIDType as 'text',\n },\n {\n name: 'createdAt',\n label: 'Created At',\n type: 'date',\n },\n {\n name: 'updatedAt',\n label: 'Updated At',\n type: 'date',\n },\n ]\n\n graphqlResult.globals.graphQL[slug].versionType = buildObjectType({\n name: `${formattedName}Version`,\n fields: versionGlobalFields,\n forceNullable: forceNullableObjectType,\n parentName: `${formattedName}Version`,\n graphqlResult,\n config,\n })\n\n graphqlResult.Query.fields[`version${formatName(formattedName)}`] = {\n args: {\n id: { type: idType },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findVersionByIDResolver(global),\n type: graphqlResult.globals.graphQL[slug].versionType,\n }\n graphqlResult.Query.fields[`versions${formattedName}`] = {\n args: {\n where: {\n type: buildWhereInputType({\n name: `versions${formattedName}`,\n fields: versionGlobalFields,\n parentName: `versions${formattedName}`,\n }),\n },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n limit: { type: GraphQLInt },\n page: { type: GraphQLInt },\n sort: { type: GraphQLString },\n },\n resolve: findVersionsResolver(global),\n type: buildPaginatedListType(\n `versions${formatName(formattedName)}`,\n graphqlResult.globals.graphQL[slug].versionType,\n ),\n }\n graphqlResult.Mutation.fields[`restoreVersion${formatName(formattedName)}`] = {\n args: {\n id: { type: idType },\n },\n resolve: restoreVersionResolver(global),\n type: graphqlResult.globals.graphQL[slug].type,\n }\n }\n })\n}\n\nexport default initGlobalsGraphQL\n"],"names":["GraphQLBoolean","GraphQLInt","GraphQLNonNull","GraphQLString","singular","toWords","buildVersionGlobalFields","buildMutationInputType","buildObjectType","buildPaginatedListType","buildPolicyType","buildWhereInputType","formatName","docAccessResolver","findOneResolver","findVersionByIDResolver","findVersionsResolver","restoreVersionResolver","updateResolver","initGlobalsGraphQL","config","graphqlResult","Object","keys","globals","forEach","slug","global","fields","graphQL","versions","formattedName","name","forceNullableObjectType","Boolean","drafts","updateMutationInputType","parentName","mutationInputType","type","forceNullable","Query","args","draft","localization","fallbackLocale","types","fallbackLocaleInputType","locale","localeInputType","resolve","Mutation","data","entity","scope","typeSuffix","idType","db","defaultIDType","versionGlobalFields","label","versionType","id","where","limit","page","sort"],"mappings":"AAAA,oCAAoC,GACpC,SAASA,cAAc,EAAEC,UAAU,EAAEC,cAAc,EAAEC,aAAa,QAAQ,UAAS;AACnF,SAASC,QAAQ,QAAQ,YAAW;AACpC,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,wBAAwB,QAAQ,mBAAkB;AAK3D,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,OAAOC,qBAAqB,uBAAsB;AAClD,OAAOC,4BAA4B,8BAA6B;AAChE,S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AMtC;oBAAW;oBACzBiE,MAAM;wBAAE3B,MAAMpC;oBAAc;gBAC9B;gBACA+C,SAASlC,qBAAqBW;gBAC9BY,MAAM9B,uBACJ,CAAC,QAAQ,EAAEG,WAAWmB,eAAe,CAAC,EACtCV,cAAcG,OAAO,CAACK,OAAO,CAACH,KAAK,CAACmC,WAAW;YAEnD;YACAxC,cAAc8B,QAAQ,CAACvB,MAAM,CAAC,CAAC,cAAc,EAAEhB,WAAWmB,eAAe,CAAC,CAAC,GAAG;gBAC5EW,MAAM;oBACJoB,IAAI;wBAAEvB,MAAMiB;oBAAO;gBACrB;gBACAN,SAASjC,uBAAuBU;gBAChCY,MAAMlB,cAAcG,OAAO,CAACK,OAAO,CAACH,KAAK,CAACa,IAAI;YAChD;QACF;IACF;AACF;AAEA,eAAepB,mBAAkB"}
|
|
1
|
+
{"version":3,"sources":["../../src/schema/initGlobals.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { GraphQLBoolean, GraphQLInt, GraphQLNonNull, GraphQLString } from 'graphql'\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { GraphQLInfo } from 'payload/config'\nimport type { Field, SanitizedConfig, SanitizedGlobalConfig } from 'payload/types'\n\nimport { toWords } from 'payload/utilities'\nimport { buildVersionGlobalFields } from 'payload/versions'\n\nimport { docAccessResolver } from '../resolvers/globals/docAccess.js'\nimport findOneResolver from '../resolvers/globals/findOne.js'\nimport findVersionByIDResolver from '../resolvers/globals/findVersionByID.js'\nimport findVersionsResolver from '../resolvers/globals/findVersions.js'\nimport restoreVersionResolver from '../resolvers/globals/restoreVersion.js'\nimport updateResolver from '../resolvers/globals/update.js'\nimport formatName from '../utilities/formatName.js'\nimport { buildMutationInputType } from './buildMutationInputType.js'\nimport buildObjectType from './buildObjectType.js'\nimport buildPaginatedListType from './buildPaginatedListType.js'\nimport { buildPolicyType } from './buildPoliciesType.js'\nimport buildWhereInputType from './buildWhereInputType.js'\n\ntype InitGlobalsGraphQLArgs = {\n config: SanitizedConfig\n graphqlResult: GraphQLInfo\n}\nfunction initGlobalsGraphQL({ config, graphqlResult }: InitGlobalsGraphQLArgs): void {\n Object.keys(graphqlResult.globals.config).forEach((slug) => {\n const global: SanitizedGlobalConfig = graphqlResult.globals.config[slug]\n const { fields, graphQL, versions } = global\n\n if (graphQL === false) {\n return\n }\n\n const formattedName = graphQL?.name ? graphQL.name : singular(toWords(global.slug, true))\n\n const forceNullableObjectType = Boolean(versions?.drafts)\n\n if (!graphqlResult.globals.graphQL) graphqlResult.globals.graphQL = {}\n\n const updateMutationInputType = buildMutationInputType({\n name: formattedName,\n config,\n fields,\n graphqlResult,\n parentName: formattedName,\n })\n graphqlResult.globals.graphQL[slug] = {\n type: buildObjectType({\n name: formattedName,\n config,\n fields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: formattedName,\n }),\n mutationInputType: updateMutationInputType\n ? new GraphQLNonNull(updateMutationInputType)\n : null,\n }\n\n graphqlResult.Query.fields[formattedName] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findOneResolver(global),\n }\n\n graphqlResult.Mutation.fields[`update${formattedName}`] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n ...(updateMutationInputType\n ? { data: { type: graphqlResult.globals.graphQL[slug].mutationInputType } }\n : {}),\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: updateResolver(global),\n }\n\n graphqlResult.Query.fields[`docAccess${formattedName}`] = {\n type: buildPolicyType({\n type: 'global',\n entity: global,\n scope: 'docAccess',\n typeSuffix: 'DocAccess',\n }),\n resolve: docAccessResolver(global),\n }\n\n if (global.versions) {\n const idType = config.db.defaultIDType === 'number' ? GraphQLInt : GraphQLString\n\n const versionGlobalFields: Field[] = [\n ...buildVersionGlobalFields(global),\n {\n name: 'id',\n type: config.db.defaultIDType as 'text',\n },\n {\n name: 'createdAt',\n type: 'date',\n label: 'Created At',\n },\n {\n name: 'updatedAt',\n type: 'date',\n label: 'Updated At',\n },\n ]\n\n graphqlResult.globals.graphQL[slug].versionType = buildObjectType({\n name: `${formattedName}Version`,\n config,\n fields: versionGlobalFields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: `${formattedName}Version`,\n })\n\n graphqlResult.Query.fields[`version${formatName(formattedName)}`] = {\n type: graphqlResult.globals.graphQL[slug].versionType,\n args: {\n id: { type: idType },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findVersionByIDResolver(global),\n }\n graphqlResult.Query.fields[`versions${formattedName}`] = {\n type: buildPaginatedListType(\n `versions${formatName(formattedName)}`,\n graphqlResult.globals.graphQL[slug].versionType,\n ),\n args: {\n where: {\n type: buildWhereInputType({\n name: `versions${formattedName}`,\n fields: versionGlobalFields,\n parentName: `versions${formattedName}`,\n }),\n },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n limit: { type: GraphQLInt },\n page: { type: GraphQLInt },\n sort: { type: GraphQLString },\n },\n resolve: findVersionsResolver(global),\n }\n graphqlResult.Mutation.fields[`restoreVersion${formatName(formattedName)}`] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n id: { type: idType },\n },\n resolve: restoreVersionResolver(global),\n }\n }\n })\n}\n\nexport default initGlobalsGraphQL\n"],"names":["GraphQLBoolean","GraphQLInt","GraphQLNonNull","GraphQLString","pluralize","singular","toWords","buildVersionGlobalFields","docAccessResolver","findOneResolver","findVersionByIDResolver","findVersionsResolver","restoreVersionResolver","updateResolver","formatName","buildMutationInputType","buildObjectType","buildPaginatedListType","buildPolicyType","buildWhereInputType","initGlobalsGraphQL","config","graphqlResult","Object","keys","globals","forEach","slug","global","fields","graphQL","versions","formattedName","name","forceNullableObjectType","Boolean","drafts","updateMutationInputType","parentName","type","forceNullable","mutationInputType","Query","args","draft","localization","fallbackLocale","types","fallbackLocaleInputType","locale","localeInputType","resolve","Mutation","data","entity","scope","typeSuffix","idType","db","defaultIDType","versionGlobalFields","label","versionType","id","where","limit","page","sort"],"mappings":"AAAA,oCAAoC,GACpC,SAASA,cAAc,EAAEC,UAAU,EAAEC,cAAc,EAAEC,aAAa,QAAQ,UAAS;AACnF,OAAOC,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAKrB,SAASE,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,wBAAwB,QAAQ,mBAAkB;AAE3D,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,OAAOC,qBAAqB,kCAAiC;AAC7D,OAAOC,6BAA6B,0CAAyC;AAC7E,OAAOC,0BAA0B,uCAAsC;AACvE,OAAOC,4BAA4B,yCAAwC;AAC3E,OAAOC,oBAAoB,iCAAgC;AAC3D,OAAOC,gBAAgB,6BAA4B;AACnD,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,OAAOC,qBAAqB,uBAAsB;AAClD,OAAOC,4BAA4B,8BAA6B;AAChE,SAASC,eAAe,QAAQ,yBAAwB;AACxD,OAAOC,yBAAyB,2BAA0B;AAM1D,SAASC,mBAAmB,EAAEC,MAAM,EAAEC,aAAa,EAA0B;IAC3EC,OAAOC,IAAI,CAACF,cAAcG,OAAO,CAACJ,MAAM,EAAEK,OAAO,CAAC,CAACC;QACjD,MAAMC,SAAgCN,cAAcG,OAAO,CAACJ,MAAM,CAACM,KAAK;QACxE,MAAM,EAAEE,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGH;QAEtC,IAAIE,YAAY,OAAO;YACrB;QACF;QAEA,MAAME,gBAAgBF,SAASG,OAAOH,QAAQG,I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elyBuildNestedPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"recursivelyBuildNestedPaths.d.ts","sourceRoot":"","sources":["../../src/schema/recursivelyBuildNestedPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAMlE,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,kBAAkB,GAAG,SAAS,CAAA;IACrC,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,QAAA,MAAM,2BAA2B,4CAA6C,IAAI,QAmEjF,CAAA;AAED,eAAe,2BAA2B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/recursivelyBuildNestedPaths.ts"],"sourcesContent":["import type { FieldWithSubFields, TabsField } from 'payload/types'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/types'\nimport fieldToSchemaMap from './fieldToWhereInputSchemaMap.js'\n\ntype Args = {\n field: FieldWithSubFields | TabsField\n nestedFieldName2: string\n parentName: string\n}\n\nconst recursivelyBuildNestedPaths = ({ field, nestedFieldName2, parentName }: Args) => {\n const fieldName = fieldAffectsData(field) ? field.name : undefined\n const nestedFieldName = fieldName || nestedFieldName2\n\n if (field.type === 'tabs') {\n // if the tab has a name, treat it as a group\n // otherwise, treat it as a row\n return field.tabs.reduce((tabSchema, tab: any) => {\n tabSchema.push(\n ...recursivelyBuildNestedPaths({\n field: {\n ...tab,\n type: 'name' in tab ? 'group' : 'row',\n },\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n )\n return tabSchema\n }, [])\n }\n\n const nestedPaths = field.fields.reduce((nestedFields, nestedField) => {\n if (!fieldIsPresentationalOnly(nestedField)) {\n if (!fieldAffectsData(nestedField)) {\n return [\n ...nestedFields,\n ...recursivelyBuildNestedPaths({\n field: nestedField,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n ]\n }\n\n const nestedPathName = fieldAffectsData(nestedField)\n ? `${nestedFieldName ? `${nestedFieldName}__` : ''}${nestedField.name}`\n : undefined\n const getFieldSchema = fieldToSchemaMap({\n nestedFieldName,\n parentName,\n })[nestedField.type]\n\n if (getFieldSchema) {\n const fieldSchema = getFieldSchema({\n ...nestedField,\n name: nestedPathName,\n })\n\n if (Array.isArray(fieldSchema)) {\n return [...nestedFields, ...fieldSchema]\n }\n\n return [\n ...nestedFields,\n {\n
|
|
1
|
+
{"version":3,"sources":["../../src/schema/recursivelyBuildNestedPaths.ts"],"sourcesContent":["import type { FieldWithSubFields, TabsField } from 'payload/types'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/types'\n\nimport fieldToSchemaMap from './fieldToWhereInputSchemaMap.js'\n\ntype Args = {\n field: FieldWithSubFields | TabsField\n nestedFieldName2: string\n parentName: string\n}\n\nconst recursivelyBuildNestedPaths = ({ field, nestedFieldName2, parentName }: Args) => {\n const fieldName = fieldAffectsData(field) ? field.name : undefined\n const nestedFieldName = fieldName || nestedFieldName2\n\n if (field.type === 'tabs') {\n // if the tab has a name, treat it as a group\n // otherwise, treat it as a row\n return field.tabs.reduce((tabSchema, tab: any) => {\n tabSchema.push(\n ...recursivelyBuildNestedPaths({\n field: {\n ...tab,\n type: 'name' in tab ? 'group' : 'row',\n },\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n )\n return tabSchema\n }, [])\n }\n\n const nestedPaths = field.fields.reduce((nestedFields, nestedField) => {\n if (!fieldIsPresentationalOnly(nestedField)) {\n if (!fieldAffectsData(nestedField)) {\n return [\n ...nestedFields,\n ...recursivelyBuildNestedPaths({\n field: nestedField,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n ]\n }\n\n const nestedPathName = fieldAffectsData(nestedField)\n ? `${nestedFieldName ? `${nestedFieldName}__` : ''}${nestedField.name}`\n : undefined\n const getFieldSchema = fieldToSchemaMap({\n nestedFieldName,\n parentName,\n })[nestedField.type]\n\n if (getFieldSchema) {\n const fieldSchema = getFieldSchema({\n ...nestedField,\n name: nestedPathName,\n })\n\n if (Array.isArray(fieldSchema)) {\n return [...nestedFields, ...fieldSchema]\n }\n\n return [\n ...nestedFields,\n {\n type: fieldSchema,\n key: nestedPathName,\n },\n ]\n }\n }\n\n return nestedFields\n }, [])\n\n return nestedPaths\n}\n\nexport default recursivelyBuildNestedPaths\n"],"names":["fieldAffectsData","fieldIsPresentationalOnly","fieldToSchemaMap","recursivelyBuildNestedPaths","field","nestedFieldName2","parentName","fieldName","name","undefined","nestedFieldName","type","tabs","reduce","tabSchema","tab","push","nestedPaths","fields","nestedFields","nestedField","nestedPathName","getFieldSchema","fieldSchema","Array","isArray","key"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,gBAAe;AAE3E,OAAOC,sBAAsB,kCAAiC;AAQ9D,MAAMC,8BAA8B,CAAC,EAAEC,KAAK,EAAEC,gBAAgB,EAAEC,UAAU,EAAQ;IAChF,MAAMC,YAAYP,iBAAiBI,SAASA,MAAMI,IAAI,GAAGC;IACzD,MAAMC,kBAAkBH,aAAaF;IAErC,IAAID,MAAMO,IAAI,KAAK,QAAQ;QACzB,6CAA6C;QAC7C,+BAA+B;QAC/B,OAAOP,MAAMQ,IAAI,CAACC,MAAM,CAAC,CAACC,WAAWC;YACnCD,UAAUE,IAAI,IACTb,4BAA4B;gBAC7BC,OAAO;oBACL,GAAGW,GAAG;oBACNJ,MAAM,UAAUI,MAAM,UAAU;gBAClC;gBACAV,kBAAkBK;gBAClBJ;YACF;YAEF,OAAOQ;QACT,GAAG,EAAE;IACP;IAEA,MAAMG,cAAcb,MAAMc,MAAM,CAACL,MAAM,CAAC,CAACM,cAAcC;QACrD,IAAI,CAACnB,0BAA0BmB,cAAc;YAC3C,IAAI,CAACpB,iBAAiBoB,cAAc;gBAClC,OAAO;uBACFD;uBACAhB,4BAA4B;wBAC7BC,OAAOgB;wBACPf,kBAAkBK;wBAClBJ;oBACF;iBACD;YACH;YAEA,MAAMe,iBAAiBrB,iBAAiBoB,eACpC,CAAC,EAAEV,kBAAkB,CAAC,EAAEA,gBAAgB,EAAE,CAAC,GAAG,GAAG,EAAEU,YAAYZ,IAAI,CAAC,CAAC,GACrEC;YACJ,MAAMa,iBAAiBpB,iBAAiB;gBACtCQ;gBACAJ;YACF,EAAE,CAACc,YAAYT,IAAI,CAAC;YAEpB,IAAIW,gBAAgB;gBAClB,MAAMC,cAAcD,eAAe;oBACjC,GAAGF,WAAW;oBACdZ,MAAMa;gBACR;gBAEA,IAAIG,MAAMC,OAAO,CAACF,cAAc;oBAC9B,OAAO;2BAAIJ;2BAAiBI;qBAAY;gBAC1C;gBAEA,OAAO;uBACFJ;oBACH;wBACER,MAAMY;wBACNG,KAAKL;oBACP;iBACD;YACH;QACF;QAEA,OAAOF;IACT,GAAG,EAAE;IAEL,OAAOF;AACT;AAEA,eAAed,4BAA2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withNullableType.d.ts","sourceRoot":"","sources":["../../src/schema/withNullableType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"withNullableType.d.ts","sourceRoot":"","sources":["../../src/schema/withNullableType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAIvD,QAAA,MAAM,gBAAgB,UACb,kBAAkB,QACnB,WAAW,8BAEhB,WAkBF,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/withNullableType.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\
|
|
1
|
+
{"version":3,"sources":["../../src/schema/withNullableType.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\nimport type { FieldAffectingData } from 'payload/types'\n\nimport { GraphQLNonNull } from 'graphql'\n\nconst withNullableType = (\n field: FieldAffectingData,\n type: GraphQLType,\n forceNullable = false,\n): GraphQLType => {\n const hasReadAccessControl = field.access && field.access.read\n const condition = field.admin && field.admin.condition\n const isTimestamp = field.name === 'createdAt' || field.name === 'updatedAt'\n\n if (\n !forceNullable &&\n 'required' in field &&\n field.required &&\n !field.localized &&\n !condition &&\n !hasReadAccessControl &&\n !isTimestamp\n ) {\n return new GraphQLNonNull(type)\n }\n\n return type\n}\n\nexport default withNullableType\n"],"names":["GraphQLNonNull","withNullableType","field","type","forceNullable","hasReadAccessControl","access","read","condition","admin","isTimestamp","name","required","localized"],"mappings":"AAGA,SAASA,cAAc,QAAQ,UAAS;AAExC,MAAMC,mBAAmB,CACvBC,OACAC,MACAC,gBAAgB,KAAK;IAErB,MAAMC,uBAAuBH,MAAMI,MAAM,IAAIJ,MAAMI,MAAM,CAACC,IAAI;IAC9D,MAAMC,YAAYN,MAAMO,KAAK,IAAIP,MAAMO,KAAK,CAACD,SAAS;IACtD,MAAME,cAAcR,MAAMS,IAAI,KAAK,eAAeT,MAAMS,IAAI,KAAK;IAEjE,IACE,CAACP,iBACD,cAAcF,SACdA,MAAMU,QAAQ,IACd,CAACV,MAAMW,SAAS,IAChB,CAACL,aACD,CAACH,wBACD,CAACK,aACD;QACA,OAAO,IAAIV,eAAeG;IAC5B;IAEA,OAAOA;AACT;AAEA,eAAeF,iBAAgB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GraphQLInputObjectType } from 'graphql';
|
|
2
1
|
import type { FieldAffectingData } from 'payload/types';
|
|
2
|
+
import { GraphQLInputObjectType } from 'graphql';
|
|
3
3
|
/**
|
|
4
4
|
* In GraphQL, you can use "where" as an argument to filter a collection. Example:
|
|
5
5
|
* { Posts(where: { title: { equals: "Hello" } }) { text } }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withOperators.d.ts","sourceRoot":"","sources":["../../src/schema/withOperators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withOperators.d.ts","sourceRoot":"","sources":["../../src/schema/withOperators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAwC,MAAM,eAAe,CAAA;AAE7F,OAAO,EAIL,sBAAsB,EAIvB,MAAM,SAAS,CAAA;AA8OhB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,UACjB,kBAAkB,cACb,MAAM,KACjB,sBA+CF,CAAA"}
|
|
@@ -8,11 +8,11 @@ import operators from './operators.js';
|
|
|
8
8
|
const GeoJSONObject = new GraphQLInputObjectType({
|
|
9
9
|
name: 'GeoJSONObject',
|
|
10
10
|
fields: {
|
|
11
|
-
coordinates: {
|
|
12
|
-
type: GraphQLJSON
|
|
13
|
-
},
|
|
14
11
|
type: {
|
|
15
12
|
type: GraphQLString
|
|
13
|
+
},
|
|
14
|
+
coordinates: {
|
|
15
|
+
type: GraphQLJSON
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/withOperators.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLString,\n} from 'graphql'\nimport { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars'\nimport { GraphQLJSON } from 'graphql-type-json'\n\nimport type { FieldAffectingData, NumberField, RadioField, SelectField } from 'payload/types'\n\nimport { optionIsObject } from 'payload/types'\nimport combineParentName from '../utilities/combineParentName.js'\nimport formatName from '../utilities/formatName.js'\nimport operators from './operators.js'\n\ntype staticTypes =\n | 'checkbox'\n | 'code'\n | 'date'\n | 'email'\n | 'json'\n | 'number'\n | 'point'\n | 'relationship'\n | 'richText'\n | 'text'\n | 'textarea'\n | 'upload'\n\ntype dynamicTypes = 'radio' | 'select'\n\nconst GeoJSONObject = new GraphQLInputObjectType({\n name: 'GeoJSONObject',\n fields: {\n coordinates: {\n type: GraphQLJSON,\n },\n type: { type: GraphQLString },\n },\n})\n\ntype DefaultsType = {\n [key in staticTypes]: {\n operators: {\n name: string\n type: ((field: FieldAffectingData, parentName: string) => GraphQLType) | GraphQLType\n }[]\n }\n} & {\n [key in dynamicTypes]: {\n operators: {\n name: string\n type: (field: FieldAffectingData, parentName: string) => GraphQLType\n }[]\n }\n}\n\nconst defaults: DefaultsType = {\n checkbox: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLBoolean,\n })),\n ],\n },\n code: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n date: {\n operators: [\n ...[...operators.equality, ...operators.comparison, 'like'].map((operator) => ({\n name: operator,\n type: DateTimeResolver,\n })),\n ],\n },\n email: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: EmailAddressResolver,\n })),\n ],\n },\n json: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.geojson].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n number: {\n operators: [\n ...[...operators.equality, ...operators.comparison].map((operator) => ({\n name: operator,\n type: (field: NumberField): GraphQLType => {\n return field?.name === 'id' ? GraphQLInt : GraphQLFloat\n },\n })),\n ],\n },\n point: {\n operators: [\n ...[...operators.equality, ...operators.comparison, ...operators.geo].map((operator) => ({\n name: operator,\n type: new GraphQLList(GraphQLFloat),\n })),\n ...operators.geojson.map((operator) => ({\n name: operator,\n /**\n * @example:\n * within: {\n * type: \"Polygon\",\n * coordinates: [[\n * [0.0, 0.0],\n * [1.0, 1.0],\n * [1.0, 0.0],\n * [0.0, 0.0],\n * ]],\n * }\n * @example\n * intersects: {\n * type: \"Point\",\n * coordinates: [ 0.5, 0.5 ]\n * }\n */\n type: GeoJSONObject,\n })),\n ],\n },\n radio: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: (field: RadioField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n relationship: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n richText: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n select: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: (field: SelectField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n text: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n textarea: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n upload: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n // array: n/a\n // group: n/a\n // row: n/a\n // collapsible: n/a\n // tabs: n/a\n}\n\nconst listOperators = ['in', 'not_in', 'all']\n\nconst gqlTypeCache: Record<string, GraphQLType> = {}\n\n/**\n * In GraphQL, you can use \"where\" as an argument to filter a collection. Example:\n * { Posts(where: { title: { equals: \"Hello\" } }) { text } }\n * This function defines the operators for a field's condition in the \"where\" argument of the collection (it thus gets called for every field).\n * For example, in the example above, it would control that\n * - \"equals\" is a valid operator for the \"title\" field\n * - the accepted type of the \"equals\" argument has to be a string.\n *\n * @param field the field for which their valid operators inside a \"where\" argument is being defined\n * @param parentName the name of the parent field (if any)\n * @returns all the operators (including their types) which can be used as a condition for a given field inside a where\n */\nexport const withOperators = (\n field: FieldAffectingData,\n parentName: string,\n): GraphQLInputObjectType => {\n if (!defaults?.[field.type]) throw new Error(`Error: ${field.type} has no defaults configured.`)\n\n const name = `${combineParentName(parentName, field.name)}_operator`\n\n // Get the default operators for the field type which are hard-coded above\n const fieldOperators = [...defaults[field.type].operators]\n\n if (!('required' in field) || !field.required) {\n fieldOperators.push({\n name: 'exists',\n type: fieldOperators[0].type,\n })\n }\n\n return new GraphQLInputObjectType({\n name,\n fields: fieldOperators.reduce((objectTypeFields, operator) => {\n // Get the type of the operator. It can be either static, or dynamic (=> a function)\n let gqlType: GraphQLType =\n typeof operator.type === 'function' ? operator.type(field, parentName) : operator.type\n\n // GraphQL does not allow types with duplicate names, so we use this cache to avoid that.\n // Without this, select and radio fields would have the same name, and GraphQL would throw an error\n // This usually only happens if a custom type is returned from the operator.type function\n if (typeof operator.type === 'function' && 'name' in gqlType) {\n if (gqlTypeCache[gqlType.name]) {\n gqlType = gqlTypeCache[gqlType.name]\n } else {\n gqlTypeCache[gqlType.name] = gqlType\n }\n }\n\n if (listOperators.includes(operator.name)) {\n gqlType = new GraphQLList(gqlType)\n } else if (operator.name === 'exists') {\n gqlType = GraphQLBoolean\n }\n\n return {\n ...objectTypeFields,\n [operator.name]: {\n type: gqlType,\n },\n }\n }, {}),\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLString","DateTimeResolver","EmailAddressResolver","GraphQLJSON","optionIsObject","combineParentName","formatName","operators","GeoJSONObject","name","fields","coordinates","type","defaults","checkbox","equality","map","operator","code","partial","date","comparison","email","contains","json","geojson","number","field","point","geo","radio","parentName","values","options","reduce","option","value","relationship","richText","select","text","textarea","upload","listOperators","gqlTypeCache","withOperators","Error","fieldOperators","required","push","objectTypeFields","gqlType","includes"],"mappings":"AAEA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,aAAa,QACR,UAAS;AAChB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,kBAAiB;AACxE,SAASC,WAAW,QAAQ,oBAAmB;AAI/C,SAASC,cAAc,QAAQ,gBAAe;AAC9C,OAAOC,uBAAuB,oCAAmC;AACjE,OAAOC,gBAAgB,6BAA4B;AACnD,OAAOC,eAAe,iBAAgB;AAkBtC,MAAMC,gBAAgB,IAAIX,uBAAuB;IAC/CY,MAAM;IACNC,QAAQ;QACNC,aAAa;YACXC,MAAMT;QACR;QACAS,MAAM;YAAEA,MAAMZ;QAAc;IAC9B;AACF;AAkBA,MAAMa,WAAyB;IAC7BC,UAAU;QACRP,WAAW;eACNA,UAAUQ,QAAQ,CAACC,GAAG,CAAC,CAACC,WAAc,CAAA;oBACvCR,MAAMQ;oBACNL,MAAMlB;gBACR,CAAA;SACD;IACH;IACAwB,MAAM;QACJX,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUY,OAAO;aAAC,CAACH,GAAG,CAAC,CAACC,WAAc,CAAA;oBAClER,MAAMQ;oBACNL,MAAMZ;gBACR,CAAA;SACD;IACH;IACAoB,MAAM;QACJb,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUc,UAAU;gBAAE;aAAO,CAACL,GAAG,CAAC,CAACC,WAAc,CAAA;oBAC7ER,MAAMQ;oBACNL,MAAMX;gBACR,CAAA;SACD;IACH;IACAqB,OAAO;QACLf,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR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QACAC,QAAQqC,eAAeb,MAAM,CAAC,CAACgB,kBAAkBjC;YAC/C,oFAAoF;YACpF,IAAIkC,UACF,OAAOlC,SAASL,IAAI,KAAK,aAAaK,SAASL,IAAI,CAACe,OAAOI,cAAcd,SAASL,IAAI;YAExF,yFAAyF;YACzF,mGAAmG;YACnG,yFAAyF;YACzF,IAAI,OAAOK,SAASL,IAAI,KAAK,cAAc,UAAUuC,SAAS;gBAC5D,IAAIP,YAAY,CAACO,QAAQ1C,IAAI,CAAC,EAAE;oBAC9B0C,UAAUP,YAAY,CAACO,QAAQ1C,IAAI,CAAC;gBACtC,OAAO;oBACLmC,YAAY,CAACO,QAAQ1C,IAAI,CAAC,GAAG0C;gBAC/B;YACF;YAEA,IAAIR,cAAcS,QAAQ,CAACnC,SAASR,IAAI,GAAG;gBACzC0C,UAAU,IAAIpD,YAAYoD;YAC5B,OAAO,IAAIlC,SAASR,IAAI,KAAK,UAAU;gBACrC0C,UAAUzD;YACZ;YAEA,OAAO;gBACL,GAAGwD,gBAAgB;gBACnB,CAACjC,SAASR,IAAI,CAAC,EAAE;oBACfG,MAAMuC;gBACR;YACF;QACF,GAAG,CAAC;IACN;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/schema/withOperators.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\nimport type { FieldAffectingData, NumberField, RadioField, SelectField } from 'payload/types'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLString,\n} from 'graphql'\nimport { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars'\nimport { GraphQLJSON } from 'graphql-type-json'\nimport { optionIsObject } from 'payload/types'\n\nimport combineParentName from '../utilities/combineParentName.js'\nimport formatName from '../utilities/formatName.js'\nimport operators from './operators.js'\n\ntype staticTypes =\n | 'checkbox'\n | 'code'\n | 'date'\n | 'email'\n | 'json'\n | 'number'\n | 'point'\n | 'relationship'\n | 'richText'\n | 'text'\n | 'textarea'\n | 'upload'\n\ntype dynamicTypes = 'radio' | 'select'\n\nconst GeoJSONObject = new GraphQLInputObjectType({\n name: 'GeoJSONObject',\n fields: {\n type: { type: GraphQLString },\n coordinates: {\n type: GraphQLJSON,\n },\n },\n})\n\ntype DefaultsType = {\n [key in staticTypes]: {\n operators: {\n name: string\n type: ((field: FieldAffectingData, parentName: string) => GraphQLType) | GraphQLType\n }[]\n }\n} & {\n [key in dynamicTypes]: {\n operators: {\n name: string\n type: (field: FieldAffectingData, parentName: string) => GraphQLType\n }[]\n }\n}\n\nconst defaults: DefaultsType = {\n checkbox: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLBoolean,\n })),\n ],\n },\n code: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n date: {\n operators: [\n ...[...operators.equality, ...operators.comparison, 'like'].map((operator) => ({\n name: operator,\n type: DateTimeResolver,\n })),\n ],\n },\n email: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: EmailAddressResolver,\n })),\n ],\n },\n json: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.geojson].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n number: {\n operators: [\n ...[...operators.equality, ...operators.comparison].map((operator) => ({\n name: operator,\n type: (field: NumberField): GraphQLType => {\n return field?.name === 'id' ? GraphQLInt : GraphQLFloat\n },\n })),\n ],\n },\n point: {\n operators: [\n ...[...operators.equality, ...operators.comparison, ...operators.geo].map((operator) => ({\n name: operator,\n type: new GraphQLList(GraphQLFloat),\n })),\n ...operators.geojson.map((operator) => ({\n name: operator,\n /**\n * @example:\n * within: {\n * type: \"Polygon\",\n * coordinates: [[\n * [0.0, 0.0],\n * [1.0, 1.0],\n * [1.0, 0.0],\n * [0.0, 0.0],\n * ]],\n * }\n * @example\n * intersects: {\n * type: \"Point\",\n * coordinates: [ 0.5, 0.5 ]\n * }\n */\n type: GeoJSONObject,\n })),\n ],\n },\n radio: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: (field: RadioField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n relationship: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n richText: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n select: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: (field: SelectField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n text: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n textarea: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n upload: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n // array: n/a\n // group: n/a\n // row: n/a\n // collapsible: n/a\n // tabs: n/a\n}\n\nconst listOperators = ['in', 'not_in', 'all']\n\nconst gqlTypeCache: Record<string, GraphQLType> = {}\n\n/**\n * In GraphQL, you can use \"where\" as an argument to filter a collection. Example:\n * { Posts(where: { title: { equals: \"Hello\" } }) { text } }\n * This function defines the operators for a field's condition in the \"where\" argument of the collection (it thus gets called for every field).\n * For example, in the example above, it would control that\n * - \"equals\" is a valid operator for the \"title\" field\n * - the accepted type of the \"equals\" argument has to be a string.\n *\n * @param field the field for which their valid operators inside a \"where\" argument is being defined\n * @param parentName the name of the parent field (if any)\n * @returns all the operators (including their types) which can be used as a condition for a given field inside a where\n */\nexport const withOperators = (\n field: FieldAffectingData,\n parentName: string,\n): GraphQLInputObjectType => {\n if (!defaults?.[field.type]) throw new Error(`Error: ${field.type} has no defaults configured.`)\n\n const name = `${combineParentName(parentName, field.name)}_operator`\n\n // Get the default operators for the field type which are hard-coded above\n const fieldOperators = [...defaults[field.type].operators]\n\n if (!('required' in field) || !field.required) {\n fieldOperators.push({\n name: 'exists',\n type: fieldOperators[0].type,\n })\n }\n\n return new GraphQLInputObjectType({\n name,\n fields: fieldOperators.reduce((objectTypeFields, operator) => {\n // Get the type of the operator. It can be either static, or dynamic (=> a function)\n let gqlType: GraphQLType =\n typeof operator.type === 'function' ? operator.type(field, parentName) : operator.type\n\n // GraphQL does not allow types with duplicate names, so we use this cache to avoid that.\n // Without this, select and radio fields would have the same name, and GraphQL would throw an error\n // This usually only happens if a custom type is returned from the operator.type function\n if (typeof operator.type === 'function' && 'name' in gqlType) {\n if (gqlTypeCache[gqlType.name]) {\n gqlType = gqlTypeCache[gqlType.name]\n } else {\n gqlTypeCache[gqlType.name] = gqlType\n }\n }\n\n if (listOperators.includes(operator.name)) {\n gqlType = new GraphQLList(gqlType)\n } else if (operator.name === 'exists') {\n gqlType = GraphQLBoolean\n }\n\n return {\n ...objectTypeFields,\n [operator.name]: {\n type: gqlType,\n },\n }\n }, {}),\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLString","DateTimeResolver","EmailAddressResolver","GraphQLJSON","optionIsObject","combineParentName","formatName","operators","GeoJSONObject","name","fields","type","coordinates","defaults","checkbox","equality","map","operator","code","partial","date","comparison","email","contains","json","geojson","number","field","point","geo","radio","parentName","values","options","reduce","option","value","relationship","richText","select","text","textarea","upload","listOperators","gqlTypeCache","withOperators","Error","fieldOperators","required","push","objectTypeFields","gqlType","includes"],"mappings":"AAGA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,aAAa,QACR,UAAS;AAChB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,kBAAiB;AACxE,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SAASC,cAAc,QAAQ,gBAAe;AAE9C,OAAOC,uBAAuB,oCAAmC;AACjE,OAAOC,gBAAgB,6BAA4B;AACnD,OAAOC,eAAe,iBAAgB;AAkBtC,MAAMC,gBAAgB,IAAIX,uBAAuB;IAC/CY,MAAM;IACNC,QAAQ;QACNC,MAAM;YAAEA,MAAMX;QAAc;QAC5BY,aAAa;YACXD,MAAMR;QACR;IACF;AACF;AAkBA,MAAMU,WAAyB;IAC7BC,UAAU;QACRP,WAAW;eACNA,UAAUQ,QAAQ,CAACC,GAAG,CAAC,CAACC,WAAc,CAAA;oBACvCR,MAAMQ;oBACNN,MAAMjB;gBACR,CAAA;SACD;IACH;IACAwB,MAAM;QACJX,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUY,OAAO;aAAC,CAACH,GAAG,CAAC,CAACC,WAAc,CAAA;oBAClER,MAAMQ;oBACNN,MAAMX;gBACR,CAAA;SACD;IACH;IACAoB,MAAM;QACJb,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUc,UAAU;gBAAE;aAAO,CAACL,GAAG,CAAC,CAACC,WAAc,CAAA;oBAC7ER,MAAMQ;oBACNN,MAAMV;gBACR,CAAA;SACD;IACH;IACAqB,OAAO;QACLf,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUY,OAA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QqC,eAAeb,MAAM,CAAC,CAACgB,kBAAkBjC;YAC/C,oFAAoF;YACpF,IAAIkC,UACF,OAAOlC,SAASN,IAAI,KAAK,aAAaM,SAASN,IAAI,CAACgB,OAAOI,cAAcd,SAASN,IAAI;YAExF,yFAAyF;YACzF,mGAAmG;YACnG,yFAAyF;YACzF,IAAI,OAAOM,SAASN,IAAI,KAAK,cAAc,UAAUwC,SAAS;gBAC5D,IAAIP,YAAY,CAACO,QAAQ1C,IAAI,CAAC,EAAE;oBAC9B0C,UAAUP,YAAY,CAACO,QAAQ1C,IAAI,CAAC;gBACtC,OAAO;oBACLmC,YAAY,CAACO,QAAQ1C,IAAI,CAAC,GAAG0C;gBAC/B;YACF;YAEA,IAAIR,cAAcS,QAAQ,CAACnC,SAASR,IAAI,GAAG;gBACzC0C,UAAU,IAAIpD,YAAYoD;YAC5B,OAAO,IAAIlC,SAASR,IAAI,KAAK,UAAU;gBACrC0C,UAAUzD;YACZ;YAEA,OAAO;gBACL,GAAGwD,gBAAgB;gBACnB,CAACjC,SAASR,IAAI,CAAC,EAAE;oBACfE,MAAMwC;gBACR;YACF;QACF,GAAG,CAAC;IACN;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapCustomResolver.d.ts","sourceRoot":"","sources":["../../src/utilities/wrapCustomResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAwB,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"wrapCustomResolver.d.ts","sourceRoot":"","sources":["../../src/utilities/wrapCustomResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAwB,MAAM,4BAA4B,CAAA;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAInD,KAAK,cAAc,GAAG;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA;AAe7C,wBAAgB,gBAAgB,CAAC,OAAO,EACtC,MAAM,EAAE,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,GAC1D,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAOrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/wrapCustomResolver.ts"],"sourcesContent":["import type { ObjMap } from 'graphql/jsutils/ObjMap.js'\nimport type { GraphQLFieldConfig, GraphQLFieldResolver } from 'graphql/type/definition.js'\
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/wrapCustomResolver.ts"],"sourcesContent":["import type { ObjMap } from 'graphql/jsutils/ObjMap.js'\nimport type { GraphQLFieldConfig, GraphQLFieldResolver } from 'graphql/type/definition.js'\nimport type { PayloadRequest } from 'payload/types'\n\nimport { isolateObjectProperty } from 'payload/utilities'\n\ntype PayloadContext = { req: PayloadRequest }\n\nfunction wrapCustomResolver<TSource, TArgs, TResult>(\n resolver: GraphQLFieldResolver<TSource, PayloadContext, TArgs, TResult>,\n): GraphQLFieldResolver<TSource, PayloadContext, TArgs, TResult> {\n return (source, args, context, info) => {\n return resolver(\n source,\n args,\n { ...context, req: isolateObjectProperty(context.req, 'transactionID') },\n info,\n )\n }\n}\n\nexport function wrapCustomFields<TSource>(\n fields: ObjMap<GraphQLFieldConfig<TSource, PayloadContext>>,\n): ObjMap<GraphQLFieldConfig<TSource, PayloadContext>> {\n for (const key in fields) {\n if (fields[key].resolve) {\n fields[key].resolve = wrapCustomResolver(fields[key].resolve)\n }\n }\n return fields\n}\n"],"names":["isolateObjectProperty","wrapCustomResolver","resolver","source","args","context","info","req","wrapCustomFields","fields","key","resolve"],"mappings":"AAIA,SAASA,qBAAqB,QAAQ,oBAAmB;AAIzD,SAASC,mBACPC,QAAuE;IAEvE,OAAO,CAACC,QAAQC,MAAMC,SAASC;QAC7B,OAAOJ,SACLC,QACAC,MACA;YAAE,GAAGC,OAAO;YAAEE,KAAKP,sBAAsBK,QAAQE,GAAG,EAAE;QAAiB,GACvED;IAEJ;AACF;AAEA,OAAO,SAASE,iBACdC,MAA2D;IAE3D,IAAK,MAAMC,OAAOD,OAAQ;QACxB,IAAIA,MAAM,CAACC,IAAI,CAACC,OAAO,EAAE;YACvBF,MAAM,CAACC,IAAI,CAACC,OAAO,GAAGV,mBAAmBQ,MAAM,CAACC,IAAI,CAACC,OAAO;QAC9D;IACF;IACA,OAAOF;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/graphql",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.49",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
+
"@types/pluralize": "^0.0.33",
|
|
15
16
|
"ts-essentials": "7.0.3",
|
|
16
17
|
"@payloadcms/eslint-config": "1.1.1",
|
|
17
|
-
"payload": "3.0.0-alpha.
|
|
18
|
+
"payload": "3.0.0-alpha.49"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"graphql": "16.8.1",
|
|
@@ -26,10 +27,7 @@
|
|
|
26
27
|
"pluralize": "8.0.0"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
|
-
"payload": "3.0.0-alpha.
|
|
30
|
-
},
|
|
31
|
-
"publishConfig": {
|
|
32
|
-
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
"payload": "3.0.0-alpha.49"
|
|
33
31
|
},
|
|
34
32
|
"files": [
|
|
35
33
|
"dist"
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import type { OperationArgs } from 'graphql-http'
|
|
3
|
+
import type { GraphQLInfo } from 'payload/config'
|
|
4
|
+
import type { SanitizedConfig } from 'payload/types'
|
|
4
5
|
|
|
6
|
+
import * as GraphQL from 'graphql'
|
|
5
7
|
import {
|
|
8
|
+
createComplexityRule,
|
|
6
9
|
fieldExtensionsEstimator,
|
|
7
10
|
simpleEstimator,
|
|
8
|
-
createComplexityRule,
|
|
9
11
|
} from 'graphql-query-complexity'
|
|
10
12
|
|
|
11
|
-
import type { GraphQLInfo } from 'payload/config'
|
|
12
|
-
import type { SanitizedConfig } from 'payload/types'
|
|
13
13
|
import accessResolver from './resolvers/auth/access.js'
|
|
14
|
-
import initCollections from './schema/initCollections.js'
|
|
15
|
-
import initGlobals from './schema/initGlobals.js'
|
|
16
14
|
import buildFallbackLocaleInputType from './schema/buildFallbackLocaleInputType.js'
|
|
17
15
|
import buildLocaleInputType from './schema/buildLocaleInputType.js'
|
|
18
16
|
import buildPoliciesType from './schema/buildPoliciesType.js'
|
|
17
|
+
import initCollections from './schema/initCollections.js'
|
|
18
|
+
import initGlobals from './schema/initGlobals.js'
|
|
19
19
|
import { wrapCustomFields } from './utilities/wrapCustomResolver.js'
|
|
20
20
|
|
|
21
21
|
export async function configToSchema(config: SanitizedConfig): Promise<{
|
|
@@ -34,24 +34,24 @@ export async function configToSchema(config: SanitizedConfig): Promise<{
|
|
|
34
34
|
config: config.globals,
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
blockTypes: {},
|
|
42
|
-
groupTypes: {},
|
|
43
|
-
tabTypes: {},
|
|
37
|
+
const graphqlResult: GraphQLInfo = {
|
|
38
|
+
Mutation: {
|
|
39
|
+
name: 'Mutation',
|
|
40
|
+
fields: {},
|
|
44
41
|
},
|
|
45
42
|
Query: {
|
|
46
43
|
name: 'Query',
|
|
47
44
|
fields: {},
|
|
48
45
|
},
|
|
49
|
-
Mutation: {
|
|
50
|
-
name: 'Mutation',
|
|
51
|
-
fields: {},
|
|
52
|
-
},
|
|
53
46
|
collections,
|
|
54
47
|
globals,
|
|
48
|
+
types: {
|
|
49
|
+
arrayTypes: {},
|
|
50
|
+
blockInputTypes: {},
|
|
51
|
+
blockTypes: {},
|
|
52
|
+
groupTypes: {},
|
|
53
|
+
tabTypes: {},
|
|
54
|
+
},
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
if (config.localization) {
|
|
@@ -65,8 +65,8 @@ export async function configToSchema(config: SanitizedConfig): Promise<{
|
|
|
65
65
|
initGlobals({ config, graphqlResult })
|
|
66
66
|
|
|
67
67
|
graphqlResult.Query.fields['Access'] = {
|
|
68
|
-
resolve: accessResolver(config),
|
|
69
68
|
type: buildPoliciesType(config),
|
|
69
|
+
resolve: accessResolver(config),
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (typeof config.graphQL.queries === 'function') {
|