@payloadcms/graphql 3.0.0-canary.ff8c8fd → 3.0.0
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.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/packages/graphql-query-complexity/QueryComplexity.d.ts +2 -2
- package/dist/packages/graphql-query-complexity/QueryComplexity.d.ts.map +1 -1
- package/dist/packages/graphql-query-complexity/QueryComplexity.js +6 -6
- package/dist/packages/graphql-query-complexity/QueryComplexity.js.map +1 -1
- package/dist/packages/graphql-query-complexity/createComplexityRule.d.ts +1 -1
- package/dist/packages/graphql-query-complexity/createComplexityRule.d.ts.map +1 -1
- package/dist/packages/graphql-query-complexity/createComplexityRule.js +1 -1
- package/dist/packages/graphql-query-complexity/createComplexityRule.js.map +1 -1
- package/dist/packages/graphql-type-json/index.js +4 -4
- package/dist/packages/graphql-type-json/index.js.map +1 -1
- package/dist/resolvers/auth/access.d.ts +1 -2
- package/dist/resolvers/auth/access.d.ts.map +1 -1
- package/dist/resolvers/auth/access.js +2 -3
- package/dist/resolvers/auth/access.js.map +1 -1
- package/dist/resolvers/auth/forgotPassword.d.ts +1 -2
- package/dist/resolvers/auth/forgotPassword.d.ts.map +1 -1
- package/dist/resolvers/auth/forgotPassword.js +1 -2
- package/dist/resolvers/auth/forgotPassword.js.map +1 -1
- package/dist/resolvers/auth/init.d.ts +1 -2
- package/dist/resolvers/auth/init.d.ts.map +1 -1
- package/dist/resolvers/auth/init.js +1 -2
- package/dist/resolvers/auth/init.js.map +1 -1
- package/dist/resolvers/auth/login.d.ts +1 -2
- package/dist/resolvers/auth/login.d.ts.map +1 -1
- package/dist/resolvers/auth/login.js +3 -4
- package/dist/resolvers/auth/login.js.map +1 -1
- package/dist/resolvers/auth/logout.d.ts +1 -2
- package/dist/resolvers/auth/logout.d.ts.map +1 -1
- package/dist/resolvers/auth/logout.js +4 -4
- package/dist/resolvers/auth/logout.js.map +1 -1
- package/dist/resolvers/auth/me.d.ts +1 -2
- package/dist/resolvers/auth/me.d.ts.map +1 -1
- package/dist/resolvers/auth/me.js +1 -2
- package/dist/resolvers/auth/me.js.map +1 -1
- package/dist/resolvers/auth/refresh.d.ts +1 -2
- package/dist/resolvers/auth/refresh.d.ts.map +1 -1
- package/dist/resolvers/auth/refresh.js +3 -4
- package/dist/resolvers/auth/refresh.js.map +1 -1
- package/dist/resolvers/auth/resetPassword.d.ts +1 -2
- package/dist/resolvers/auth/resetPassword.d.ts.map +1 -1
- package/dist/resolvers/auth/resetPassword.js +9 -6
- package/dist/resolvers/auth/resetPassword.js.map +1 -1
- package/dist/resolvers/auth/unlock.d.ts +1 -2
- package/dist/resolvers/auth/unlock.d.ts.map +1 -1
- package/dist/resolvers/auth/unlock.js +1 -2
- package/dist/resolvers/auth/unlock.js.map +1 -1
- package/dist/resolvers/auth/verifyEmail.d.ts +1 -2
- package/dist/resolvers/auth/verifyEmail.d.ts.map +1 -1
- package/dist/resolvers/auth/verifyEmail.js +7 -4
- 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 +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 +6 -2
- package/dist/resolvers/collections/delete.js.map +1 -1
- package/dist/resolvers/collections/duplicate.d.ts +1 -1
- package/dist/resolvers/collections/duplicate.d.ts.map +1 -1
- package/dist/resolvers/collections/duplicate.js +1 -1
- package/dist/resolvers/collections/duplicate.js.map +1 -1
- package/dist/resolvers/collections/find.d.ts.map +1 -1
- package/dist/resolvers/collections/find.js +6 -2
- 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 +6 -2
- package/dist/resolvers/collections/findByID.js.map +1 -1
- package/dist/resolvers/collections/findVersions.d.ts.map +1 -1
- package/dist/resolvers/collections/findVersions.js +6 -2
- package/dist/resolvers/collections/findVersions.js.map +1 -1
- package/dist/resolvers/collections/restoreVersion.d.ts +1 -1
- package/dist/resolvers/collections/restoreVersion.d.ts.map +1 -1
- package/dist/resolvers/collections/restoreVersion.js +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 +6 -2
- package/dist/resolvers/collections/update.js.map +1 -1
- package/dist/resolvers/globals/findOne.d.ts +1 -1
- package/dist/resolvers/globals/findOne.d.ts.map +1 -1
- package/dist/resolvers/globals/findOne.js +7 -3
- package/dist/resolvers/globals/findOne.js.map +1 -1
- package/dist/resolvers/globals/findVersionByID.d.ts +1 -1
- package/dist/resolvers/globals/findVersionByID.d.ts.map +1 -1
- package/dist/resolvers/globals/findVersionByID.js +7 -3
- package/dist/resolvers/globals/findVersionByID.js.map +1 -1
- package/dist/resolvers/globals/findVersions.d.ts +1 -1
- package/dist/resolvers/globals/findVersions.d.ts.map +1 -1
- package/dist/resolvers/globals/findVersions.js +1 -1
- package/dist/resolvers/globals/findVersions.js.map +1 -1
- package/dist/resolvers/globals/index.d.ts +5 -5
- package/dist/resolvers/globals/index.d.ts.map +1 -1
- package/dist/resolvers/globals/index.js +5 -5
- package/dist/resolvers/globals/index.js.map +1 -1
- package/dist/resolvers/globals/restoreVersion.d.ts +1 -1
- package/dist/resolvers/globals/restoreVersion.d.ts.map +1 -1
- package/dist/resolvers/globals/restoreVersion.js +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 +7 -3
- package/dist/resolvers/globals/update.js.map +1 -1
- package/dist/schema/buildFallbackLocaleInputType.d.ts +1 -2
- package/dist/schema/buildFallbackLocaleInputType.d.ts.map +1 -1
- package/dist/schema/buildFallbackLocaleInputType.js +2 -3
- package/dist/schema/buildFallbackLocaleInputType.js.map +1 -1
- package/dist/schema/buildLocaleInputType.d.ts +1 -2
- package/dist/schema/buildLocaleInputType.d.ts.map +1 -1
- package/dist/schema/buildLocaleInputType.js +2 -3
- package/dist/schema/buildLocaleInputType.js.map +1 -1
- package/dist/schema/buildMutationInputType.d.ts.map +1 -1
- package/dist/schema/buildMutationInputType.js +27 -11
- package/dist/schema/buildMutationInputType.js.map +1 -1
- package/dist/schema/buildObjectType.d.ts.map +1 -1
- package/dist/schema/buildObjectType.js +148 -66
- 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 +5 -3
- package/dist/schema/buildPoliciesType.js.map +1 -1
- package/dist/schema/buildWhereInputType.d.ts +2 -2
- package/dist/schema/buildWhereInputType.d.ts.map +1 -1
- package/dist/schema/buildWhereInputType.js +3 -4
- package/dist/schema/buildWhereInputType.js.map +1 -1
- package/dist/schema/fieldToWhereInputSchemaMap.d.ts +2 -2
- package/dist/schema/fieldToWhereInputSchemaMap.d.ts.map +1 -1
- package/dist/schema/fieldToWhereInputSchemaMap.js +4 -5
- package/dist/schema/fieldToWhereInputSchemaMap.js.map +1 -1
- package/dist/schema/initCollections.d.ts +2 -2
- package/dist/schema/initCollections.d.ts.map +1 -1
- package/dist/schema/initCollections.js +26 -22
- package/dist/schema/initCollections.js.map +1 -1
- package/dist/schema/initGlobals.d.ts +2 -2
- package/dist/schema/initGlobals.d.ts.map +1 -1
- package/dist/schema/initGlobals.js +17 -16
- package/dist/schema/initGlobals.js.map +1 -1
- package/dist/schema/isFieldNullable.d.ts +1 -2
- package/dist/schema/isFieldNullable.d.ts.map +1 -1
- package/dist/schema/isFieldNullable.js +1 -2
- package/dist/schema/isFieldNullable.js.map +1 -1
- package/dist/schema/operators.d.ts +1 -2
- package/dist/schema/operators.d.ts.map +1 -1
- package/dist/schema/operators.js +1 -2
- package/dist/schema/operators.js.map +1 -1
- package/dist/schema/recursivelyBuildNestedPaths.d.ts +2 -2
- package/dist/schema/recursivelyBuildNestedPaths.d.ts.map +1 -1
- package/dist/schema/recursivelyBuildNestedPaths.js +2 -3
- package/dist/schema/recursivelyBuildNestedPaths.js.map +1 -1
- package/dist/schema/withNullableType.d.ts +1 -2
- package/dist/schema/withNullableType.d.ts.map +1 -1
- package/dist/schema/withNullableType.js +1 -2
- package/dist/schema/withNullableType.js.map +1 -1
- package/dist/schema/withOperators.d.ts.map +1 -1
- package/dist/schema/withOperators.js +6 -4
- package/dist/schema/withOperators.js.map +1 -1
- package/dist/utilities/combineParentName.d.ts +1 -2
- package/dist/utilities/combineParentName.d.ts.map +1 -1
- package/dist/utilities/combineParentName.js +2 -3
- package/dist/utilities/combineParentName.js.map +1 -1
- package/dist/utilities/formatName.d.ts +1 -2
- package/dist/utilities/formatName.d.ts.map +1 -1
- package/dist/utilities/formatName.js +1 -2
- package/dist/utilities/formatName.js.map +1 -1
- package/dist/utilities/formatName.spec.js +1 -1
- package/dist/utilities/formatName.spec.js.map +1 -1
- package/dist/utilities/formatOptions.d.ts +1 -2
- package/dist/utilities/formatOptions.d.ts.map +1 -1
- package/dist/utilities/formatOptions.js +2 -3
- package/dist/utilities/formatOptions.js.map +1 -1
- package/license.md +22 -0
- package/package.json +18 -7
- package/dist/utilities/getCheckIfLocaleObject.d.ts +0 -5
- package/dist/utilities/getCheckIfLocaleObject.d.ts.map +0 -1
- package/dist/utilities/getCheckIfLocaleObject.js +0 -3
- package/dist/utilities/getCheckIfLocaleObject.js.map +0 -1
- package/dist/utilities/uppercase.d.ts +0 -3
- package/dist/utilities/uppercase.d.ts.map +0 -1
- package/dist/utilities/uppercase.js +0 -11
- package/dist/utilities/uppercase.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as GraphQL from 'graphql';
|
|
2
2
|
import { createComplexityRule, fieldExtensionsEstimator, simpleEstimator } from './packages/graphql-query-complexity/index.js';
|
|
3
|
-
import accessResolver from './resolvers/auth/access.js';
|
|
4
|
-
import buildFallbackLocaleInputType from './schema/buildFallbackLocaleInputType.js';
|
|
5
|
-
import buildLocaleInputType from './schema/buildLocaleInputType.js';
|
|
6
|
-
import buildPoliciesType from './schema/buildPoliciesType.js';
|
|
7
|
-
import initCollections from './schema/initCollections.js';
|
|
8
|
-
import initGlobals from './schema/initGlobals.js';
|
|
3
|
+
import { accessResolver } from './resolvers/auth/access.js';
|
|
4
|
+
import { buildFallbackLocaleInputType } from './schema/buildFallbackLocaleInputType.js';
|
|
5
|
+
import { buildLocaleInputType } from './schema/buildLocaleInputType.js';
|
|
6
|
+
import { buildPoliciesType } from './schema/buildPoliciesType.js';
|
|
7
|
+
import { initCollections } from './schema/initCollections.js';
|
|
8
|
+
import { initGlobals } from './schema/initGlobals.js';
|
|
9
9
|
import { wrapCustomFields } from './utilities/wrapCustomResolver.js';
|
|
10
10
|
export function configToSchema(config) {
|
|
11
11
|
const collections = config.collections.reduce((acc, collection)=>{
|
|
@@ -18,6 +18,8 @@ export function configToSchema(config) {
|
|
|
18
18
|
config: config.globals
|
|
19
19
|
};
|
|
20
20
|
const graphqlResult = {
|
|
21
|
+
collections,
|
|
22
|
+
globals,
|
|
21
23
|
Mutation: {
|
|
22
24
|
name: 'Mutation',
|
|
23
25
|
fields: {}
|
|
@@ -26,8 +28,6 @@ export function configToSchema(config) {
|
|
|
26
28
|
name: 'Query',
|
|
27
29
|
fields: {}
|
|
28
30
|
},
|
|
29
|
-
collections,
|
|
30
|
-
globals,
|
|
31
31
|
types: {
|
|
32
32
|
arrayTypes: {},
|
|
33
33
|
blockInputTypes: {},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { OperationArgs } from 'graphql-http'\nimport type { GraphQLInfo, SanitizedConfig } from 'payload'\n\nimport * as GraphQL from 'graphql'\n\nimport {\n createComplexityRule,\n fieldExtensionsEstimator,\n simpleEstimator,\n} from './packages/graphql-query-complexity/index.js'\nimport accessResolver from './resolvers/auth/access.js'\nimport buildFallbackLocaleInputType from './schema/buildFallbackLocaleInputType.js'\nimport buildLocaleInputType from './schema/buildLocaleInputType.js'\nimport buildPoliciesType from './schema/buildPoliciesType.js'\nimport initCollections from './schema/initCollections.js'\nimport initGlobals from './schema/initGlobals.js'\nimport { wrapCustomFields } from './utilities/wrapCustomResolver.js'\n\nexport function configToSchema(config: SanitizedConfig): {\n schema: GraphQL.GraphQLSchema\n validationRules: (args: OperationArgs<any>) => GraphQL.ValidationRule[]\n} {\n const collections = config.collections.reduce((acc, collection) => {\n acc[collection.slug] = {\n config: collection,\n }\n\n return acc\n }, {})\n\n const globals = {\n config: config.globals,\n }\n\n const graphqlResult: GraphQLInfo = {\n Mutation: {\n name: 'Mutation',\n fields: {},\n },\n Query: {\n name: 'Query',\n fields: {},\n },\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { OperationArgs } from 'graphql-http'\nimport type { GraphQLInfo, SanitizedConfig } from 'payload'\n\nimport * as GraphQL from 'graphql'\n\nimport {\n createComplexityRule,\n fieldExtensionsEstimator,\n simpleEstimator,\n} from './packages/graphql-query-complexity/index.js'\nimport { accessResolver } from './resolvers/auth/access.js'\nimport { buildFallbackLocaleInputType } from './schema/buildFallbackLocaleInputType.js'\nimport { buildLocaleInputType } from './schema/buildLocaleInputType.js'\nimport { buildPoliciesType } from './schema/buildPoliciesType.js'\nimport { initCollections } from './schema/initCollections.js'\nimport { initGlobals } from './schema/initGlobals.js'\nimport { wrapCustomFields } from './utilities/wrapCustomResolver.js'\n\nexport function configToSchema(config: SanitizedConfig): {\n schema: GraphQL.GraphQLSchema\n validationRules: (args: OperationArgs<any>) => GraphQL.ValidationRule[]\n} {\n const collections = config.collections.reduce((acc, collection) => {\n acc[collection.slug] = {\n config: collection,\n }\n\n return acc\n }, {})\n\n const globals = {\n config: config.globals,\n }\n\n const graphqlResult: GraphQLInfo = {\n collections,\n globals,\n Mutation: {\n name: 'Mutation',\n fields: {},\n },\n Query: {\n name: 'Query',\n fields: {},\n },\n types: {\n arrayTypes: {},\n blockInputTypes: {},\n blockTypes: {},\n groupTypes: {},\n tabTypes: {},\n },\n }\n\n if (config.localization) {\n graphqlResult.types['localeInputType'] = buildLocaleInputType(config.localization)\n graphqlResult.types['fallbackLocaleInputType'] = buildFallbackLocaleInputType(\n config.localization,\n )\n }\n\n initCollections({ config, graphqlResult })\n initGlobals({ config, graphqlResult })\n\n graphqlResult.Query.fields['Access'] = {\n type: buildPoliciesType(config),\n resolve: accessResolver(config),\n }\n\n if (typeof config.graphQL.queries === 'function') {\n const customQueries = config.graphQL.queries(GraphQL, {\n ...graphqlResult,\n config,\n })\n graphqlResult.Query = {\n ...graphqlResult.Query,\n fields: {\n ...graphqlResult.Query.fields,\n ...wrapCustomFields((customQueries || {}) as never),\n },\n }\n }\n\n if (typeof config.graphQL.mutations === 'function') {\n const customMutations = config.graphQL.mutations(GraphQL, {\n ...graphqlResult,\n config,\n })\n graphqlResult.Mutation = {\n ...graphqlResult.Mutation,\n fields: {\n ...graphqlResult.Mutation.fields,\n ...wrapCustomFields((customMutations || {}) as never),\n },\n }\n }\n\n const query = new GraphQL.GraphQLObjectType(graphqlResult.Query)\n const mutation = new GraphQL.GraphQLObjectType(graphqlResult.Mutation)\n\n const schemaToCreate = {\n mutation,\n query,\n }\n\n const schema = new GraphQL.GraphQLSchema(schemaToCreate)\n\n const validationRules = (args) => [\n createComplexityRule({\n estimators: [\n fieldExtensionsEstimator(),\n simpleEstimator({ defaultComplexity: 1 }), // Fallback if complexity not set\n ],\n maximumComplexity: config.graphQL.maxComplexity,\n variables: args.variableValues,\n // onComplete: (complexity) => { console.log('Query Complexity:', complexity); },\n }),\n ]\n\n return {\n schema,\n validationRules,\n }\n}\n"],"names":["GraphQL","createComplexityRule","fieldExtensionsEstimator","simpleEstimator","accessResolver","buildFallbackLocaleInputType","buildLocaleInputType","buildPoliciesType","initCollections","initGlobals","wrapCustomFields","configToSchema","config","collections","reduce","acc","collection","slug","globals","graphqlResult","Mutation","name","fields","Query","types","arrayTypes","blockInputTypes","blockTypes","groupTypes","tabTypes","localization","type","resolve","graphQL","queries","customQueries","mutations","customMutations","query","GraphQLObjectType","mutation","schemaToCreate","schema","GraphQLSchema","validationRules","args","estimators","defaultComplexity","maximumComplexity","maxComplexity","variables","variableValues"],"mappings":"AAGA,YAAYA,aAAa,UAAS;AAElC,SACEC,oBAAoB,EACpBC,wBAAwB,EACxBC,eAAe,QACV,+CAA8C;AACrD,SAASC,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,4BAA4B,QAAQ,2CAA0C;AACvF,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,gBAAgB,QAAQ,oCAAmC;AAEpE,OAAO,SAASC,eAAeC,MAAuB;IAIpD,MAAMC,cAAcD,OAAOC,WAAW,CAACC,MAAM,CAAC,CAACC,KAAKC;QAClDD,GAAG,CAACC,WAAWC,IAAI,CAAC,GAAG;YACrBL,QAAQI;QACV;QAEA,OAAOD;IACT,GAAG,CAAC;IAEJ,MAAMG,UAAU;QACdN,QAAQA,OAAOM,OAAO;IACxB;IAEA,MAAMC,gBAA6B;QACjCN;QACAK;QACAE,UAAU;YACRC,MAAM;YACNC,QAAQ,CAAC;QACX;QACAC,OAAO;YACLF,MAAM;YACNC,QAAQ,CAAC;QACX;QACAE,OAAO;YACLC,YAAY,CAAC;YACbC,iBAAiB,CAAC;YAClBC,YAAY,CAAC;YACbC,YAAY,CAAC;YACbC,UAAU,CAAC;QACb;IACF;IAEA,IAAIjB,OAAOkB,YAAY,EAAE;QACvBX,cAAcK,KAAK,CAAC,kBAAkB,GAAGlB,qBAAqBM,OA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BAAE4C,mBAAmB;oBAAE;iBACxC;gBACDC,mBAAmBpC,OAAOqB,OAAO,CAACgB,aAAa;gBAC/CC,WAAWL,KAAKM,cAAc;YAEhC;SACD;IAED,OAAO;QACLT;QACAE;IACF;AACF"}
|
|
@@ -32,12 +32,12 @@ export declare function getComplexity(options: {
|
|
|
32
32
|
schema: GraphQLSchema;
|
|
33
33
|
variables?: Record<string, any>;
|
|
34
34
|
}): number;
|
|
35
|
-
export
|
|
36
|
-
OperationDefinition: Record<string, any>;
|
|
35
|
+
export declare class QueryComplexity {
|
|
37
36
|
complexity: number;
|
|
38
37
|
context: ValidationContext;
|
|
39
38
|
estimators: Array<ComplexityEstimator>;
|
|
40
39
|
includeDirectiveDef: GraphQLDirective;
|
|
40
|
+
OperationDefinition: Record<string, any>;
|
|
41
41
|
options: QueryComplexityOptions;
|
|
42
42
|
requestContext?: Record<string, any>;
|
|
43
43
|
skipDirectiveDef: GraphQLDirective;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryComplexity.d.ts","sourceRoot":"","sources":["../../../src/packages/graphql-query-complexity/QueryComplexity.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,sBAAsB,EAEtB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EAGZ,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAEhB,OAAO,
|
|
1
|
+
{"version":3,"file":"QueryComplexity.d.ts","sourceRoot":"","sources":["../../../src/packages/graphql-query-complexity/QueryComplexity.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,sBAAsB,EAEtB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EAGZ,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAEL,Y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Aa,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,GAAG,MAAM,CAwBT;AAED,qBAAa,eAAe;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,iBAAiB,CAAA;IAC1B,UAAU,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAA;IACtC,mBAAmB,EAAE,gBAAgB,CAAA;IACrC,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACxC,OAAO,EAAE,sBAAsB,CAAA;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;gBAEvB,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,sBAAsB;IAqBvE,WAAW,IAAI,YAAY;IAO3B,cAAc,CACZ,IAAI,EAAE,SAAS,GAAG,sBAAsB,GAAG,kBAAkB,GAAG,uBAAuB,EACvF,OAAO,EAAE,oBAAoB,GAAG,iBAAiB,GAAG,gBAAgB,GACnE,MAAM;IA8MT,0BAA0B,CAAC,SAAS,EAAE,uBAAuB,GAAG,IAAI;IA8CpE,0BAA0B,CAAC,SAAS,EAAE,uBAAuB,GAAG,YAAY,GAAG,IAAI;CAgBpF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */ /**
|
|
2
2
|
* Created by Ivo Meißner on 28.07.17.
|
|
3
|
-
*/ import { GraphQLError, GraphQLInterfaceType, GraphQLObjectType,
|
|
3
|
+
*/ import { getNamedType, GraphQLError, GraphQLInterfaceType, GraphQLObjectType, isAbstractType, isCompositeType, Kind, TypeInfo, ValidationContext, visit, visitWithTypeInfo } from 'graphql';
|
|
4
4
|
import { getArgumentValues, getDirectiveValues, getVariableValues } from 'graphql/execution/values.js';
|
|
5
5
|
function queryComplexityMessage(max, actual) {
|
|
6
6
|
return `The query exceeds the maximum complexity of ${max}. ` + `Actual complexity is ${actual}`;
|
|
@@ -24,12 +24,12 @@ export function getComplexity(options) {
|
|
|
24
24
|
}
|
|
25
25
|
return visitor.complexity;
|
|
26
26
|
}
|
|
27
|
-
export
|
|
28
|
-
OperationDefinition;
|
|
27
|
+
export class QueryComplexity {
|
|
29
28
|
complexity;
|
|
30
29
|
context;
|
|
31
30
|
estimators;
|
|
32
31
|
includeDirectiveDef;
|
|
32
|
+
OperationDefinition;
|
|
33
33
|
options;
|
|
34
34
|
requestContext;
|
|
35
35
|
skipDirectiveDef;
|
|
@@ -226,12 +226,12 @@ export default class QueryComplexity {
|
|
|
226
226
|
}
|
|
227
227
|
this.variableValues = coerced;
|
|
228
228
|
switch(operation.operation){
|
|
229
|
-
case 'query':
|
|
230
|
-
this.complexity += this.nodeComplexity(operation, this.context.getSchema().getQueryType());
|
|
231
|
-
break;
|
|
232
229
|
case 'mutation':
|
|
233
230
|
this.complexity += this.nodeComplexity(operation, this.context.getSchema().getMutationType());
|
|
234
231
|
break;
|
|
232
|
+
case 'query':
|
|
233
|
+
this.complexity += this.nodeComplexity(operation, this.context.getSchema().getQueryType());
|
|
234
|
+
break;
|
|
235
235
|
case 'subscription':
|
|
236
236
|
this.complexity += this.nodeComplexity(operation, this.context.getSchema().getSubscriptionType());
|
|
237
237
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/packages/graphql-query-complexity/QueryComplexity.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n/**\n * Created by Ivo Meißner on 28.07.17.\n */\n\nimport type {\n DocumentNode,\n FieldNode,\n FragmentDefinitionNode,\n FragmentSpreadNode,\n GraphQLCompositeType,\n GraphQLDirective,\n GraphQLField,\n GraphQLFieldMap,\n GraphQLNamedType,\n GraphQLSchema,\n GraphQLUnionType,\n InlineFragmentNode,\n OperationDefinitionNode,\n} from 'graphql'\n\nimport {\n GraphQLError,\n GraphQLInterfaceType,\n GraphQLObjectType,\n Kind,\n TypeInfo,\n ValidationContext,\n getNamedType,\n isAbstractType,\n isCompositeType,\n visit,\n visitWithTypeInfo,\n} from 'graphql'\nimport {\n getArgumentValues,\n getDirectiveValues,\n getVariableValues,\n} from 'graphql/execution/values.js'\n\nexport type ComplexityEstimatorArgs = {\n args: { [key: string]: any }\n childComplexity: number\n context?: Record<string, any>\n field: GraphQLField<any, any>\n node: FieldNode\n type: GraphQLCompositeType\n}\n\nexport type ComplexityEstimator = (options: ComplexityEstimatorArgs) => number | void\n\n// Complexity can be anything that is supported by the configured estimators\nexport type Complexity = any\n\n// Map of complexities for possible types (of Union, Interface types)\ntype ComplexityMap = {\n [typeName: string]: number\n}\n\nexport interface QueryComplexityOptions {\n // Pass request context to the estimators via estimationContext\n context?: Record<string, any>\n\n // The query variables. This is needed because the variables are not available\n // Optional function to create a custom error\n createError?: (max: number, actual: number) => GraphQLError\n\n // An array of complexity estimators to use for estimating the complexity\n estimators: Array<ComplexityEstimator>\n\n // Optional callback function to retrieve the determined query complexity\n // Will be invoked whether the query is rejected or not\n // The maximum allowed query complexity, queries above this threshold will be rejected\n maximumComplexity: number\n\n // This can be used for logging or to implement rate limiting\n onComplete?: (complexity: number) => void\n\n // specify operation name only when pass multi-operation documents\n operationName?: string\n\n // in the visitor of the graphql-js library\n variables?: Record<string, any>\n}\n\nfunction queryComplexityMessage(max: number, actual: number): string {\n return `The query exceeds the maximum complexity of ${max}. ` + `Actual complexity is ${actual}`\n}\n\nexport function getComplexity(options: {\n context?: Record<string, any>\n estimators: ComplexityEstimator[]\n operationName?: string\n query: DocumentNode\n schema: GraphQLSchema\n variables?: Record<string, any>\n}): number {\n const typeInfo = new TypeInfo(options.schema)\n\n const errors: GraphQLError[] = []\n const context = new ValidationContext(options.schema, options.query, typeInfo, (error) =>\n errors.push(error),\n )\n const visitor = new QueryComplexity(context, {\n // Maximum complexity does not matter since we're only interested in the calculated complexity.\n context: options.context,\n estimators: options.estimators,\n maximumComplexity: Infinity,\n operationName: options.operationName,\n variables: options.variables,\n })\n\n visit(options.query, visitWithTypeInfo(typeInfo, visitor))\n\n // Throw first error if any\n if (errors.length) {\n throw errors.pop()\n }\n\n return visitor.complexity\n}\n\nexport default class QueryComplexity {\n OperationDefinition: Record<string, any>\n complexity: number\n context: ValidationContext\n estimators: Array<ComplexityEstimator>\n includeDirectiveDef: GraphQLDirective\n options: QueryComplexityOptions\n requestContext?: Record<string, any>\n skipDirectiveDef: GraphQLDirective\n variableValues: Record<string, any>\n\n constructor(context: ValidationContext, options: QueryComplexityOptions) {\n if (!(typeof options.maximumComplexity === 'number' && options.maximumComplexity > 0)) {\n throw new Error('Maximum query complexity must be a positive number')\n }\n\n this.context = context\n this.complexity = 0\n this.options = options\n\n this.includeDirectiveDef = this.context.getSchema().getDirective('include')\n this.skipDirectiveDef = this.context.getSchema().getDirective('skip')\n this.estimators = options.estimators\n this.variableValues = {}\n this.requestContext = options.context\n\n this.OperationDefinition = {\n enter: this.onOperationDefinitionEnter,\n leave: this.onOperationDefinitionLeave,\n }\n }\n\n createError(): GraphQLError {\n if (typeof this.options.createError === 'function') {\n return this.options.createError(this.options.maximumComplexity, this.complexity)\n }\n return new GraphQLError(queryComplexityMessage(this.options.maximumComplexity, this.complexity))\n }\n\n nodeComplexity(\n node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode,\n typeDef: GraphQLInterfaceType | GraphQLObjectType | GraphQLUnionType,\n ): number {\n if (node.selectionSet) {\n let fields: GraphQLFieldMap<any, any> = {}\n if (typeDef instanceof GraphQLObjectType || typeDef instanceof GraphQLInterfaceType) {\n fields = typeDef.getFields()\n }\n\n // Determine all possible types of the current node\n let possibleTypeNames: string[]\n if (isAbstractType(typeDef)) {\n possibleTypeNames = this.context\n .getSchema()\n .getPossibleTypes(typeDef)\n .map((t) => t.name)\n } else {\n possibleTypeNames = [typeDef.name]\n }\n\n // Collect complexities for all possible types individually\n const selectionSetComplexities: ComplexityMap = node.selectionSet.selections.reduce(\n (\n complexities: ComplexityMap,\n childNode: FieldNode | FragmentSpreadNode | InlineFragmentNode,\n ): ComplexityMap => {\n // let nodeComplexity = 0;\n let innerComplexities = complexities\n\n let includeNode = true\n let skipNode = false\n\n for (const directive of childNode.directives ?? []) {\n const directiveName = directive.name.value\n switch (directiveName) {\n case 'include': {\n const values = getDirectiveValues(\n this.includeDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n includeNode = values.if\n }\n break\n }\n case 'skip': {\n const values = getDirectiveValues(\n this.skipDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n skipNode = values.if\n }\n break\n }\n }\n }\n\n if (!includeNode || skipNode) {\n return complexities\n }\n\n switch (childNode.kind) {\n case Kind.FIELD: {\n const field = fields[childNode.name.value]\n // Invalid field, should be caught by other validation rules\n if (!field) {\n break\n }\n const fieldType = getNamedType(field.type)\n\n // Get arguments\n let args: { [key: string]: any }\n try {\n args = getArgumentValues(field, childNode, this.variableValues || {})\n } catch (e) {\n this.context.reportError(e)\n return complexities\n }\n\n // Check if we have child complexity\n let childComplexity = 0\n if (isCompositeType(fieldType)) {\n childComplexity = this.nodeComplexity(childNode, fieldType)\n }\n\n // Run estimators one after another and return first valid complexity\n // score\n const estimatorArgs: ComplexityEstimatorArgs = {\n type: typeDef,\n args,\n childComplexity,\n context: this.requestContext,\n field,\n node: childNode,\n }\n const validScore = this.estimators.find((estimator) => {\n const tmpComplexity = estimator(estimatorArgs)\n\n if (typeof tmpComplexity === 'number' && !isNaN(tmpComplexity)) {\n innerComplexities = addComplexities(\n tmpComplexity,\n complexities,\n possibleTypeNames,\n )\n return true\n }\n\n return false\n })\n if (!validScore) {\n this.context.reportError(\n new GraphQLError(\n `No complexity could be calculated for field ${typeDef.name}.${field.name}. ` +\n 'At least one complexity estimator has to return a complexity score.',\n ),\n )\n return complexities\n }\n break\n }\n case Kind.FRAGMENT_SPREAD: {\n const fragment = this.context.getFragment(childNode.name.value)\n // Unknown fragment, should be caught by other validation rules\n if (!fragment) {\n break\n }\n const fragmentType = this.context\n .getSchema()\n .getType(fragment.typeCondition.name.value)\n // Invalid fragment type, ignore. Should be caught by other validation rules\n if (!isCompositeType(fragmentType)) {\n break\n }\n const nodeComplexity = this.nodeComplexity(fragment, fragmentType)\n if (isAbstractType(fragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(fragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n fragmentType.name,\n ])\n }\n break\n }\n case Kind.INLINE_FRAGMENT: {\n let inlineFragmentType: GraphQLNamedType = typeDef\n if (childNode.typeCondition && childNode.typeCondition.name) {\n inlineFragmentType = this.context\n .getSchema()\n .getType(childNode.typeCondition.name.value)\n if (!isCompositeType(inlineFragmentType)) {\n break\n }\n }\n\n const nodeComplexity = this.nodeComplexity(childNode, inlineFragmentType)\n if (isAbstractType(inlineFragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(inlineFragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n inlineFragmentType.name,\n ])\n }\n break\n }\n default: {\n innerComplexities = addComplexities(\n this.nodeComplexity(childNode, typeDef),\n complexities,\n possibleTypeNames,\n )\n break\n }\n }\n\n return innerComplexities\n },\n {},\n )\n // Only return max complexity of all possible types\n if (!selectionSetComplexities) {\n return NaN\n }\n return Math.max(...Object.values(selectionSetComplexities), 0)\n }\n return 0\n }\n\n onOperationDefinitionEnter(operation: OperationDefinitionNode): void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n // Get variable values from variables that are passed from options, merged\n // with default values defined in the operation\n const { coerced, errors } = getVariableValues(\n this.context.getSchema(),\n // We have to create a new array here because input argument is not readonly in graphql ~14.6.0\n operation.variableDefinitions ? [...operation.variableDefinitions] : [],\n this.options.variables ?? {},\n )\n if (errors && errors.length) {\n // We have input validation errors, report errors and abort\n errors.forEach((error) => this.context.reportError(error))\n return\n }\n this.variableValues = coerced\n\n switch (operation.operation) {\n case 'query':\n this.complexity += this.nodeComplexity(operation, this.context.getSchema().getQueryType())\n break\n case 'mutation':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getMutationType(),\n )\n break\n case 'subscription':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getSubscriptionType(),\n )\n break\n default:\n throw new Error(\n `Query complexity could not be calculated for operation of type ${operation.operation}`,\n )\n }\n }\n\n onOperationDefinitionLeave(operation: OperationDefinitionNode): GraphQLError | void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n if (this.options.onComplete) {\n this.options.onComplete(this.complexity)\n }\n\n if (this.complexity > this.options.maximumComplexity) {\n return this.context.reportError(this.createError())\n }\n }\n}\n\n/**\n * Adds a complexity to the complexity map for all possible types\n * @param complexity\n * @param complexityMap\n * @param possibleTypes\n */\nfunction addComplexities(\n complexity: number,\n complexityMap: ComplexityMap,\n possibleTypes: string[],\n): ComplexityMap {\n for (const type of possibleTypes) {\n if (Object.prototype.hasOwnProperty.call(complexityMap, type)) {\n complexityMap[type] += complexity\n } else {\n complexityMap[type] = complexity\n }\n }\n return complexityMap\n}\n"],"names":["GraphQLError","GraphQLInterfaceType","GraphQLObjectType","Kind","TypeInfo","ValidationContext","getNamedType","isAbstractType","isCompositeType","visit","visitWithTypeInfo","getArgumentValues","getDirectiveValues","getVariableValues","queryComplexityMessage","max","actual","getComplexity","options","typeInfo","schema","errors","context","query","error","push","visitor","QueryComplexity","estimators","maximumComplexity","Infinity","operationName","variables","length","pop","complexity","OperationDefinition","includeDirectiveDef","requestContext","skipDirectiveDef","variableValues","constructor","Error","getSchema","getDirective","enter","onOperationDefinitionEnter","leave","onOperationDefinitionLeave","createError","nodeComplexity","node","typeDef","selectionSet","fields","getFields","possibleTypeNames","getPossibleTypes","map","t","name","selectionSetComplexities","selections","reduce","complexities","childNode","innerComplexities","includeNode","skipNode","directive","directives","directiveName","value","values","if","kind","FIELD","field","fieldType","type","args","e","reportError","childComplexity","estimatorArgs","validScore","find","estimator","tmpComplexity","isNaN","addComplexities","FRAGMENT_SPREAD","fragment","getFragment","fragmentType","getType","typeCondition","INLINE_FRAGMENT","inlineFragmentType","NaN","Math","Object","operation","coerced","variableDefinitions","forEach","getQueryType","getMutationType","getSubscriptionType","onComplete","complexityMap","possibleTypes","prototype","hasOwnProperty","call"],"mappings":"AAAA,qDAAqD,GAErD,+DAA+D,GAC/D;;CAEC,GAkBD,SACEA,YAAY,EACZC,oBAAoB,EACpBC,iBAAiB,EACjBC,IAAI,EACJC,QAAQ,EACRC,iBAAiB,EACjBC,YAAY,EACZC,cAAc,EACdC,eAAe,EACfC,KAAK,EACLC,iBAAiB,QACZ,UAAS;AAChB,SACEC,iBAAiB,EACjBC,kBAAkB,EAClBC,iBAAiB,QACZ,8BAA6B;AA+CpC,SAASC,uBAAuBC,GAAW,EAAEC,MAAc;IACzD,OAAO,CAAC,4CAA4C,EAAED,IAAI,EAAE,CAAC,GAAG,CAAC,qBAAqB,EAAEC,OAAO,CAAC;AAClG;AAEA,OAAO,SAASC,cAAcC,OAO7B;IACC,MAAMC,WAAW,IAAIf,SAASc,QAAQE,MAAM;IAE5C,MAAMC,SAAyB,EAAE;IACjC,MAAMC,UAAU,IAAIjB,kBAAkBa,QAAQE,MAAM,EAAEF,QAAQK,KAAK,EAAEJ,UAAU,CAACK,QAC9EH,OAAOI,IAAI,CAACD;IAEd,MA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AAa,CAAC/B,KAAK,GAAG5C;QACxB;IACF;IACA,OAAO2E;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/packages/graphql-query-complexity/QueryComplexity.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n/**\n * Created by Ivo Meißner on 28.07.17.\n */\n\nimport type {\n DocumentNode,\n FieldNode,\n FragmentDefinitionNode,\n FragmentSpreadNode,\n GraphQLCompositeType,\n GraphQLDirective,\n GraphQLField,\n GraphQLFieldMap,\n GraphQLNamedType,\n GraphQLSchema,\n GraphQLUnionType,\n InlineFragmentNode,\n OperationDefinitionNode,\n} from 'graphql'\n\nimport {\n getNamedType,\n GraphQLError,\n GraphQLInterfaceType,\n GraphQLObjectType,\n isAbstractType,\n isCompositeType,\n Kind,\n TypeInfo,\n ValidationContext,\n visit,\n visitWithTypeInfo,\n} from 'graphql'\nimport {\n getArgumentValues,\n getDirectiveValues,\n getVariableValues,\n} from 'graphql/execution/values.js'\n\nexport type ComplexityEstimatorArgs = {\n args: { [key: string]: any }\n childComplexity: number\n context?: Record<string, any>\n field: GraphQLField<any, any>\n node: FieldNode\n type: GraphQLCompositeType\n}\n\nexport type ComplexityEstimator = (options: ComplexityEstimatorArgs) => number | void\n\n// Complexity can be anything that is supported by the configured estimators\nexport type Complexity = any\n\n// Map of complexities for possible types (of Union, Interface types)\ntype ComplexityMap = {\n [typeName: string]: number\n}\n\nexport interface QueryComplexityOptions {\n // Pass request context to the estimators via estimationContext\n context?: Record<string, any>\n\n // The query variables. This is needed because the variables are not available\n // Optional function to create a custom error\n createError?: (max: number, actual: number) => GraphQLError\n\n // An array of complexity estimators to use for estimating the complexity\n estimators: Array<ComplexityEstimator>\n\n // Optional callback function to retrieve the determined query complexity\n // Will be invoked whether the query is rejected or not\n // The maximum allowed query complexity, queries above this threshold will be rejected\n maximumComplexity: number\n\n // This can be used for logging or to implement rate limiting\n onComplete?: (complexity: number) => void\n\n // specify operation name only when pass multi-operation documents\n operationName?: string\n\n // in the visitor of the graphql-js library\n variables?: Record<string, any>\n}\n\nfunction queryComplexityMessage(max: number, actual: number): string {\n return `The query exceeds the maximum complexity of ${max}. ` + `Actual complexity is ${actual}`\n}\n\nexport function getComplexity(options: {\n context?: Record<string, any>\n estimators: ComplexityEstimator[]\n operationName?: string\n query: DocumentNode\n schema: GraphQLSchema\n variables?: Record<string, any>\n}): number {\n const typeInfo = new TypeInfo(options.schema)\n\n const errors: GraphQLError[] = []\n const context = new ValidationContext(options.schema, options.query, typeInfo, (error) =>\n errors.push(error),\n )\n const visitor = new QueryComplexity(context, {\n // Maximum complexity does not matter since we're only interested in the calculated complexity.\n context: options.context,\n estimators: options.estimators,\n maximumComplexity: Infinity,\n operationName: options.operationName,\n variables: options.variables,\n })\n\n visit(options.query, visitWithTypeInfo(typeInfo, visitor))\n\n // Throw first error if any\n if (errors.length) {\n throw errors.pop()\n }\n\n return visitor.complexity\n}\n\nexport class QueryComplexity {\n complexity: number\n context: ValidationContext\n estimators: Array<ComplexityEstimator>\n includeDirectiveDef: GraphQLDirective\n OperationDefinition: Record<string, any>\n options: QueryComplexityOptions\n requestContext?: Record<string, any>\n skipDirectiveDef: GraphQLDirective\n variableValues: Record<string, any>\n\n constructor(context: ValidationContext, options: QueryComplexityOptions) {\n if (!(typeof options.maximumComplexity === 'number' && options.maximumComplexity > 0)) {\n throw new Error('Maximum query complexity must be a positive number')\n }\n\n this.context = context\n this.complexity = 0\n this.options = options\n\n this.includeDirectiveDef = this.context.getSchema().getDirective('include')\n this.skipDirectiveDef = this.context.getSchema().getDirective('skip')\n this.estimators = options.estimators\n this.variableValues = {}\n this.requestContext = options.context\n\n this.OperationDefinition = {\n enter: this.onOperationDefinitionEnter,\n leave: this.onOperationDefinitionLeave,\n }\n }\n\n createError(): GraphQLError {\n if (typeof this.options.createError === 'function') {\n return this.options.createError(this.options.maximumComplexity, this.complexity)\n }\n return new GraphQLError(queryComplexityMessage(this.options.maximumComplexity, this.complexity))\n }\n\n nodeComplexity(\n node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode,\n typeDef: GraphQLInterfaceType | GraphQLObjectType | GraphQLUnionType,\n ): number {\n if (node.selectionSet) {\n let fields: GraphQLFieldMap<any, any> = {}\n if (typeDef instanceof GraphQLObjectType || typeDef instanceof GraphQLInterfaceType) {\n fields = typeDef.getFields()\n }\n\n // Determine all possible types of the current node\n let possibleTypeNames: string[]\n if (isAbstractType(typeDef)) {\n possibleTypeNames = this.context\n .getSchema()\n .getPossibleTypes(typeDef)\n .map((t) => t.name)\n } else {\n possibleTypeNames = [typeDef.name]\n }\n\n // Collect complexities for all possible types individually\n const selectionSetComplexities: ComplexityMap = node.selectionSet.selections.reduce(\n (\n complexities: ComplexityMap,\n childNode: FieldNode | FragmentSpreadNode | InlineFragmentNode,\n ): ComplexityMap => {\n // let nodeComplexity = 0;\n let innerComplexities = complexities\n\n let includeNode = true\n let skipNode = false\n\n for (const directive of childNode.directives ?? []) {\n const directiveName = directive.name.value\n switch (directiveName) {\n case 'include': {\n const values = getDirectiveValues(\n this.includeDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n includeNode = values.if\n }\n break\n }\n case 'skip': {\n const values = getDirectiveValues(\n this.skipDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n skipNode = values.if\n }\n break\n }\n }\n }\n\n if (!includeNode || skipNode) {\n return complexities\n }\n\n switch (childNode.kind) {\n case Kind.FIELD: {\n const field = fields[childNode.name.value]\n // Invalid field, should be caught by other validation rules\n if (!field) {\n break\n }\n const fieldType = getNamedType(field.type)\n\n // Get arguments\n let args: { [key: string]: any }\n try {\n args = getArgumentValues(field, childNode, this.variableValues || {})\n } catch (e) {\n this.context.reportError(e)\n return complexities\n }\n\n // Check if we have child complexity\n let childComplexity = 0\n if (isCompositeType(fieldType)) {\n childComplexity = this.nodeComplexity(childNode, fieldType)\n }\n\n // Run estimators one after another and return first valid complexity\n // score\n const estimatorArgs: ComplexityEstimatorArgs = {\n type: typeDef,\n args,\n childComplexity,\n context: this.requestContext,\n field,\n node: childNode,\n }\n const validScore = this.estimators.find((estimator) => {\n const tmpComplexity = estimator(estimatorArgs)\n\n if (typeof tmpComplexity === 'number' && !isNaN(tmpComplexity)) {\n innerComplexities = addComplexities(\n tmpComplexity,\n complexities,\n possibleTypeNames,\n )\n return true\n }\n\n return false\n })\n if (!validScore) {\n this.context.reportError(\n new GraphQLError(\n `No complexity could be calculated for field ${typeDef.name}.${field.name}. ` +\n 'At least one complexity estimator has to return a complexity score.',\n ),\n )\n return complexities\n }\n break\n }\n case Kind.FRAGMENT_SPREAD: {\n const fragment = this.context.getFragment(childNode.name.value)\n // Unknown fragment, should be caught by other validation rules\n if (!fragment) {\n break\n }\n const fragmentType = this.context\n .getSchema()\n .getType(fragment.typeCondition.name.value)\n // Invalid fragment type, ignore. Should be caught by other validation rules\n if (!isCompositeType(fragmentType)) {\n break\n }\n const nodeComplexity = this.nodeComplexity(fragment, fragmentType)\n if (isAbstractType(fragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(fragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n fragmentType.name,\n ])\n }\n break\n }\n case Kind.INLINE_FRAGMENT: {\n let inlineFragmentType: GraphQLNamedType = typeDef\n if (childNode.typeCondition && childNode.typeCondition.name) {\n inlineFragmentType = this.context\n .getSchema()\n .getType(childNode.typeCondition.name.value)\n if (!isCompositeType(inlineFragmentType)) {\n break\n }\n }\n\n const nodeComplexity = this.nodeComplexity(childNode, inlineFragmentType)\n if (isAbstractType(inlineFragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(inlineFragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n inlineFragmentType.name,\n ])\n }\n break\n }\n default: {\n innerComplexities = addComplexities(\n this.nodeComplexity(childNode, typeDef),\n complexities,\n possibleTypeNames,\n )\n break\n }\n }\n\n return innerComplexities\n },\n {},\n )\n // Only return max complexity of all possible types\n if (!selectionSetComplexities) {\n return NaN\n }\n return Math.max(...Object.values(selectionSetComplexities), 0)\n }\n return 0\n }\n\n onOperationDefinitionEnter(operation: OperationDefinitionNode): void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n // Get variable values from variables that are passed from options, merged\n // with default values defined in the operation\n const { coerced, errors } = getVariableValues(\n this.context.getSchema(),\n // We have to create a new array here because input argument is not readonly in graphql ~14.6.0\n operation.variableDefinitions ? [...operation.variableDefinitions] : [],\n this.options.variables ?? {},\n )\n if (errors && errors.length) {\n // We have input validation errors, report errors and abort\n errors.forEach((error) => this.context.reportError(error))\n return\n }\n this.variableValues = coerced\n\n switch (operation.operation) {\n case 'mutation':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getMutationType(),\n )\n break\n case 'query':\n this.complexity += this.nodeComplexity(operation, this.context.getSchema().getQueryType())\n break\n case 'subscription':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getSubscriptionType(),\n )\n break\n default:\n throw new Error(\n `Query complexity could not be calculated for operation of type ${operation.operation}`,\n )\n }\n }\n\n onOperationDefinitionLeave(operation: OperationDefinitionNode): GraphQLError | void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n if (this.options.onComplete) {\n this.options.onComplete(this.complexity)\n }\n\n if (this.complexity > this.options.maximumComplexity) {\n return this.context.reportError(this.createError())\n }\n }\n}\n\n/**\n * Adds a complexity to the complexity map for all possible types\n * @param complexity\n * @param complexityMap\n * @param possibleTypes\n */\nfunction addComplexities(\n complexity: number,\n complexityMap: ComplexityMap,\n possibleTypes: string[],\n): ComplexityMap {\n for (const type of possibleTypes) {\n if (Object.prototype.hasOwnProperty.call(complexityMap, type)) {\n complexityMap[type] += complexity\n } else {\n complexityMap[type] = complexity\n }\n }\n return complexityMap\n}\n"],"names":["getNamedType","GraphQLError","GraphQLInterfaceType","GraphQLObjectType","isAbstractType","isCompositeType","Kind","TypeInfo","ValidationContext","visit","visitWithTypeInfo","getArgumentValues","getDirectiveValues","getVariableValues","queryComplexityMessage","max","actual","getComplexity","options","typeInfo","schema","errors","context","query","error","push","visitor","QueryComplexity","estimators","maximumComplexity","Infinity","operationName","variables","length","pop","complexity","includeDirectiveDef","OperationDefinition","requestContext","skipDirectiveDef","variableValues","constructor","Error","getSchema","getDirective","enter","onOperationDefinitionEnter","leave","onOperationDefinitionLeave","createError","nodeComplexity","node","typeDef","selectionSet","fields","getFields","possibleTypeNames","getPossibleTypes","map","t","name","selectionSetComplexities","selections","reduce","complexities","childNode","innerComplexities","includeNode","skipNode","directive","directives","directiveName","value","values","if","kind","FIELD","field","fieldType","type","args","e","reportError","childComplexity","estimatorArgs","validScore","find","estimator","tmpComplexity","isNaN","addComplexities","FRAGMENT_SPREAD","fragment","getFragment","fragmentType","getType","typeCondition","INLINE_FRAGMENT","inlineFragmentType","NaN","Math","Object","operation","coerced","variableDefinitions","forEach","getMutationType","getQueryType","getSubscriptionType","onComplete","complexityMap","possibleTypes","prototype","hasOwnProperty","call"],"mappings":"AAAA,qDAAqD,GAErD,+DAA+D,GAC/D;;CAEC,GAkBD,SACEA,YAAY,EACZC,YAAY,EACZC,oBAAoB,EACpBC,iBAAiB,EACjBC,cAAc,EACdC,eAAe,EACfC,IAAI,EACJC,QAAQ,EACRC,iBAAiB,EACjBC,KAAK,EACLC,iBAAiB,QACZ,UAAS;AAChB,SACEC,iBAAiB,EACjBC,kBAAkB,EAClBC,iBAAiB,QACZ,8BAA6B;AA+CpC,SAASC,uBAAuBC,GAAW,E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BAAiB,EAAE;YACpD,OAAO,IAAI,CAACP,OAAO,CAAC4D,WAAW,CAAC,IAAI,CAACjC,WAAW;QAClD;IACF;AACF;AAEA;;;;;CAKC,GACD,SAASyC,gBACPvD,UAAkB,EAClB2E,aAA4B,EAC5BC,aAAuB;IAEvB,KAAK,MAAMhC,QAAQgC,cAAe;QAChC,IAAIV,OAAOW,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,eAAe/B,OAAO;YAC7D+B,aAAa,CAAC/B,KAAK,IAAI5C;QACzB,OAAO;YACL2E,aAAa,CAAC/B,KAAK,GAAG5C;QACxB;IACF;IACA,OAAO2E;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ValidationContext } from 'graphql';
|
|
2
2
|
import type { QueryComplexityOptions } from './QueryComplexity.js';
|
|
3
|
-
import QueryComplexity from './QueryComplexity.js';
|
|
3
|
+
import { QueryComplexity } from './QueryComplexity.js';
|
|
4
4
|
export declare function createComplexityRule(options: QueryComplexityOptions): (context: ValidationContext) => QueryComplexity;
|
|
5
5
|
//# sourceMappingURL=createComplexityRule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createComplexityRule.d.ts","sourceRoot":"","sources":["../../../src/packages/graphql-query-complexity/createComplexityRule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAElE,OAAO,eAAe,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"createComplexityRule.d.ts","sourceRoot":"","sources":["../../../src/packages/graphql-query-complexity/createComplexityRule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAElE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,sBAAsB,GAC9B,CAAC,OAAO,EAAE,iBAAiB,KAAK,eAAe,CAIjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/packages/graphql-query-complexity/createComplexityRule.ts"],"sourcesContent":["import type { ValidationContext } from 'graphql'\n\nimport type { QueryComplexityOptions } from './QueryComplexity.js'\n\nimport QueryComplexity from './QueryComplexity.js'\n\nexport function createComplexityRule(\n options: QueryComplexityOptions,\n): (context: ValidationContext) => QueryComplexity {\n return (context: ValidationContext): QueryComplexity => {\n return new QueryComplexity(context, options)\n }\n}\n"],"names":["QueryComplexity","createComplexityRule","options","context"],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"sources":["../../../src/packages/graphql-query-complexity/createComplexityRule.ts"],"sourcesContent":["import type { ValidationContext } from 'graphql'\n\nimport type { QueryComplexityOptions } from './QueryComplexity.js'\n\nimport { QueryComplexity } from './QueryComplexity.js'\n\nexport function createComplexityRule(\n options: QueryComplexityOptions,\n): (context: ValidationContext) => QueryComplexity {\n return (context: ValidationContext): QueryComplexity => {\n return new QueryComplexity(context, options)\n }\n}\n"],"names":["QueryComplexity","createComplexityRule","options","context"],"mappings":"AAIA,SAASA,eAAe,QAAQ,uBAAsB;AAEtD,OAAO,SAASC,qBACdC,OAA+B;IAE/B,OAAO,CAACC;QACN,OAAO,IAAIH,gBAAgBG,SAASD;IACtC;AACF"}
|
|
@@ -18,18 +18,18 @@ function parseObject(typeName, ast, variables) {
|
|
|
18
18
|
}
|
|
19
19
|
function parseLiteral(typeName, ast, variables) {
|
|
20
20
|
switch(ast.kind){
|
|
21
|
-
case Kind.STRING:
|
|
22
21
|
case Kind.BOOLEAN:
|
|
22
|
+
case Kind.STRING:
|
|
23
23
|
return ast.value;
|
|
24
|
-
case Kind.INT:
|
|
25
24
|
case Kind.FLOAT:
|
|
25
|
+
case Kind.INT:
|
|
26
26
|
return parseFloat(ast.value);
|
|
27
|
-
case Kind.OBJECT:
|
|
28
|
-
return parseObject(typeName, ast, variables);
|
|
29
27
|
case Kind.LIST:
|
|
30
28
|
return ast.values.map((n)=>parseLiteral(typeName, n, variables));
|
|
31
29
|
case Kind.NULL:
|
|
32
30
|
return null;
|
|
31
|
+
case Kind.OBJECT:
|
|
32
|
+
return parseObject(typeName, ast, variables);
|
|
33
33
|
case Kind.VARIABLE:
|
|
34
34
|
return variables ? variables[ast.name.value] : undefined;
|
|
35
35
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/packages/graphql-type-json/index.ts"],"sourcesContent":["import { GraphQLScalarType } from 'graphql'\nimport { Kind, print } from 'graphql/language/index.js'\n\nfunction identity(value) {\n return value\n}\n\nfunction ensureObject(value) {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(`JSONObject cannot represent non-object value: ${value}`)\n }\n\n return value\n}\n\nfunction parseObject(typeName, ast, variables) {\n const value = Object.create(null)\n ast.fields.forEach((field) => {\n value[field.name.value] = parseLiteral(typeName, field.value, variables)\n })\n\n return value\n}\n\nfunction parseLiteral(typeName, ast, variables) {\n switch (ast.kind) {\n case Kind.
|
|
1
|
+
{"version":3,"sources":["../../../src/packages/graphql-type-json/index.ts"],"sourcesContent":["import { GraphQLScalarType } from 'graphql'\nimport { Kind, print } from 'graphql/language/index.js'\n\nfunction identity(value) {\n return value\n}\n\nfunction ensureObject(value) {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(`JSONObject cannot represent non-object value: ${value}`)\n }\n\n return value\n}\n\nfunction parseObject(typeName, ast, variables) {\n const value = Object.create(null)\n ast.fields.forEach((field) => {\n value[field.name.value] = parseLiteral(typeName, field.value, variables)\n })\n\n return value\n}\n\nfunction parseLiteral(typeName, ast, variables) {\n switch (ast.kind) {\n case Kind.BOOLEAN:\n case Kind.STRING:\n return ast.value\n case Kind.FLOAT:\n case Kind.INT:\n return parseFloat(ast.value)\n case Kind.LIST:\n return ast.values.map((n) => parseLiteral(typeName, n, variables))\n case Kind.NULL:\n return null\n case Kind.OBJECT:\n return parseObject(typeName, ast, variables)\n case Kind.VARIABLE:\n return variables ? variables[ast.name.value] : undefined\n default:\n throw new TypeError(`${typeName} cannot represent value: ${print(ast)}`)\n }\n}\n\n// This named export is intended for users of CommonJS. Users of ES modules\n// should instead use the default export.\nexport const GraphQLJSON = new GraphQLScalarType({\n name: 'JSON',\n description:\n 'The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n parseLiteral: (ast, variables) => parseLiteral('JSON', ast, variables),\n parseValue: identity,\n serialize: identity,\n specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n\nexport const GraphQLJSONObject = new GraphQLScalarType({\n name: 'JSONObject',\n description:\n 'The `JSONObject` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n parseLiteral: (ast, variables) => {\n if (ast.kind !== Kind.OBJECT) {\n throw new TypeError(`JSONObject cannot represent non-object value: ${print(ast)}`)\n }\n\n return parseObject('JSONObject', ast, variables)\n },\n parseValue: ensureObject,\n serialize: ensureObject,\n specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n"],"names":["GraphQLScalarType","Kind","print","identity","value","ensureObject","Array","isArray","TypeError","parseObject","typeName","ast","variables","Object","create","fields","forEach","field","name","parseLiteral","kind","BOOLEAN","STRING","FLOAT","INT","parseFloat","LIST","values","map","n","NULL","OBJECT","VARIABLE","undefined","GraphQLJSON","description","parseValue","serialize","specifiedByURL","GraphQLJSONObject"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,IAAI,EAAEC,KAAK,QAAQ,4BAA2B;AAEvD,SAASC,SAASC,KAAK;IACrB,OAAOA;AACT;AAEA,SAASC,aA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QR,KAAKC;IAC5DwB,YAAYjC;IACZkC,WAAWlC;IACXmC,gBAAgB;AAClB,GAAE;AAEF,OAAO,MAAMC,oBAAoB,IAAIvC,kBAAkB;IACrDkB,MAAM;IACNiB,aACE;IACFhB,cAAc,CAACR,KAAKC;QAClB,IAAID,IAAIS,IAAI,KAAKnB,KAAK8B,MAAM,EAAE;YAC5B,MAAM,IAAIvB,UAAU,CAAC,8CAA8C,EAAEN,MAAMS,KAAK,CAAC;QACnF;QAEA,OAAOF,YAAY,cAAcE,KAAKC;IACxC;IACAwB,YAAY/B;IACZgC,WAAWhC;IACXiC,gBAAgB;AAClB,GAAE"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { SanitizedConfig } from 'payload';
|
|
2
2
|
import type { Context } from '../types.js';
|
|
3
|
-
declare function accessResolver(config: SanitizedConfig): (_: any, args: any, context: Context) => Promise<any>;
|
|
4
|
-
export default accessResolver;
|
|
3
|
+
export declare function accessResolver(config: SanitizedConfig): (_: any, args: any, context: Context) => Promise<any>;
|
|
5
4
|
//# sourceMappingURL=access.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAe1C,
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAe1C,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,gCACV,OAAO,kBAelD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { accessOperation, isolateObjectProperty } from 'payload';
|
|
2
|
-
import formatName from '../../utilities/formatName.js';
|
|
2
|
+
import { formatName } from '../../utilities/formatName.js';
|
|
3
3
|
const formatConfigNames = (results, configs)=>{
|
|
4
4
|
const formattedResults = {
|
|
5
5
|
...results
|
|
@@ -13,7 +13,7 @@ const formatConfigNames = (results, configs)=>{
|
|
|
13
13
|
});
|
|
14
14
|
return formattedResults;
|
|
15
15
|
};
|
|
16
|
-
function accessResolver(config) {
|
|
16
|
+
export function accessResolver(config) {
|
|
17
17
|
async function resolver(_, args, context) {
|
|
18
18
|
const options = {
|
|
19
19
|
req: isolateObjectProperty(context.req, 'transactionID')
|
|
@@ -27,6 +27,5 @@ function accessResolver(config) {
|
|
|
27
27
|
}
|
|
28
28
|
return resolver;
|
|
29
29
|
}
|
|
30
|
-
export default accessResolver;
|
|
31
30
|
|
|
32
31
|
//# sourceMappingURL=access.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/auth/access.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport { accessOperation, isolateObjectProperty } from 'payload'\n\nimport type { Context } from '../types.js'\n\nimport formatName from '../../utilities/formatName.js'\nconst formatConfigNames = (results, configs) => {\n const formattedResults = { ...results }\n\n configs.forEach(({ slug }) => {\n const result = { ...(formattedResults[slug] || {}) }\n delete formattedResults[slug]\n formattedResults[formatName(slug)] = result\n })\n\n return formattedResults\n}\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/auth/access.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport { accessOperation, isolateObjectProperty } from 'payload'\n\nimport type { Context } from '../types.js'\n\nimport { formatName } from '../../utilities/formatName.js'\nconst formatConfigNames = (results, configs) => {\n const formattedResults = { ...results }\n\n configs.forEach(({ slug }) => {\n const result = { ...(formattedResults[slug] || {}) }\n delete formattedResults[slug]\n formattedResults[formatName(slug)] = result\n })\n\n return formattedResults\n}\n\nexport function accessResolver(config: SanitizedConfig) {\n async function resolver(_, args, context: Context) {\n const options = {\n req: isolateObjectProperty<any>(context.req, 'transactionID'),\n }\n\n const accessResults = await accessOperation(options)\n\n return {\n ...accessResults,\n ...formatConfigNames(accessResults.collections, config.collections),\n ...formatConfigNames(accessResults.globals, config.globals),\n }\n }\n\n return resolver\n}\n"],"names":["accessOperation","isolateObjectProperty","formatName","formatConfigNames","results","configs","formattedResults","forEach","slug","result","accessResolver","config","resolver","_","args","context","options","req","accessResults","collections","globals"],"mappings":"AAEA,SAASA,eAAe,EAAEC,qBAAqB,QAAQ,UAAS;AAIhE,SAASC,UAAU,QAAQ,gCAA+B;AAC1D,MAAMC,oBAAoB,CAACC,SAASC;IAClC,MAAMC,mBAAmB;QAAE,GAAGF,OAAO;IAAC;IAEtCC,QAAQE,OAAO,CAAC,CAAC,EAAEC,IAAI,EAAE;QACvB,MAAMC,SAAS;YAAE,GAAIH,gBAAgB,CAACE,KAAK,IAAI,CAAC,CAAC;QAAE;QACnD,OAAOF,gBAAgB,CAACE,KAAK;QAC7BF,gBAAgB,CAACJ,WAAWM,MAAM,GAAGC;IACvC;IAEA,OAAOH;AACT;AAEA,OAAO,SAASI,eAAeC,MAAuB;IACpD,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QAC/C,MAAMC,UAAU;YACdC,KAAKhB,sBAA2Bc,QAAQE,GAAG,EAAE;QAC/C;QAEA,MAAMC,gBAAgB,MAAMlB,gBAAgBgB;QAE5C,OAAO;YACL,GAAGE,aAAa;YAChB,GAAGf,kBAAkBe,cAAcC,WAAW,EAAER,OAAOQ,WAAW,CAAC;YACnE,GAAGhB,kBAAkBe,cAAcE,OAAO,EAAET,OAAOS,OAAO,CAAC;QAC7D;IACF;IAEA,OAAOR;AACT"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { Collection } from 'payload';
|
|
2
|
-
declare function
|
|
3
|
-
export default forgotPasswordResolver;
|
|
2
|
+
export declare function forgotPassword(collection: Collection): any;
|
|
4
3
|
//# sourceMappingURL=forgotPassword.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/forgotPassword.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,
|
|
1
|
+
{"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/forgotPassword.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,GAAG,CAkB1D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { forgotPasswordOperation, isolateObjectProperty } from 'payload';
|
|
2
|
-
function
|
|
2
|
+
export function forgotPassword(collection) {
|
|
3
3
|
async function resolver(_, args, context) {
|
|
4
4
|
const options = {
|
|
5
5
|
collection,
|
|
@@ -16,6 +16,5 @@ function forgotPasswordResolver(collection) {
|
|
|
16
16
|
}
|
|
17
17
|
return resolver;
|
|
18
18
|
}
|
|
19
|
-
export default forgotPasswordResolver;
|
|
20
19
|
|
|
21
20
|
//# sourceMappingURL=forgotPassword.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/auth/forgotPassword.ts"],"sourcesContent":["import type { Collection } from 'payload'\n\nimport { forgotPasswordOperation, isolateObjectProperty } from 'payload'\n\nimport type { Context } from '../types.js'\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/auth/forgotPassword.ts"],"sourcesContent":["import type { Collection } from 'payload'\n\nimport { forgotPasswordOperation, isolateObjectProperty } from 'payload'\n\nimport type { Context } from '../types.js'\n\nexport function forgotPassword(collection: Collection): any {\n async function resolver(_, args, context: Context) {\n const options = {\n collection,\n data: {\n email: args.email,\n username: args.username,\n },\n disableEmail: args.disableEmail,\n expiration: args.expiration,\n req: isolateObjectProperty(context.req, 'transactionID'),\n }\n\n await forgotPasswordOperation(options)\n return true\n }\n\n return resolver\n}\n"],"names":["forgotPasswordOperation","isolateObjectProperty","forgotPassword","collection","resolver","_","args","context","options","data","email","username","disableEmail","expiration","req"],"mappings":"AAEA,SAASA,uBAAuB,EAAEC,qBAAqB,QAAQ,UAAS;AAIxE,OAAO,SAASC,eAAeC,UAAsB;IACnD,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QAC/C,MAAMC,UAAU;YACdL;YACAM,MAAM;gBACJC,OAAOJ,KAAKI,KAAK;gBACjBC,UAAUL,KAAKK,QAAQ;YACzB;YACAC,cAAcN,KAAKM,YAAY;YAC/BC,YAAYP,KAAKO,UAAU;YAC3BC,KAAKb,sBAAsBM,QAAQO,GAAG,EAAE;QAC1C;QAEA,MAAMd,wBAAwBQ;QAC9B,OAAO;IACT;IAEA,OAAOJ;AACT"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { Context } from '../types.js';
|
|
2
|
-
declare function
|
|
3
|
-
export default initResolver;
|
|
2
|
+
export declare function init(collection: string): (_: any, args: any, context: Context) => Promise<boolean>;
|
|
4
3
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,wBAAgB,IAAI,CAAC,UAAU,EAAE,MAAM,gCACK,OAAO,sBAUlD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { initOperation, isolateObjectProperty } from 'payload';
|
|
2
|
-
function
|
|
2
|
+
export function init(collection) {
|
|
3
3
|
async function resolver(_, args, context) {
|
|
4
4
|
const options = {
|
|
5
5
|
collection,
|
|
@@ -9,6 +9,5 @@ function initResolver(collection) {
|
|
|
9
9
|
}
|
|
10
10
|
return resolver;
|
|
11
11
|
}
|
|
12
|
-
export default initResolver;
|
|
13
12
|
|
|
14
13
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/auth/init.ts"],"sourcesContent":["import { initOperation, isolateObjectProperty } from 'payload'\n\nimport type { Context } from '../types.js'\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/auth/init.ts"],"sourcesContent":["import { initOperation, isolateObjectProperty } from 'payload'\n\nimport type { Context } from '../types.js'\n\nexport function init(collection: string) {\n async function resolver(_, args, context: Context) {\n const options = {\n collection,\n req: isolateObjectProperty(context.req, 'transactionID'),\n }\n\n return initOperation(options)\n }\n\n return resolver\n}\n"],"names":["initOperation","isolateObjectProperty","init","collection","resolver","_","args","context","options","req"],"mappings":"AAAA,SAASA,aAAa,EAAEC,qBAAqB,QAAQ,UAAS;AAI9D,OAAO,SAASC,KAAKC,UAAkB;IACrC,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QAC/C,MAAMC,UAAU;YACdL;YACAM,KAAKR,sBAAsBM,QAAQE,GAAG,EAAE;QAC1C;QAEA,OAAOT,cAAcQ;IACvB;IAEA,OAAOJ;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,wBAAgB,KAAK,CAAC,UAAU,EAAE,UAAU,GAAG,GAAG,CA8BjD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generatePayloadCookie, isolateObjectProperty, loginOperation } from 'payload';
|
|
2
|
-
function
|
|
2
|
+
export function login(collection) {
|
|
3
3
|
async function resolver(_, args, context) {
|
|
4
4
|
const options = {
|
|
5
5
|
collection,
|
|
@@ -13,8 +13,8 @@ function loginResolver(collection) {
|
|
|
13
13
|
};
|
|
14
14
|
const result = await loginOperation(options);
|
|
15
15
|
const cookie = generatePayloadCookie({
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
collectionAuthConfig: collection.config.auth,
|
|
17
|
+
cookiePrefix: context.req.payload.config.cookiePrefix,
|
|
18
18
|
token: result.token
|
|
19
19
|
});
|
|
20
20
|
context.headers['Set-Cookie'] = cookie;
|
|
@@ -25,6 +25,5 @@ function loginResolver(collection) {
|
|
|
25
25
|
}
|
|
26
26
|
return resolver;
|
|
27
27
|
}
|
|
28
|
-
export default loginResolver;
|
|
29
28
|
|
|
30
29
|
//# sourceMappingURL=login.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/auth/login.ts"],"sourcesContent":["import type { Collection } from 'payload'\n\nimport { generatePayloadCookie, isolateObjectProperty, loginOperation } from 'payload'\n\nimport type { Context } from '../types.js'\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/auth/login.ts"],"sourcesContent":["import type { Collection } from 'payload'\n\nimport { generatePayloadCookie, isolateObjectProperty, loginOperation } from 'payload'\n\nimport type { Context } from '../types.js'\n\nexport function login(collection: Collection): any {\n async function resolver(_, args, context: Context) {\n const options = {\n collection,\n data: {\n email: args.email,\n password: args.password,\n username: args.username,\n },\n depth: 0,\n req: isolateObjectProperty(context.req, 'transactionID'),\n }\n\n const result = await loginOperation(options)\n const cookie = generatePayloadCookie({\n collectionAuthConfig: collection.config.auth,\n cookiePrefix: context.req.payload.config.cookiePrefix,\n token: result.token,\n })\n\n context.headers['Set-Cookie'] = cookie\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return result\n }\n\n return resolver\n}\n"],"names":["generatePayloadCookie","isolateObjectProperty","loginOperation","login","collection","resolver","_","args","context","options","data","email","password","username","depth","req","result","cookie","collectionAuthConfig","config","auth","cookiePrefix","payload","token","headers","removeTokenFromResponses"],"mappings":"AAEA,SAASA,qBAAqB,EAAEC,qBAAqB,EAAEC,cAAc,QAAQ,UAAS;AAItF,OAAO,SAASC,MAAMC,UAAsB;IAC1C,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QAC/C,MAAMC,UAAU;YACdL;YACAM,MAAM;gBACJC,OAAOJ,KAAKI,KAAK;gBACjBC,UAAUL,KAAKK,QAAQ;gBACvBC,UAAUN,KAAKM,QAAQ;YACzB;YACAC,OAAO;YACPC,KAAKd,sBAAsBO,QAAQO,GAAG,EAAE;QAC1C;QAEA,MAAMC,SAAS,MAAMd,eAAeO;QACpC,MAAMQ,SAASjB,sBAAsB;YACnCkB,sBAAsBd,WAAWe,MAAM,CAACC,IAAI;YAC5CC,cAAcb,QAAQO,GAAG,CAACO,OAAO,CAACH,MAAM,CAACE,YAAY;YACrDE,OAAOP,OAAOO,KAAK;QACrB;QAEAf,QAAQgB,OAAO,CAAC,aAAa,GAAGP;QAEhC,IAAIb,WAAWe,MAAM,CAACC,IAAI,CAACK,wBAAwB,EAAE;YACnD,OAAOT,OAAOO,KAAK;QACrB;QAEA,OAAOP;IACT;IAEA,OAAOX;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/logout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/logout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,wBAAgB,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,GAAG,CAkBlD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateExpiredPayloadCookie, isolateObjectProperty, logoutOperation } from 'payload';
|
|
2
|
-
function
|
|
2
|
+
export function logout(collection) {
|
|
3
3
|
async function resolver(_, args, context) {
|
|
4
4
|
const options = {
|
|
5
5
|
collection,
|
|
@@ -7,14 +7,14 @@ function logoutResolver(collection) {
|
|
|
7
7
|
};
|
|
8
8
|
const result = await logoutOperation(options);
|
|
9
9
|
const expiredCookie = generateExpiredPayloadCookie({
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
collectionAuthConfig: collection.config.auth,
|
|
11
|
+
config: context.req.payload.config,
|
|
12
|
+
cookiePrefix: context.req.payload.config.cookiePrefix
|
|
12
13
|
});
|
|
13
14
|
context.headers['Set-Cookie'] = expiredCookie;
|
|
14
15
|
return result;
|
|
15
16
|
}
|
|
16
17
|
return resolver;
|
|
17
18
|
}
|
|
18
|
-
export default logoutResolver;
|
|
19
19
|
|
|
20
20
|
//# sourceMappingURL=logout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/resolvers/auth/logout.ts"],"sourcesContent":["import type { Collection } from 'payload'\n\nimport { generateExpiredPayloadCookie, isolateObjectProperty, logoutOperation } from 'payload'\n\nimport type { Context } from '../types.js'\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/resolvers/auth/logout.ts"],"sourcesContent":["import type { Collection } from 'payload'\n\nimport { generateExpiredPayloadCookie, isolateObjectProperty, logoutOperation } from 'payload'\n\nimport type { Context } from '../types.js'\n\nexport function logout(collection: Collection): any {\n async function resolver(_, args, context: Context) {\n const options = {\n collection,\n req: isolateObjectProperty(context.req, 'transactionID'),\n }\n\n const result = await logoutOperation(options)\n const expiredCookie = generateExpiredPayloadCookie({\n collectionAuthConfig: collection.config.auth,\n config: context.req.payload.config,\n cookiePrefix: context.req.payload.config.cookiePrefix,\n })\n context.headers['Set-Cookie'] = expiredCookie\n return result\n }\n\n return resolver\n}\n"],"names":["generateExpiredPayloadCookie","isolateObjectProperty","logoutOperation","logout","collection","resolver","_","args","context","options","req","result","expiredCookie","collectionAuthConfig","config","auth","payload","cookiePrefix","headers"],"mappings":"AAEA,SAASA,4BAA4B,EAAEC,qBAAqB,EAAEC,eAAe,QAAQ,UAAS;AAI9F,OAAO,SAASC,OAAOC,UAAsB;IAC3C,eAAeC,SAASC,CAAC,EAAEC,IAAI,EAAEC,OAAgB;QAC/C,MAAMC,UAAU;YACdL;YACAM,KAAKT,sBAAsBO,QAAQE,GAAG,EAAE;QAC1C;QAEA,MAAMC,SAAS,MAAMT,gBAAgBO;QACrC,MAAMG,gBAAgBZ,6BAA6B;YACjDa,sBAAsBT,WAAWU,MAAM,CAACC,IAAI;YAC5CD,QAAQN,QAAQE,GAAG,CAACM,OAAO,CAACF,MAAM;YAClCG,cAAcT,QAAQE,GAAG,CAACM,OAAO,CAACF,MAAM,CAACG,YAAY;QACvD;QACAT,QAAQU,OAAO,CAAC,aAAa,GAAGN;QAChC,OAAOD;IACT;IAEA,OAAON;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"me.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/me.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,
|
|
1
|
+
{"version":3,"file":"me.d.ts","sourceRoot":"","sources":["../../../src/resolvers/auth/me.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,wBAAgB,EAAE,CAAC,UAAU,EAAE,UAAU,GAAG,GAAG,CAqB9C"}
|