@payloadcms/graphql 3.0.0-beta.3 → 3.0.0-beta.30
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 +2 -2
- 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 +64 -0
- package/dist/packages/graphql-type-json/index.js.map +1 -0
- package/dist/resolvers/collections/count.d.ts +13 -0
- package/dist/resolvers/collections/count.d.ts.map +1 -0
- package/dist/resolvers/collections/count.js +23 -0
- package/dist/resolvers/collections/count.js.map +1 -0
- package/dist/resolvers/collections/create.d.ts +2 -2
- 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 +5 -3
- package/dist/resolvers/collections/delete.d.ts.map +1 -1
- package/dist/resolvers/collections/delete.js +7 -4
- package/dist/resolvers/collections/delete.js.map +1 -1
- package/dist/resolvers/collections/docAccess.d.ts +2 -2
- package/dist/resolvers/collections/docAccess.d.ts.map +1 -1
- package/dist/resolvers/collections/docAccess.js.map +1 -1
- package/dist/resolvers/collections/duplicate.d.ts +2 -2
- package/dist/resolvers/collections/duplicate.d.ts.map +1 -1
- package/dist/resolvers/collections/duplicate.js +1 -0
- package/dist/resolvers/collections/duplicate.js.map +1 -1
- package/dist/resolvers/collections/find.d.ts +3 -3
- package/dist/resolvers/collections/find.d.ts.map +1 -1
- package/dist/resolvers/collections/find.js +5 -1
- package/dist/resolvers/collections/find.js.map +1 -1
- package/dist/resolvers/collections/findByID.d.ts +3 -3
- package/dist/resolvers/collections/findByID.d.ts.map +1 -1
- package/dist/resolvers/collections/findByID.js +5 -1
- package/dist/resolvers/collections/findByID.js.map +1 -1
- package/dist/resolvers/collections/findVersionByID.d.ts +3 -4
- package/dist/resolvers/collections/findVersionByID.d.ts.map +1 -1
- package/dist/resolvers/collections/findVersionByID.js +2 -2
- package/dist/resolvers/collections/findVersionByID.js.map +1 -1
- package/dist/resolvers/collections/findVersions.d.ts +4 -3
- package/dist/resolvers/collections/findVersions.d.ts.map +1 -1
- package/dist/resolvers/collections/findVersions.js +7 -4
- package/dist/resolvers/collections/findVersions.js.map +1 -1
- package/dist/resolvers/collections/restoreVersion.d.ts +2 -2
- 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 +4 -3
- package/dist/resolvers/collections/update.d.ts.map +1 -1
- package/dist/resolvers/collections/update.js +7 -4
- package/dist/resolvers/collections/update.js.map +1 -1
- package/dist/resolvers/globals/docAccess.d.ts +2 -2
- package/dist/resolvers/globals/docAccess.d.ts.map +1 -1
- package/dist/resolvers/globals/docAccess.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.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.map +1 -1
- package/dist/resolvers/globals/restoreVersion.d.ts +2 -2
- 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 +2 -2
- 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/buildMutationInputType.d.ts.map +1 -1
- package/dist/schema/buildMutationInputType.js +2 -2
- package/dist/schema/buildMutationInputType.js.map +1 -1
- package/dist/schema/buildObjectType.d.ts.map +1 -1
- package/dist/schema/buildObjectType.js +59 -37
- package/dist/schema/buildObjectType.js.map +1 -1
- package/dist/schema/buildPoliciesType.js +1 -1
- package/dist/schema/buildPoliciesType.js.map +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.d.ts.map +1 -1
- package/dist/schema/fieldToWhereInputSchemaMap.js +1 -2
- package/dist/schema/fieldToWhereInputSchemaMap.js.map +1 -1
- package/dist/schema/initCollections.d.ts.map +1 -1
- package/dist/schema/initCollections.js +31 -6
- package/dist/schema/initCollections.js.map +1 -1
- package/dist/schema/withOperators.js +1 -1
- package/dist/schema/withOperators.js.map +1 -1
- package/dist/utilities/wrapCustomResolver.d.ts +2 -2
- package/dist/utilities/wrapCustomResolver.d.ts.map +1 -1
- package/dist/utilities/wrapCustomResolver.js.map +1 -1
- package/package.json +16 -19
- package/src/index.ts +0 -126
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restoreVersion.d.ts","sourceRoot":"","sources":["../../../src/resolvers/collections/restoreVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"restoreVersion.d.ts","sourceRoot":"","sources":["../../../src/resolvers/collections/restoreVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAO/C,MAAM,MAAM,QAAQ,GAAG,CACrB,CAAC,EAAE,OAAO,EACV,IAAI,EAAE;IACJ,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CACpB,EACD,OAAO,EAAE;IACP,GAAG,EAAE,sBAAsB,CAAA;CAC5B,KACE,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,CAc/E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/collections/restoreVersion.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/collections/restoreVersion.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\nimport type { Collection } from 'payload/types'\n\nimport { restoreVersionOperation } from 'payload/operations'\nimport { isolateObjectProperty } from 'payload/utilities'\n\nimport type { Context } from '../types.js'\n\nexport type Resolver = (\n _: unknown,\n args: {\n id: number | string\n },\n context: {\n req: PayloadRequestWithData\n },\n) => Promise<Document>\n\nexport default function restoreVersionResolver(collection: Collection): Resolver {\n async function resolver(_, args, context: Context) {\n const options = {\n id: args.id,\n collection,\n depth: 0,\n req: isolateObjectProperty(context.req, 'transactionID'),\n }\n\n const result = await restoreVersionOperation(options)\n return result\n }\n\n return resolver\n}\n"],"names":["restoreVersionOperation","isolateObjectProperty","restoreVersionResolver","collection","resolver","_","args","context","options","id","depth","req","result"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAGA,SAASA,uBAAuB,QAAQ,qBAAoB;AAC5D,SAASC,qBAAqB,QAAQ,oBAAmB;AAczD,eAAe,SAASC,uBAAuBC,UAAsB;IACnE,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QAC/C,MAAMC,UAAU;YACdC,IAAIH,KAAKG,EAAE;YACXN;YACAO,OAAO;YACPC,KAAKV,sBAAsBM,QAAQI,GAAG,EAAE;QAC1C;QAEA,MAAMC,SAAS,MAAMZ,wBAAwBQ;QAC7C,OAAOI;IACT;IAEA,OAAOR;AACT"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { GeneratedTypes } from 'payload';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PayloadRequestWithData } from 'payload/types';
|
|
3
3
|
import type { Collection } from 'payload/types';
|
|
4
4
|
export type Resolver<TSlug extends keyof GeneratedTypes['collections']> = (_: unknown, args: {
|
|
5
5
|
autosave: boolean;
|
|
6
6
|
data: GeneratedTypes['collections'][TSlug];
|
|
7
7
|
draft: boolean;
|
|
8
|
+
fallbackLocale?: string;
|
|
8
9
|
id: number | string;
|
|
9
10
|
locale?: string;
|
|
10
11
|
}, context: {
|
|
11
|
-
req:
|
|
12
|
+
req: PayloadRequestWithData;
|
|
12
13
|
}) => Promise<GeneratedTypes['collections'][TSlug]>;
|
|
13
|
-
export
|
|
14
|
+
export declare function updateResolver<TSlug extends keyof GeneratedTypes['collections']>(collection: Collection): Resolver<TSlug>;
|
|
14
15
|
//# sourceMappingURL=update.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/resolvers/collections/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/resolvers/collections/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAO/C,MAAM,MAAM,QAAQ,CAAC,KAAK,SAAS,MAAM,cAAc,CAAC,aAAa,CAAC,IAAI,CACxE,CAAC,EAAE,OAAO,EACV,IAAI,EAAE;IACJ,QAAQ,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,CAAA;IAC1C,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,EACD,OAAO,EAAE;IACP,GAAG,EAAE,sBAAsB,CAAA;CAC5B,KACE,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;AAElD,wBAAgB,cAAc,CAAC,KAAK,SAAS,MAAM,cAAc,CAAC,aAAa,CAAC,EAC9E,UAAU,EAAE,UAAU,GACrB,QAAQ,CAAC,KAAK,CAAC,CAmCjB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { updateByIDOperation } from 'payload/operations';
|
|
2
2
|
import { isolateObjectProperty } from 'payload/utilities';
|
|
3
|
-
export
|
|
4
|
-
async function resolver(_, args, context) {
|
|
3
|
+
export function updateResolver(collection) {
|
|
4
|
+
return async function resolver(_, args, context) {
|
|
5
5
|
let { req } = context;
|
|
6
6
|
const locale = req.locale;
|
|
7
7
|
const fallbackLocale = req.fallbackLocale;
|
|
@@ -9,6 +9,10 @@ export default function updateResolver(collection) {
|
|
|
9
9
|
req = isolateObjectProperty(req, 'fallbackLocale');
|
|
10
10
|
req.locale = args.locale || locale;
|
|
11
11
|
req.fallbackLocale = args.fallbackLocale || fallbackLocale;
|
|
12
|
+
if (!req.query) req.query = {};
|
|
13
|
+
const draft = args.draft ?? req.query?.draft === 'false' ? false : req.query?.draft === 'true' ? true : undefined;
|
|
14
|
+
if (typeof draft === 'boolean') req.query.draft = String(draft);
|
|
15
|
+
context.req = req;
|
|
12
16
|
const options = {
|
|
13
17
|
id: args.id,
|
|
14
18
|
autosave: args.autosave,
|
|
@@ -20,8 +24,7 @@ export default function updateResolver(collection) {
|
|
|
20
24
|
};
|
|
21
25
|
const result = await updateByIDOperation(options);
|
|
22
26
|
return result;
|
|
23
|
-
}
|
|
24
|
-
return resolver;
|
|
27
|
+
};
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
//# sourceMappingURL=update.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/collections/update.ts"],"sourcesContent":["import type { GeneratedTypes } from 'payload'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/collections/update.ts"],"sourcesContent":["import type { GeneratedTypes } from 'payload'\nimport type { PayloadRequestWithData } from 'payload/types'\nimport type { Collection } from 'payload/types'\n\nimport { updateByIDOperation } from 'payload/operations'\nimport { isolateObjectProperty } from 'payload/utilities'\n\nimport type { Context } from '../types.js'\n\nexport type Resolver<TSlug extends keyof GeneratedTypes['collections']> = (\n _: unknown,\n args: {\n autosave: boolean\n data: GeneratedTypes['collections'][TSlug]\n draft: boolean\n fallbackLocale?: string\n id: number | string\n locale?: string\n },\n context: {\n req: PayloadRequestWithData\n },\n) => Promise<GeneratedTypes['collections'][TSlug]>\n\nexport function updateResolver<TSlug extends keyof GeneratedTypes['collections']>(\n collection: Collection,\n): Resolver<TSlug> {\n return async function resolver(_, args, context: Context) {\n let { req } = context\n const locale = req.locale\n const fallbackLocale = req.fallbackLocale\n req = isolateObjectProperty(req, 'locale')\n req = isolateObjectProperty(req, 'fallbackLocale')\n req.locale = args.locale || locale\n req.fallbackLocale = args.fallbackLocale || fallbackLocale\n if (!req.query) req.query = {}\n\n const draft: boolean =\n args.draft ?? req.query?.draft === 'false'\n ? false\n : req.query?.draft === 'true'\n ? true\n : undefined\n if (typeof draft === 'boolean') req.query.draft = String(draft)\n\n context.req = req\n\n const options = {\n id: args.id,\n autosave: args.autosave,\n collection,\n data: args.data as any,\n depth: 0,\n draft: args.draft,\n req: isolateObjectProperty(req, 'transactionID'),\n }\n\n const result = await updateByIDOperation<TSlug>(options)\n\n return result\n }\n}\n"],"names":["updateByIDOperation","isolateObjectProperty","updateResolver","collection","resolver","_","args","context","req","locale","fallbackLocale","query","draft","undefined","String","options","id","autosave","data","depth","result"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,mBAAmB,QAAQ,qBAAoB;AACxD,SAASC,qBAAqB,QAAQ,oBAAmB;AAmBzD,OAAO,SAASC,eACdC,UAAsB;IAEtB,OAAO,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QACtD,IAAI,EAAEC,GAAG,EAAE,GAAGD;QACd,MAAME,SAASD,IAAIC,MAAM;QACzB,MAAMC,iBAAiBF,IAAIE,cAAc;QACzCF,MAAMP,sBAAsBO,KAAK;QACjCA,MAAMP,sBAAsBO,KAAK;QACjCA,IAAIC,MAAM,GAAGH,KAAKG,MAAM,IAAIA;QAC5BD,IAAIE,cAAc,GAAGJ,KAAKI,cAAc,IAAIA;QAC5C,IAAI,CAACF,IAAIG,KAAK,EAAEH,IAAIG,KAAK,GAAG,CAAC;QAE7B,MAAMC,QACJN,KAAKM,KAAK,IAAIJ,IAAIG,KAAK,EAAEC,UAAU,UAC/B,QACAJ,IAAIG,KAAK,EAAEC,UAAU,SACnB,OACAC;QACR,IAAI,OAAOD,UAAU,WAAWJ,IAAIG,KAAK,CAACC,KAAK,GAAGE,OAAOF;QAEzDL,QAAQC,GAAG,GAAGA;QAEd,MAAMO,UAAU;YACdC,IAAIV,KAAKU,EAAE;YACXC,UAAUX,KAAKW,QAAQ;YACvBd;YACAe,MAAMZ,KAAKY,IAAI;YACfC,OAAO;YACPP,OAAON,KAAKM,KAAK;YACjBJ,KAAKP,sBAAsBO,KAAK;QAClC;QAEA,MAAMY,SAAS,MAAMpB,oBAA2Be;QAEhD,OAAOK;IACT;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CollectionPermission, GlobalPermission } from 'payload/auth';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types';
|
|
3
3
|
export type Resolver = (_: unknown, context: {
|
|
4
|
-
req:
|
|
4
|
+
req: PayloadRequestWithData;
|
|
5
5
|
}) => Promise<CollectionPermission | GlobalPermission>;
|
|
6
6
|
export declare function docAccessResolver(global: SanitizedGlobalConfig): Resolver;
|
|
7
7
|
//# sourceMappingURL=docAccess.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docAccess.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/docAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC1E,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"docAccess.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/docAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAOlF,MAAM,MAAM,QAAQ,GAAG,CACrB,CAAC,EAAE,OAAO,EACV,OAAO,EAAE;IACP,GAAG,EAAE,sBAAsB,CAAA;CAC5B,KACE,OAAO,CAAC,oBAAoB,GAAG,gBAAgB,CAAC,CAAA;AAErD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,qBAAqB,GAAG,QAAQ,CASzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/globals/docAccess.ts"],"sourcesContent":["import type { CollectionPermission, GlobalPermission } from 'payload/auth'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/globals/docAccess.ts"],"sourcesContent":["import type { CollectionPermission, GlobalPermission } from 'payload/auth'\nimport type { PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'\n\nimport { docAccessOperationGlobal } from 'payload/operations'\nimport { isolateObjectProperty } from 'payload/utilities'\n\nimport type { Context } from '../types.js'\n\nexport type Resolver = (\n _: unknown,\n context: {\n req: PayloadRequestWithData\n },\n) => Promise<CollectionPermission | GlobalPermission>\n\nexport function docAccessResolver(global: SanitizedGlobalConfig): Resolver {\n async function resolver(_, context: Context) {\n return docAccessOperationGlobal({\n globalConfig: global,\n req: isolateObjectProperty(context.req, 'transactionID'),\n })\n }\n\n return resolver\n}\n"],"names":["docAccessOperationGlobal","isolateObjectProperty","docAccessResolver","global","resolver","_","context","globalConfig","req"],"rangeMappings":";;;;;;;;;;","mappings":"AAGA,SAASA,wBAAwB,QAAQ,qBAAoB;AAC7D,SAASC,qBAAqB,QAAQ,oBAAmB;AAWzD,OAAO,SAASC,kBAAkBC,MAA6B;IAC7D,eAAeC,SAASC,CAAC,EAAEC,OAAgB;QACzC,OAAON,yBAAyB;YAC9BO,cAAcJ;YACdK,KAAKP,sBAAsBK,QAAQE,GAAG,EAAE;QAC1C;IACF;IAEA,OAAOJ;AACT"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Document,
|
|
1
|
+
import type { Document, PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types';
|
|
2
2
|
export type Resolver = (_: unknown, args: {
|
|
3
3
|
draft?: boolean;
|
|
4
4
|
fallbackLocale?: string;
|
|
5
5
|
id: number | string;
|
|
6
6
|
locale?: string;
|
|
7
7
|
}, context: {
|
|
8
|
-
req:
|
|
8
|
+
req: PayloadRequestWithData;
|
|
9
9
|
}) => Promise<Document>;
|
|
10
10
|
export default function findVersionByIDResolver(globalConfig: SanitizedGlobalConfig): Resolver;
|
|
11
11
|
//# sourceMappingURL=findVersionByID.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/findVersionByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/findVersionByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAO5F,MAAM,MAAM,QAAQ,GAAG,CACrB,CAAC,EAAE,OAAO,EACV,IAAI,EAAE;IACJ,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,EACD,OAAO,EAAE;IACP,GAAG,EAAE,sBAAsB,CAAA;CAC5B,KACE,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,YAAY,EAAE,qBAAqB,GAAG,QAAQ,CAgB7F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/globals/findVersionByID.ts"],"sourcesContent":["import type { Document,
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/globals/findVersionByID.ts"],"sourcesContent":["import type { Document, PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'\n\nimport { findVersionByIDOperationGlobal } from 'payload/operations'\nimport { isolateObjectProperty } from 'payload/utilities'\n\nimport type { Context } from '../types.js'\n\nexport type Resolver = (\n _: unknown,\n args: {\n draft?: boolean\n fallbackLocale?: string\n id: number | string\n locale?: string\n },\n context: {\n req: PayloadRequestWithData\n },\n) => Promise<Document>\n\nexport default function findVersionByIDResolver(globalConfig: SanitizedGlobalConfig): Resolver {\n return async function resolver(_, args, context: Context) {\n if (args.locale) context.req.locale = args.locale\n if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale\n\n const options = {\n id: args.id,\n depth: 0,\n draft: args.draft,\n globalConfig,\n req: isolateObjectProperty(context.req, 'transactionID'),\n }\n\n const result = await findVersionByIDOperationGlobal(options)\n return result\n }\n}\n"],"names":["findVersionByIDOperationGlobal","isolateObjectProperty","findVersionByIDResolver","globalConfig","resolver","_","args","context","locale","req","fallbackLocale","options","id","depth","draft","result"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,8BAA8B,QAAQ,qBAAoB;AACnE,SAASC,qBAAqB,QAAQ,oBAAmB;AAiBzD,eAAe,SAASC,wBAAwBC,YAAmC;IACjF,OAAO,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QACtD,IAAID,KAAKE,MAAM,EAAED,QAAQE,GAAG,CAACD,MAAM,GAAGF,KAAKE,MAAM;QACjD,IAAIF,KAAKI,cAAc,EAAEH,QAAQE,GAAG,CAACC,cAAc,GAAGJ,KAAKI,cAAc;QAEzE,MAAMC,UAAU;YACdC,IAAIN,KAAKM,EAAE;YACXC,OAAO;YACPC,OAAOR,KAAKQ,KAAK;YACjBX;YACAM,KAAKR,sBAAsBM,QAAQE,GAAG,EAAE;QAC1C;QAEA,MAAMM,SAAS,MAAMf,+BAA+BW;QACpD,OAAOI;IACT;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Document,
|
|
1
|
+
import type { Document, PayloadRequestWithData, SanitizedGlobalConfig, Where } from 'payload/types';
|
|
2
2
|
export type Resolver = (_: unknown, args: {
|
|
3
3
|
fallbackLocale?: string;
|
|
4
4
|
limit?: number;
|
|
@@ -7,7 +7,7 @@ export type Resolver = (_: unknown, args: {
|
|
|
7
7
|
sort?: string;
|
|
8
8
|
where: Where;
|
|
9
9
|
}, context: {
|
|
10
|
-
req:
|
|
10
|
+
req: PayloadRequestWithData;
|
|
11
11
|
}) => Promise<Document>;
|
|
12
12
|
export default function findVersionsResolver(globalConfig: SanitizedGlobalConfig): Resolver;
|
|
13
13
|
//# sourceMappingURL=findVersions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAOnG,MAAM,MAAM,QAAQ,GAAG,CACrB,CAAC,EAAE,OAAO,EACV,IAAI,EAAE;IACJ,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,KAAK,CAAA;CACb,EACD,OAAO,EAAE;IACP,GAAG,EAAE,sBAAsB,CAAA;CAC5B,KACE,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,YAAY,EAAE,qBAAqB,GAAG,QAAQ,CAgB1F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/globals/findVersions.ts"],"sourcesContent":["import type { Document,
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/globals/findVersions.ts"],"sourcesContent":["import type { Document, PayloadRequestWithData, SanitizedGlobalConfig, Where } from 'payload/types'\n\nimport { findVersionsOperationGlobal } from 'payload/operations'\nimport { isolateObjectProperty } from 'payload/utilities'\n\nimport type { Context } from '../types.js'\n\nexport type Resolver = (\n _: unknown,\n args: {\n fallbackLocale?: string\n limit?: number\n locale?: string\n page?: number\n sort?: string\n where: Where\n },\n context: {\n req: PayloadRequestWithData\n },\n) => Promise<Document>\n\nexport default function findVersionsResolver(globalConfig: SanitizedGlobalConfig): Resolver {\n return async function resolver(_, args, context: Context) {\n const options = {\n depth: 0,\n globalConfig,\n limit: args.limit,\n page: args.page,\n req: isolateObjectProperty(context.req, 'transactionID'),\n sort: args.sort,\n where: args.where,\n }\n\n const result = await findVersionsOperationGlobal(options)\n\n return result\n }\n}\n"],"names":["findVersionsOperationGlobal","isolateObjectProperty","findVersionsResolver","globalConfig","resolver","_","args","context","options","depth","limit","page","req","sort","where","result"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,2BAA2B,QAAQ,qBAAoB;AAChE,SAASC,qBAAqB,QAAQ,oBAAmB;AAmBzD,eAAe,SAASC,qBAAqBC,YAAmC;IAC9E,OAAO,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QACtD,MAAMC,UAAU;YACdC,OAAO;YACPN;YACAO,OAAOJ,KAAKI,KAAK;YACjBC,MAAML,KAAKK,IAAI;YACfC,KAAKX,sBAAsBM,QAAQK,GAAG,EAAE;YACxCC,MAAMP,KAAKO,IAAI;YACfC,OAAOR,KAAKQ,KAAK;QACnB;QAEA,MAAMC,SAAS,MAAMf,4BAA4BQ;QAEjD,OAAOO;IACT;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Document,
|
|
1
|
+
import type { Document, PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types';
|
|
2
2
|
type Resolver = (_: unknown, args: {
|
|
3
3
|
id: number | string;
|
|
4
4
|
}, context: {
|
|
5
|
-
req:
|
|
5
|
+
req: PayloadRequestWithData;
|
|
6
6
|
}) => Promise<Document>;
|
|
7
7
|
export default function restoreVersionResolver(globalConfig: SanitizedGlobalConfig): Resolver;
|
|
8
8
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restoreVersion.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/restoreVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"restoreVersion.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/restoreVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAO5F,KAAK,QAAQ,GAAG,CACd,CAAC,EAAE,OAAO,EACV,IAAI,EAAE;IACJ,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CACpB,EACD,OAAO,EAAE;IACP,GAAG,EAAE,sBAAsB,CAAA;CAC5B,KACE,OAAO,CAAC,QAAQ,CAAC,CAAA;AACtB,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,YAAY,EAAE,qBAAqB,GAAG,QAAQ,CAY5F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/globals/restoreVersion.ts"],"sourcesContent":["import type { Document,
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/globals/restoreVersion.ts"],"sourcesContent":["import type { Document, PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'\n\nimport { restoreVersionOperationGlobal } from 'payload/operations'\nimport { isolateObjectProperty } from 'payload/utilities'\n\nimport type { Context } from '../types.js'\n\ntype Resolver = (\n _: unknown,\n args: {\n id: number | string\n },\n context: {\n req: PayloadRequestWithData\n },\n) => Promise<Document>\nexport default function restoreVersionResolver(globalConfig: SanitizedGlobalConfig): Resolver {\n return async function resolver(_, args, context: Context) {\n const options = {\n id: args.id,\n depth: 0,\n globalConfig,\n req: isolateObjectProperty(context.req, 'transactionID'),\n }\n\n const result = await restoreVersionOperationGlobal(options)\n return result\n }\n}\n"],"names":["restoreVersionOperationGlobal","isolateObjectProperty","restoreVersionResolver","globalConfig","resolver","_","args","context","options","id","depth","req","result"],"rangeMappings":";;;;;;;;;;;;;","mappings":"AAEA,SAASA,6BAA6B,QAAQ,qBAAoB;AAClE,SAASC,qBAAqB,QAAQ,oBAAmB;AAazD,eAAe,SAASC,uBAAuBC,YAAmC;IAChF,OAAO,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QACtD,MAAMC,UAAU;YACdC,IAAIH,KAAKG,EAAE;YACXC,OAAO;YACPP;YACAQ,KAAKV,sBAAsBM,QAAQI,GAAG,EAAE;QAC1C;QAEA,MAAMC,SAAS,MAAMZ,8BAA8BQ;QACnD,OAAOI;IACT;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GeneratedTypes } from 'payload';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types';
|
|
3
3
|
import type { DeepPartial } from 'ts-essentials';
|
|
4
4
|
type Resolver<TSlug extends keyof GeneratedTypes['globals']> = (_: unknown, args: {
|
|
5
5
|
data?: DeepPartial<Omit<GeneratedTypes['globals'][TSlug], 'id'>>;
|
|
@@ -7,7 +7,7 @@ type Resolver<TSlug extends keyof GeneratedTypes['globals']> = (_: unknown, args
|
|
|
7
7
|
fallbackLocale?: string;
|
|
8
8
|
locale?: string;
|
|
9
9
|
}, context: {
|
|
10
|
-
req:
|
|
10
|
+
req: PayloadRequestWithData;
|
|
11
11
|
}) => Promise<GeneratedTypes['globals'][TSlug]>;
|
|
12
12
|
export default function updateResolver<TSlug extends keyof GeneratedTypes['globals']>(globalConfig: SanitizedGlobalConfig): Resolver<TSlug>;
|
|
13
13
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/resolvers/globals/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAOhD,KAAK,QAAQ,CAAC,KAAK,SAAS,MAAM,cAAc,CAAC,SAAS,CAAC,IAAI,CAC7D,CAAC,EAAE,OAAO,EACV,IAAI,EAAE;IACJ,IAAI,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IAChE,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,EACD,OAAO,EAAE;IACP,GAAG,EAAE,sBAAsB,CAAA;CAC5B,KACE,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;AAE9C,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAAK,SAAS,MAAM,cAAc,CAAC,SAAS,CAAC,EAClF,YAAY,EAAE,qBAAqB,GAClC,QAAQ,CAAC,KAAK,CAAC,CAmBjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/globals/update.ts"],"sourcesContent":["import type { GeneratedTypes } from 'payload'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/globals/update.ts"],"sourcesContent":["import type { GeneratedTypes } from 'payload'\nimport type { PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'\nimport type { DeepPartial } from 'ts-essentials'\n\nimport { updateOperationGlobal } from 'payload/operations'\nimport { isolateObjectProperty } from 'payload/utilities'\n\nimport type { Context } from '../types.js'\n\ntype Resolver<TSlug extends keyof GeneratedTypes['globals']> = (\n _: unknown,\n args: {\n data?: DeepPartial<Omit<GeneratedTypes['globals'][TSlug], 'id'>>\n draft?: boolean\n fallbackLocale?: string\n locale?: string\n },\n context: {\n req: PayloadRequestWithData\n },\n) => Promise<GeneratedTypes['globals'][TSlug]>\n\nexport default function updateResolver<TSlug extends keyof GeneratedTypes['globals']>(\n globalConfig: SanitizedGlobalConfig,\n): Resolver<TSlug> {\n return async function resolver(_, args, context: Context) {\n if (args.locale) context.req.locale = args.locale\n if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale\n\n const { slug } = globalConfig\n\n const options = {\n slug,\n data: args.data,\n depth: 0,\n draft: args.draft,\n globalConfig,\n req: isolateObjectProperty(context.req, 'transactionID'),\n }\n\n const result = await updateOperationGlobal<TSlug>(options)\n return result\n }\n}\n"],"names":["updateOperationGlobal","isolateObjectProperty","updateResolver","globalConfig","resolver","_","args","context","locale","req","fallbackLocale","slug","options","data","depth","draft","result"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,qBAAqB,QAAQ,oBAAmB;AAiBzD,eAAe,SAASC,eACtBC,YAAmC;IAEnC,OAAO,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QACtD,IAAID,KAAKE,MAAM,EAAED,QAAQE,GAAG,CAACD,MAAM,GAAGF,KAAKE,MAAM;QACjD,IAAIF,KAAKI,cAAc,EAAEH,QAAQE,GAAG,CAACC,cAAc,GAAGJ,KAAKI,cAAc;QAEzE,MAAM,EAAEC,IAAI,EAAE,GAAGR;QAEjB,MAAMS,UAAU;YACdD;YACAE,MAAMP,KAAKO,IAAI;YACfC,OAAO;YACPC,OAAOT,KAAKS,KAAK;YACjBZ;YACAM,KAAKR,sBAAsBM,QAAQE,GAAG,EAAE;QAC1C;QAEA,MAAMO,SAAS,MAAMhB,sBAA6BY;QAClD,OAAOI;IACT;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadRequestWithData } from 'payload/types';
|
|
2
2
|
export type Context = {
|
|
3
3
|
headers: {
|
|
4
4
|
[key: string]: string;
|
|
5
5
|
};
|
|
6
|
-
req:
|
|
6
|
+
req: PayloadRequestWithData;
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resolvers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resolvers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAE3D,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KACtB,CAAA;IACD,GAAG,EAAE,sBAAsB,CAAA;CAC5B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resolvers/types.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/resolvers/types.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\n\nexport type Context = {\n headers: {\n [key: string]: string\n }\n req: PayloadRequestWithData\n}\n"],"names":[],"rangeMappings":"","mappings":"AAEA,WAKC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildMutationInputType.d.ts","sourceRoot":"","sources":["../../src/schema/buildMutationInputType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildMutationInputType.d.ts","sourceRoot":"","sources":["../../src/schema/buildMutationInputType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAe,MAAM,SAAS,CAAA;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAQV,KAAK,EASL,yBAAyB,EACzB,eAAe,EAMhB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAIL,sBAAsB,EAKvB,MAAM,SAAS,CAAA;AAWhB,QAAA,MAAM,YAAY;;;CAGjB,CAAA;AAED,eAAO,MAAM,mBAAmB,SACxB,MAAM,mBAAmB,cACnB,yBAAyB,KACpC,iBAUF,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,CAAA;CACxC,CAAA;AAED,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,sBAAsB,CAAC,EACrC,IAAI,EACJ,MAAM,EACN,MAAM,EACN,aAAqB,EACrB,aAAa,EACb,UAAU,GACX,EAAE,0BAA0B,GAAG,sBAAsB,GAAG,IAAI,CAgQ5D"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { GraphQLJSON } from 'graphql-type-json';
|
|
1
|
+
import { GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLInputObjectType, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql';
|
|
3
2
|
import { fieldAffectsData, optionIsObject, tabHasName } from 'payload/types';
|
|
4
3
|
import { toWords } from 'payload/utilities';
|
|
5
4
|
import { flattenTopLevelFields } from 'payload/utilities';
|
|
5
|
+
import { GraphQLJSON } from '../packages/graphql-type-json/index.js';
|
|
6
6
|
import combineParentName from '../utilities/combineParentName.js';
|
|
7
7
|
import formatName from '../utilities/formatName.js';
|
|
8
8
|
import { groupOrTabHasRequiredSubfield } from '../utilities/groupOrTabHasRequiredSubfield.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/buildMutationInputType.ts"],"sourcesContent":["/* eslint-disable no-use-before-define */\nimport type { GraphQLInputFieldConfig, GraphQLScalarType, GraphQLType } from 'graphql'\nimport type { GraphQLInfo } from 'payload/config'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload/types'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLNonNull,\n GraphQLString,\n} from 'graphql'\nimport { GraphQLJSON } from 'graphql-type-json'\nimport { fieldAffectsData, optionIsObject, tabHasName } from 'payload/types'\nimport { toWords } from 'payload/utilities'\nimport { flattenTopLevelFields } from 'payload/utilities'\n\nimport combineParentName from '../utilities/combineParentName.js'\nimport formatName from '../utilities/formatName.js'\nimport { groupOrTabHasRequiredSubfield } from '../utilities/groupOrTabHasRequiredSubfield.js'\nimport withNullableType from './withNullableType.js'\n\nconst idFieldTypes = {\n number: GraphQLInt,\n text: GraphQLString,\n}\n\nexport const getCollectionIDType = (\n type: keyof typeof idFieldTypes,\n collection: SanitizedCollectionConfig,\n): GraphQLScalarType => {\n const idField = flattenTopLevelFields(collection.fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (!idField) {\n return idFieldTypes[type]\n }\n\n return idFieldTypes[idField.type]\n}\n\nexport type InputObjectTypeConfig = {\n [path: string]: GraphQLInputFieldConfig\n}\n\ntype BuildMutationInputTypeArgs = {\n config: SanitizedConfig\n fields: Field[]\n forceNullable?: boolean\n graphqlResult: GraphQLInfo\n name: string\n parentName: string\n}\n\nexport function buildMutationInputType({\n name,\n config,\n fields,\n forceNullable = false,\n graphqlResult,\n parentName,\n}: BuildMutationInputTypeArgs): GraphQLInputObjectType | null {\n const fieldToSchemaMap = {\n array: (inputObjectTypeConfig: InputObjectTypeConfig, field: ArrayField) => {\n const fullName = combineParentName(parentName, toWords(field.name, true))\n let type: GraphQLList<GraphQLType> | GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: field.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) return inputObjectTypeConfig\n\n type = new GraphQLList(withNullableType(field, type, forceNullable))\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n blocks: (inputObjectTypeConfig: InputObjectTypeConfig, field: BlockField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: GraphQLJSON },\n }),\n checkbox: (inputObjectTypeConfig: InputObjectTypeConfig, field: CheckboxField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: GraphQLBoolean },\n }),\n code: (inputObjectTypeConfig: InputObjectTypeConfig, field: CodeField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n collapsible: (inputObjectTypeConfig: InputObjectTypeConfig, field: CollapsibleField) =>\n field.fields.reduce((acc, subField: CollapsibleField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) return addSubField(acc, subField)\n return acc\n }, inputObjectTypeConfig),\n date: (inputObjectTypeConfig: InputObjectTypeConfig, field: DateField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n email: (inputObjectTypeConfig: InputObjectTypeConfig, field: EmailField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n group: (inputObjectTypeConfig: InputObjectTypeConfig, field: GroupField) => {\n const requiresAtLeastOneField = groupOrTabHasRequiredSubfield(field)\n const fullName = combineParentName(parentName, toWords(field.name, true))\n let type: GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: field.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) return inputObjectTypeConfig\n\n if (requiresAtLeastOneField) type = new GraphQLNonNull(type)\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n json: (inputObjectTypeConfig: InputObjectTypeConfig, field: JSONField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n number: (inputObjectTypeConfig: InputObjectTypeConfig, field: NumberField) => {\n const type = field.name === 'id' ? GraphQLInt : GraphQLFloat\n return {\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(type) : type,\n forceNullable,\n ),\n },\n }\n },\n point: (inputObjectTypeConfig: InputObjectTypeConfig, field: PointField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, new GraphQLList(GraphQLFloat), forceNullable) },\n }),\n radio: (inputObjectTypeConfig: InputObjectTypeConfig, field: RadioField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n relationship: (inputObjectTypeConfig: InputObjectTypeConfig, field: RelationshipField) => {\n const { relationTo } = field\n type PayloadGraphQLRelationshipType =\n | GraphQLInputObjectType\n | GraphQLList<GraphQLScalarType>\n | GraphQLScalarType\n let type: PayloadGraphQLRelationshipType\n\n if (Array.isArray(relationTo)) {\n const fullName = `${combineParentName(\n parentName,\n toWords(field.name, true),\n )}RelationshipInput`\n type = new GraphQLInputObjectType({\n name: fullName,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${fullName}RelationTo`,\n values: relationTo.reduce(\n (values, option) => ({\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n })\n } else {\n type = getCollectionIDType(\n config.db.defaultIDType,\n graphqlResult.collections[relationTo].config,\n )\n }\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type: field.hasMany ? new GraphQLList(type) : type },\n }\n },\n richText: (inputObjectTypeConfig: InputObjectTypeConfig, field: RichTextField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n row: (inputObjectTypeConfig: InputObjectTypeConfig, field: RowField) =>\n field.fields.reduce((acc, subField: Field) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) return addSubField(acc, subField)\n return acc\n }, inputObjectTypeConfig),\n select: (inputObjectTypeConfig: InputObjectTypeConfig, field: SelectField) => {\n const formattedName = `${combineParentName(parentName, field.name)}_MutationInput`\n let type: GraphQLType = new GraphQLEnumType({\n name: formattedName,\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 type = field.hasMany ? new GraphQLList(type) : type\n type = withNullableType(field, type, forceNullable)\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n tabs: (inputObjectTypeConfig: InputObjectTypeConfig, field: TabsField) => {\n return field.tabs.reduce((acc, tab) => {\n if (tabHasName(tab)) {\n const fullName = combineParentName(parentName, toWords(tab.name, true))\n const requiresAtLeastOneField = groupOrTabHasRequiredSubfield(field)\n let type: GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: tab.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) return acc\n\n if (requiresAtLeastOneField) type = new GraphQLNonNull(type)\n return {\n ...acc,\n [tab.name]: { type },\n }\n }\n\n return {\n ...acc,\n ...tab.fields.reduce((subFieldSchema, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) return addSubField(subFieldSchema, subField)\n return subFieldSchema\n }, acc),\n }\n }, inputObjectTypeConfig)\n },\n text: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextField) => ({\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,\n forceNullable,\n ),\n },\n }),\n textarea: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextareaField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n upload: (inputObjectTypeConfig: InputObjectTypeConfig, field: UploadField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n }\n\n const fieldName = formatName(name)\n\n const fieldSchemas = fields.reduce((inputObjectTypeConfig, field) => {\n const fieldSchema = fieldToSchemaMap[field.type]\n\n if (typeof fieldSchema !== 'function') {\n return inputObjectTypeConfig\n }\n\n const schema = fieldSchema(inputObjectTypeConfig, field)\n if (Object.keys(schema).length === 0) {\n return inputObjectTypeConfig\n }\n\n return {\n ...inputObjectTypeConfig,\n ...fieldSchema(inputObjectTypeConfig, field),\n }\n }, {})\n\n if (Object.keys(fieldSchemas).length === 0) {\n return null\n }\n\n return new GraphQLInputObjectType({\n name: `mutation${fieldName}Input`,\n fields: fieldSchemas,\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLNonNull","GraphQLString","GraphQLJSON","fieldAffectsData","optionIsObject","tabHasName","toWords","flattenTopLevelFields","combineParentName","formatName","groupOrTabHasRequiredSubfield","withNullableType","idFieldTypes","number","text","getCollectionIDType","type","collection","idField","fields","find","field","name","buildMutationInputType","config","forceNullable","graphqlResult","parentName","fieldToSchemaMap","array","inputObjectTypeConfig","fullName","blocks","checkbox","code","collapsible","reduce","acc","subField","addSubField","date","email","group","requiresAtLeastOneField","json","hasMany","point","radio","relationship","relationTo","Array","isArray","values","option","value","db","defaultIDType","collections","richText","row","select","formattedName","options","tabs","tab","subFieldSchema","textarea","upload","fieldName","fieldSchemas","fieldSchema","schema","Object","keys","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,uCAAuC,GA6BvC,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,aAAa,QACR,UAAS;AAChB,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,UAAU,QAAQ,gBAAe;AAC5E,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,qBAAqB,QAAQ,oBAAmB;AAEzD,OAAOC,uBAAuB,oCAAmC;AACjE,OAAOC,gBAAgB,6BAA4B;AACnD,SAASC,6BAA6B,QAAQ,gDAA+C;AAC7F,OAAOC,sBAAsB,wBAAuB;AAEpD,MAAMC,eAAe;IACnBC,QAAQf;IACRg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QAAwB,CAAA;gBAC7E,GAAGS,qBAAqB;gBACxB,CAACT,MAAMC,IAAI,CAAC,EAAE;oBAAEN,MAAML,iBAAiBU,OAAOpB,eAAewB;gBAAe;YAC9E,CAAA;IACF;IAEA,MAAM2C,YAAY3D,WAAWa;IAE7B,MAAM+C,eAAelD,OAAOiB,MAAM,CAAC,CAACN,uBAAuBT;QACzD,MAAMiD,cAAc1C,gBAAgB,CAACP,MAAML,IAAI,CAAC;QAEhD,IAAI,OAAOsD,gBAAgB,YAAY;YACrC,OAAOxC;QACT;QAEA,MAAMyC,SAASD,YAAYxC,uBAAuBT;QAClD,IAAImD,OAAOC,IAAI,CAACF,QAAQG,MAAM,KAAK,GAAG;YACpC,OAAO5C;QACT;QAEA,OAAO;YACL,GAAGA,qBAAqB;YACxB,GAAGwC,YAAYxC,uBAAuBT,MAAM;QAC9C;IACF,GAAG,CAAC;IAEJ,IAAImD,OAAOC,IAAI,CAACJ,cAAcK,MAAM,KAAK,GAAG;QAC1C,OAAO;IACT;IAEA,OAAO,IAAI7E,uBAAuB;QAChCyB,MAAM,CAAC,QAAQ,EAAE8C,UAAU,KAAK,CAAC;QACjCjD,QAAQkD;IACV;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/schema/buildMutationInputType.ts"],"sourcesContent":["import type { GraphQLInputFieldConfig, GraphQLScalarType, GraphQLType } from 'graphql'\nimport type { GraphQLInfo } from 'payload/config'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload/types'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLNonNull,\n GraphQLString,\n} from 'graphql'\nimport { fieldAffectsData, optionIsObject, tabHasName } from 'payload/types'\nimport { toWords } from 'payload/utilities'\nimport { flattenTopLevelFields } from 'payload/utilities'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport combineParentName from '../utilities/combineParentName.js'\nimport formatName from '../utilities/formatName.js'\nimport { groupOrTabHasRequiredSubfield } from '../utilities/groupOrTabHasRequiredSubfield.js'\nimport withNullableType from './withNullableType.js'\n\nconst idFieldTypes = {\n number: GraphQLInt,\n text: GraphQLString,\n}\n\nexport const getCollectionIDType = (\n type: keyof typeof idFieldTypes,\n collection: SanitizedCollectionConfig,\n): GraphQLScalarType => {\n const idField = flattenTopLevelFields(collection.fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (!idField) {\n return idFieldTypes[type]\n }\n\n return idFieldTypes[idField.type]\n}\n\nexport type InputObjectTypeConfig = {\n [path: string]: GraphQLInputFieldConfig\n}\n\ntype BuildMutationInputTypeArgs = {\n config: SanitizedConfig\n fields: Field[]\n forceNullable?: boolean\n graphqlResult: GraphQLInfo\n name: string\n parentName: string\n}\n\nexport function buildMutationInputType({\n name,\n config,\n fields,\n forceNullable = false,\n graphqlResult,\n parentName,\n}: BuildMutationInputTypeArgs): GraphQLInputObjectType | null {\n const fieldToSchemaMap = {\n array: (inputObjectTypeConfig: InputObjectTypeConfig, field: ArrayField) => {\n const fullName = combineParentName(parentName, toWords(field.name, true))\n let type: GraphQLList<GraphQLType> | GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: field.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) return inputObjectTypeConfig\n\n type = new GraphQLList(withNullableType(field, type, forceNullable))\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n blocks: (inputObjectTypeConfig: InputObjectTypeConfig, field: BlockField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: GraphQLJSON },\n }),\n checkbox: (inputObjectTypeConfig: InputObjectTypeConfig, field: CheckboxField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: GraphQLBoolean },\n }),\n code: (inputObjectTypeConfig: InputObjectTypeConfig, field: CodeField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n collapsible: (inputObjectTypeConfig: InputObjectTypeConfig, field: CollapsibleField) =>\n field.fields.reduce((acc, subField: CollapsibleField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) return addSubField(acc, subField)\n return acc\n }, inputObjectTypeConfig),\n date: (inputObjectTypeConfig: InputObjectTypeConfig, field: DateField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n email: (inputObjectTypeConfig: InputObjectTypeConfig, field: EmailField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n group: (inputObjectTypeConfig: InputObjectTypeConfig, field: GroupField) => {\n const requiresAtLeastOneField = groupOrTabHasRequiredSubfield(field)\n const fullName = combineParentName(parentName, toWords(field.name, true))\n let type: GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: field.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) return inputObjectTypeConfig\n\n if (requiresAtLeastOneField) type = new GraphQLNonNull(type)\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n json: (inputObjectTypeConfig: InputObjectTypeConfig, field: JSONField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n number: (inputObjectTypeConfig: InputObjectTypeConfig, field: NumberField) => {\n const type = field.name === 'id' ? GraphQLInt : GraphQLFloat\n return {\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(type) : type,\n forceNullable,\n ),\n },\n }\n },\n point: (inputObjectTypeConfig: InputObjectTypeConfig, field: PointField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, new GraphQLList(GraphQLFloat), forceNullable) },\n }),\n radio: (inputObjectTypeConfig: InputObjectTypeConfig, field: RadioField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n relationship: (inputObjectTypeConfig: InputObjectTypeConfig, field: RelationshipField) => {\n const { relationTo } = field\n type PayloadGraphQLRelationshipType =\n | GraphQLInputObjectType\n | GraphQLList<GraphQLScalarType>\n | GraphQLScalarType\n let type: PayloadGraphQLRelationshipType\n\n if (Array.isArray(relationTo)) {\n const fullName = `${combineParentName(\n parentName,\n toWords(field.name, true),\n )}RelationshipInput`\n type = new GraphQLInputObjectType({\n name: fullName,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${fullName}RelationTo`,\n values: relationTo.reduce(\n (values, option) => ({\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n })\n } else {\n type = getCollectionIDType(\n config.db.defaultIDType,\n graphqlResult.collections[relationTo].config,\n )\n }\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type: field.hasMany ? new GraphQLList(type) : type },\n }\n },\n richText: (inputObjectTypeConfig: InputObjectTypeConfig, field: RichTextField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n row: (inputObjectTypeConfig: InputObjectTypeConfig, field: RowField) =>\n field.fields.reduce((acc, subField: Field) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) return addSubField(acc, subField)\n return acc\n }, inputObjectTypeConfig),\n select: (inputObjectTypeConfig: InputObjectTypeConfig, field: SelectField) => {\n const formattedName = `${combineParentName(parentName, field.name)}_MutationInput`\n let type: GraphQLType = new GraphQLEnumType({\n name: formattedName,\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 type = field.hasMany ? new GraphQLList(type) : type\n type = withNullableType(field, type, forceNullable)\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n tabs: (inputObjectTypeConfig: InputObjectTypeConfig, field: TabsField) => {\n return field.tabs.reduce((acc, tab) => {\n if (tabHasName(tab)) {\n const fullName = combineParentName(parentName, toWords(tab.name, true))\n const requiresAtLeastOneField = groupOrTabHasRequiredSubfield(field)\n let type: GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: tab.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) return acc\n\n if (requiresAtLeastOneField) type = new GraphQLNonNull(type)\n return {\n ...acc,\n [tab.name]: { type },\n }\n }\n\n return {\n ...acc,\n ...tab.fields.reduce((subFieldSchema, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) return addSubField(subFieldSchema, subField)\n return subFieldSchema\n }, acc),\n }\n }, inputObjectTypeConfig)\n },\n text: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextField) => ({\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,\n forceNullable,\n ),\n },\n }),\n textarea: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextareaField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n upload: (inputObjectTypeConfig: InputObjectTypeConfig, field: UploadField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n }\n\n const fieldName = formatName(name)\n\n const fieldSchemas = fields.reduce((inputObjectTypeConfig, field) => {\n const fieldSchema = fieldToSchemaMap[field.type]\n\n if (typeof fieldSchema !== 'function') {\n return inputObjectTypeConfig\n }\n\n const schema = fieldSchema(inputObjectTypeConfig, field)\n if (Object.keys(schema).length === 0) {\n return inputObjectTypeConfig\n }\n\n return {\n ...inputObjectTypeConfig,\n ...fieldSchema(inputObjectTypeConfig, field),\n }\n }, {})\n\n if (Object.keys(fieldSchemas).length === 0) {\n return null\n }\n\n return new GraphQLInputObjectType({\n name: `mutation${fieldName}Input`,\n fields: fieldSchemas,\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLNonNull","GraphQLString","fieldAffectsData","optionIsObject","tabHasName","toWords","flattenTopLevelFields","GraphQLJSON","combineParentName","formatName","groupOrTabHasRequiredSubfield","withNullableType","idFieldTypes","number","text","getCollectionIDType","type","collection","idField","fields","find","field","name","buildMutationInputType","config","forceNullable","graphqlResult","parentName","fieldToSchemaMap","array","inputObjectTypeConfig","fullName","blocks","checkbox","code","collapsible","reduce","acc","subField","addSubField","date","email","group","requiresAtLeastOneField","json","hasMany","point","radio","relationship","relationTo","Array","isArray","values","option","value","db","defaultIDType","collections","richText","row","select","formattedName","options","tabs","tab","subFieldSchema","textarea","upload","fieldName","fieldSchemas","fieldSchema","schema","Object","keys","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AA4BA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,aAAa,QACR,UAAS;AAChB,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,UAAU,QAAQ,gBAAe;AAC5E,SAASC,OAAO,QAAQ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AK,EAQV,KAAK,EAUL,eAAe,EAMhB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAOL,iBAAiB,EAGlB,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"buildObjectType.d.ts","sourceRoot":"","sources":["../../src/schema/buildObjectType.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,SAAS,CAAA;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAQV,KAAK,EAUL,eAAe,EAMhB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAOL,iBAAiB,EAGlB,MAAM,SAAS,CAAA;AA2BhB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CAC7C,CAAA;AAED,KAAK,IAAI,GAAG;IACV,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,iBAAS,eAAe,CAAC,EACvB,IAAI,EACJ,UAAe,EACf,MAAM,EACN,MAAM,EACN,aAAa,EACb,aAAa,EACb,UAAU,GACX,EAAE,IAAI,GAAG,iBAAiB,CA2lB1B;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-use-before-define */ /* eslint-disable no-await-in-loop */ /* eslint-disable no-restricted-syntax */ import { GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql';
|
|
2
2
|
import { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars';
|
|
3
|
-
/* eslint-disable no-use-before-define */ import { GraphQLJSON } from 'graphql-type-json';
|
|
4
3
|
import { tabHasName } from 'payload/types';
|
|
5
|
-
import { toWords } from 'payload/utilities';
|
|
4
|
+
import { createDataloaderCacheKey, toWords } from 'payload/utilities';
|
|
5
|
+
import { GraphQLJSON } from '../packages/graphql-type-json/index.js';
|
|
6
6
|
import combineParentName from '../utilities/combineParentName.js';
|
|
7
7
|
import formatName from '../utilities/formatName.js';
|
|
8
8
|
import formatOptions from '../utilities/formatOptions.js';
|
|
@@ -191,7 +191,7 @@ function buildObjectType({ name, baseFields = {}, config, fields, forceNullable,
|
|
|
191
191
|
value: {
|
|
192
192
|
type: new GraphQLUnionType({
|
|
193
193
|
name: relationshipName,
|
|
194
|
-
|
|
194
|
+
resolveType (data, { req }) {
|
|
195
195
|
return graphqlResult.collections[data.collection].graphQL.type.name;
|
|
196
196
|
},
|
|
197
197
|
types
|
|
@@ -208,6 +208,14 @@ function buildObjectType({ name, baseFields = {}, config, fields, forceNullable,
|
|
|
208
208
|
// that is currently being created.
|
|
209
209
|
type = type || newlyCreatedBlockType;
|
|
210
210
|
const relationshipArgs = {};
|
|
211
|
+
const relationsUseDrafts = (Array.isArray(relationTo) ? relationTo : [
|
|
212
|
+
relationTo
|
|
213
|
+
]).some((relation)=>graphqlResult.collections[relation].config.versions?.drafts);
|
|
214
|
+
if (relationsUseDrafts) {
|
|
215
|
+
relationshipArgs.draft = {
|
|
216
|
+
type: GraphQLBoolean
|
|
217
|
+
};
|
|
218
|
+
}
|
|
211
219
|
if (config.localization) {
|
|
212
220
|
relationshipArgs.locale = {
|
|
213
221
|
type: graphqlResult.types.localeInputType
|
|
@@ -227,6 +235,7 @@ function buildObjectType({ name, baseFields = {}, config, fields, forceNullable,
|
|
|
227
235
|
const locale = args.locale || context.req.locale;
|
|
228
236
|
const fallbackLocale = args.fallbackLocale || context.req.fallbackLocale;
|
|
229
237
|
let relatedCollectionSlug = field.relationTo;
|
|
238
|
+
const draft = args.draft ?? context.req.query?.draft;
|
|
230
239
|
if (hasManyValues) {
|
|
231
240
|
const results = [];
|
|
232
241
|
const resultPromises = [];
|
|
@@ -237,17 +246,18 @@ function buildObjectType({ name, baseFields = {}, config, fields, forceNullable,
|
|
|
237
246
|
collectionSlug = relatedDoc.relationTo;
|
|
238
247
|
id = relatedDoc.value;
|
|
239
248
|
}
|
|
240
|
-
const result = await context.req.payloadDataLoader.load(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
locale,
|
|
249
|
+
const result = await context.req.payloadDataLoader.load(createDataloaderCacheKey({
|
|
250
|
+
collectionSlug: collectionSlug,
|
|
251
|
+
currentDepth: 0,
|
|
252
|
+
depth: 0,
|
|
253
|
+
docID: id,
|
|
254
|
+
draft,
|
|
247
255
|
fallbackLocale,
|
|
248
|
-
|
|
249
|
-
false
|
|
250
|
-
|
|
256
|
+
locale,
|
|
257
|
+
overrideAccess: false,
|
|
258
|
+
showHiddenFields: false,
|
|
259
|
+
transactionID: context.req.transactionID
|
|
260
|
+
}));
|
|
251
261
|
if (result) {
|
|
252
262
|
if (isRelatedToManyCollections) {
|
|
253
263
|
results[i] = {
|
|
@@ -276,17 +286,18 @@ function buildObjectType({ name, baseFields = {}, config, fields, forceNullable,
|
|
|
276
286
|
relatedCollectionSlug = value.relationTo;
|
|
277
287
|
}
|
|
278
288
|
if (id) {
|
|
279
|
-
const relatedDocument = await context.req.payloadDataLoader.load(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
locale,
|
|
289
|
+
const relatedDocument = await context.req.payloadDataLoader.load(createDataloaderCacheKey({
|
|
290
|
+
collectionSlug: relatedCollectionSlug,
|
|
291
|
+
currentDepth: 0,
|
|
292
|
+
depth: 0,
|
|
293
|
+
docID: id,
|
|
294
|
+
draft,
|
|
286
295
|
fallbackLocale,
|
|
287
|
-
|
|
288
|
-
false
|
|
289
|
-
|
|
296
|
+
locale,
|
|
297
|
+
overrideAccess: false,
|
|
298
|
+
showHiddenFields: false,
|
|
299
|
+
transactionID: context.req.transactionID
|
|
300
|
+
}));
|
|
290
301
|
if (relatedDocument) {
|
|
291
302
|
if (isRelatedToManyCollections) {
|
|
292
303
|
return {
|
|
@@ -321,25 +332,35 @@ function buildObjectType({ name, baseFields = {}, config, fields, forceNullable,
|
|
|
321
332
|
async resolve (parent, args, context) {
|
|
322
333
|
let depth = config.defaultDepth;
|
|
323
334
|
if (typeof args.depth !== 'undefined') depth = args.depth;
|
|
335
|
+
if (typeof field?.editor === 'function') {
|
|
336
|
+
throw new Error('Attempted to access unsanitized rich text editor.');
|
|
337
|
+
}
|
|
324
338
|
const editor = field?.editor;
|
|
325
339
|
// RichText fields have their own depth argument in GraphQL.
|
|
326
340
|
// This is why the populationPromise (which populates richtext fields like uploads and relationships)
|
|
327
341
|
// is run here again, with the provided depth.
|
|
328
342
|
// In the graphql find.ts resolver, the depth is then hard-coded to 0.
|
|
329
343
|
// Effectively, this means that the populationPromise for GraphQL is only run here, and not in the find.ts resolver / normal population promise.
|
|
330
|
-
if (editor?.
|
|
331
|
-
|
|
344
|
+
if (editor?.populationPromises) {
|
|
345
|
+
const fieldPromises = [];
|
|
346
|
+
const populationPromises = [];
|
|
347
|
+
const populateDepth = field?.maxDepth !== undefined && field?.maxDepth < depth ? field?.maxDepth : depth;
|
|
348
|
+
editor?.populationPromises({
|
|
332
349
|
context,
|
|
333
|
-
depth,
|
|
350
|
+
depth: populateDepth,
|
|
351
|
+
draft: args.draft,
|
|
334
352
|
field,
|
|
353
|
+
fieldPromises,
|
|
335
354
|
findMany: false,
|
|
336
355
|
flattenLocales: false,
|
|
337
356
|
overrideAccess: false,
|
|
338
|
-
populationPromises
|
|
357
|
+
populationPromises,
|
|
339
358
|
req: context.req,
|
|
340
359
|
showHiddenFields: false,
|
|
341
360
|
siblingDoc: parent
|
|
342
361
|
});
|
|
362
|
+
await Promise.all(fieldPromises);
|
|
363
|
+
await Promise.all(populationPromises);
|
|
343
364
|
}
|
|
344
365
|
return parent[field.name];
|
|
345
366
|
}
|
|
@@ -442,17 +463,18 @@ function buildObjectType({ name, baseFields = {}, config, fields, forceNullable,
|
|
|
442
463
|
const fallbackLocale = args.fallbackLocale || context.req.fallbackLocale;
|
|
443
464
|
const id = value;
|
|
444
465
|
if (id) {
|
|
445
|
-
const relatedDocument = await context.req.payloadDataLoader.load(
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
locale,
|
|
466
|
+
const relatedDocument = await context.req.payloadDataLoader.load(createDataloaderCacheKey({
|
|
467
|
+
collectionSlug: relatedCollectionSlug,
|
|
468
|
+
currentDepth: 0,
|
|
469
|
+
depth: 0,
|
|
470
|
+
docID: id,
|
|
471
|
+
draft: false,
|
|
452
472
|
fallbackLocale,
|
|
453
|
-
|
|
454
|
-
false
|
|
455
|
-
|
|
473
|
+
locale,
|
|
474
|
+
overrideAccess: false,
|
|
475
|
+
showHiddenFields: false,
|
|
476
|
+
transactionID: context.req.transactionID
|
|
477
|
+
}));
|
|
456
478
|
return relatedDocument || null;
|
|
457
479
|
}
|
|
458
480
|
return null;
|