@payloadcms/graphql 3.0.0-beta.9 → 3.0.0-canary.6041f49

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.
Files changed (111) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/packages/graphql-query-complexity/QueryComplexity.d.ts +51 -0
  6. package/dist/packages/graphql-query-complexity/QueryComplexity.d.ts.map +1 -0
  7. package/dist/packages/graphql-query-complexity/QueryComplexity.js +270 -0
  8. package/dist/packages/graphql-query-complexity/QueryComplexity.js.map +1 -0
  9. package/dist/packages/graphql-query-complexity/createComplexityRule.d.ts +5 -0
  10. package/dist/packages/graphql-query-complexity/createComplexityRule.d.ts.map +1 -0
  11. package/dist/packages/graphql-query-complexity/createComplexityRule.js +8 -0
  12. package/dist/packages/graphql-query-complexity/createComplexityRule.js.map +1 -0
  13. package/dist/packages/graphql-query-complexity/estimators/fieldExtensions/index.d.ts +3 -0
  14. package/dist/packages/graphql-query-complexity/estimators/fieldExtensions/index.d.ts.map +1 -0
  15. package/dist/packages/graphql-query-complexity/estimators/fieldExtensions/index.js +14 -0
  16. package/dist/packages/graphql-query-complexity/estimators/fieldExtensions/index.js.map +1 -0
  17. package/dist/packages/graphql-query-complexity/estimators/simple/index.d.ts +5 -0
  18. package/dist/packages/graphql-query-complexity/estimators/simple/index.d.ts.map +1 -0
  19. package/dist/packages/graphql-query-complexity/estimators/simple/index.js +8 -0
  20. package/dist/packages/graphql-query-complexity/estimators/simple/index.js.map +1 -0
  21. package/dist/packages/graphql-query-complexity/index.d.ts +4 -0
  22. package/dist/packages/graphql-query-complexity/index.d.ts.map +1 -0
  23. package/dist/packages/graphql-query-complexity/index.js +5 -0
  24. package/dist/packages/graphql-query-complexity/index.js.map +1 -0
  25. package/dist/packages/graphql-type-json/index.d.ts +4 -0
  26. package/dist/packages/graphql-type-json/index.d.ts.map +1 -0
  27. package/dist/packages/graphql-type-json/index.js +64 -0
  28. package/dist/packages/graphql-type-json/index.js.map +1 -0
  29. package/dist/resolvers/collections/count.d.ts +13 -0
  30. package/dist/resolvers/collections/count.d.ts.map +1 -0
  31. package/dist/resolvers/collections/count.js +23 -0
  32. package/dist/resolvers/collections/count.js.map +1 -0
  33. package/dist/resolvers/collections/create.d.ts +2 -2
  34. package/dist/resolvers/collections/create.d.ts.map +1 -1
  35. package/dist/resolvers/collections/create.js.map +1 -1
  36. package/dist/resolvers/collections/delete.d.ts +5 -3
  37. package/dist/resolvers/collections/delete.d.ts.map +1 -1
  38. package/dist/resolvers/collections/delete.js +7 -4
  39. package/dist/resolvers/collections/delete.js.map +1 -1
  40. package/dist/resolvers/collections/docAccess.d.ts +2 -2
  41. package/dist/resolvers/collections/docAccess.d.ts.map +1 -1
  42. package/dist/resolvers/collections/docAccess.js.map +1 -1
  43. package/dist/resolvers/collections/duplicate.d.ts +2 -2
  44. package/dist/resolvers/collections/duplicate.d.ts.map +1 -1
  45. package/dist/resolvers/collections/duplicate.js +1 -0
  46. package/dist/resolvers/collections/duplicate.js.map +1 -1
  47. package/dist/resolvers/collections/find.d.ts +3 -3
  48. package/dist/resolvers/collections/find.d.ts.map +1 -1
  49. package/dist/resolvers/collections/find.js +5 -1
  50. package/dist/resolvers/collections/find.js.map +1 -1
  51. package/dist/resolvers/collections/findByID.d.ts +3 -3
  52. package/dist/resolvers/collections/findByID.d.ts.map +1 -1
  53. package/dist/resolvers/collections/findByID.js +5 -1
  54. package/dist/resolvers/collections/findByID.js.map +1 -1
  55. package/dist/resolvers/collections/findVersionByID.d.ts +3 -4
  56. package/dist/resolvers/collections/findVersionByID.d.ts.map +1 -1
  57. package/dist/resolvers/collections/findVersionByID.js +2 -2
  58. package/dist/resolvers/collections/findVersionByID.js.map +1 -1
  59. package/dist/resolvers/collections/findVersions.d.ts +4 -3
  60. package/dist/resolvers/collections/findVersions.d.ts.map +1 -1
  61. package/dist/resolvers/collections/findVersions.js +7 -4
  62. package/dist/resolvers/collections/findVersions.js.map +1 -1
  63. package/dist/resolvers/collections/restoreVersion.d.ts +2 -2
  64. package/dist/resolvers/collections/restoreVersion.d.ts.map +1 -1
  65. package/dist/resolvers/collections/restoreVersion.js.map +1 -1
  66. package/dist/resolvers/collections/update.d.ts +4 -3
  67. package/dist/resolvers/collections/update.d.ts.map +1 -1
  68. package/dist/resolvers/collections/update.js +7 -4
  69. package/dist/resolvers/collections/update.js.map +1 -1
  70. package/dist/resolvers/globals/docAccess.d.ts +2 -2
  71. package/dist/resolvers/globals/docAccess.d.ts.map +1 -1
  72. package/dist/resolvers/globals/docAccess.js.map +1 -1
  73. package/dist/resolvers/globals/findVersionByID.d.ts +2 -2
  74. package/dist/resolvers/globals/findVersionByID.d.ts.map +1 -1
  75. package/dist/resolvers/globals/findVersionByID.js.map +1 -1
  76. package/dist/resolvers/globals/findVersions.d.ts +2 -2
  77. package/dist/resolvers/globals/findVersions.d.ts.map +1 -1
  78. package/dist/resolvers/globals/findVersions.js.map +1 -1
  79. package/dist/resolvers/globals/restoreVersion.d.ts +2 -2
  80. package/dist/resolvers/globals/restoreVersion.d.ts.map +1 -1
  81. package/dist/resolvers/globals/restoreVersion.js.map +1 -1
  82. package/dist/resolvers/globals/update.d.ts +2 -2
  83. package/dist/resolvers/globals/update.d.ts.map +1 -1
  84. package/dist/resolvers/globals/update.js.map +1 -1
  85. package/dist/resolvers/types.d.ts +2 -2
  86. package/dist/resolvers/types.d.ts.map +1 -1
  87. package/dist/resolvers/types.js.map +1 -1
  88. package/dist/schema/buildMutationInputType.d.ts.map +1 -1
  89. package/dist/schema/buildMutationInputType.js +2 -2
  90. package/dist/schema/buildMutationInputType.js.map +1 -1
  91. package/dist/schema/buildObjectType.d.ts.map +1 -1
  92. package/dist/schema/buildObjectType.js +59 -37
  93. package/dist/schema/buildObjectType.js.map +1 -1
  94. package/dist/schema/buildPoliciesType.js +1 -1
  95. package/dist/schema/buildPoliciesType.js.map +1 -1
  96. package/dist/schema/buildWhereInputType.d.ts.map +1 -1
  97. package/dist/schema/buildWhereInputType.js +1 -1
  98. package/dist/schema/buildWhereInputType.js.map +1 -1
  99. package/dist/schema/fieldToWhereInputSchemaMap.d.ts.map +1 -1
  100. package/dist/schema/fieldToWhereInputSchemaMap.js +1 -2
  101. package/dist/schema/fieldToWhereInputSchemaMap.js.map +1 -1
  102. package/dist/schema/initCollections.d.ts.map +1 -1
  103. package/dist/schema/initCollections.js +31 -6
  104. package/dist/schema/initCollections.js.map +1 -1
  105. package/dist/schema/withOperators.js +1 -1
  106. package/dist/schema/withOperators.js.map +1 -1
  107. package/dist/utilities/wrapCustomResolver.d.ts +2 -2
  108. package/dist/utilities/wrapCustomResolver.d.ts.map +1 -1
  109. package/dist/utilities/wrapCustomResolver.js.map +1 -1
  110. package/package.json +16 -19
  111. package/src/index.ts +0 -126
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { OperationArgs } from 'graphql-http';
2
2
  import type { SanitizedConfig } from 'payload/types';
3
3
  import * as GraphQL from 'graphql';
4
- export declare function configToSchema(config: SanitizedConfig): Promise<{
4
+ export declare function configToSchema(config: SanitizedConfig): {
5
5
  schema: GraphQL.GraphQLSchema;
6
6
  validationRules: (args: OperationArgs<any>) => GraphQL.ValidationRule[];
7
- }>;
7
+ };
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAelC,wBAAsB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC;IACrE,MAAM,EAAE,OAAO,CAAC,aAAa,CAAA;IAC7B,eAAe,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,cAAc,EAAE,CAAA;CACxE,CAAC,CAsGD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAelC,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG;IACvD,MAAM,EAAE,OAAO,CAAC,aAAa,CAAA;IAC7B,eAAe,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,cAAc,EAAE,CAAA;CACxE,CAsGA"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ import * as GraphQL from 'graphql';
2
- import { createComplexityRule, fieldExtensionsEstimator, simpleEstimator } from 'graphql-query-complexity';
2
+ import { createComplexityRule, fieldExtensionsEstimator, simpleEstimator } from './packages/graphql-query-complexity/index.js';
3
3
  import accessResolver from './resolvers/auth/access.js';
4
4
  import buildFallbackLocaleInputType from './schema/buildFallbackLocaleInputType.js';
5
5
  import buildLocaleInputType from './schema/buildLocaleInputType.js';
@@ -7,7 +7,7 @@ import buildPoliciesType from './schema/buildPoliciesType.js';
7
7
  import initCollections from './schema/initCollections.js';
8
8
  import initGlobals from './schema/initGlobals.js';
9
9
  import { wrapCustomFields } from './utilities/wrapCustomResolver.js';
10
- export async function configToSchema(config) {
10
+ export function configToSchema(config) {
11
11
  const collections = config.collections.reduce((acc, collection)=>{
12
12
  acc[collection.slug] = {
13
13
  config: collection
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { OperationArgs } from 'graphql-http'\nimport type { GraphQLInfo } from 'payload/config'\nimport type { SanitizedConfig } from 'payload/types'\n\nimport * as GraphQL from 'graphql'\nimport {\n createComplexityRule,\n fieldExtensionsEstimator,\n simpleEstimator,\n} from 'graphql-query-complexity'\n\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 async function configToSchema(config: SanitizedConfig): Promise<{\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 collections,\n globals,\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAKpC,YAAYA,aAAa,UAAS;AAClC,SACEC,oBAAoB,EACpBC,wBAAwB,EACxBC,eAAe,QACV,2BAA0B;AAEjC,OAAOC,oBAAoB,6BAA4B;AACvD,OAAOC,kCAAkC,2CAA0C;AACnF,OAAOC,0BAA0B,mCAAkC;AACnE,OAAOC,uBAAuB,gCAA+B;AAC7D,OAAOC,qBAAq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AY;YACrD;QACF;IACF;IAEA,IAAI,OAAOvB,OAAOqB,OAAO,CAACG,SAAS,KAAK,YAAY;QAClD,MAAMC,kBAAkBzB,OAAOqB,OAAO,CAACG,SAAS,CAACpC,SAAS;YACxD,GAAGmB,aAAa;YAChBP;QACF;QACAO,cAAcC,QAAQ,GAAG;YACvB,GAAGD,cAAcC,QAAQ;YACzBE,QAAQ;gBACN,GAAGH,cAAcC,QAAQ,CAACE,MAAM;gBAChC,GAAGZ,iBAAkB2B,mBAAmB,CAAC,EAAY;YACvD;QACF;IACF;IAEA,MAAMC,QAAQ,IAAItC,QAAQuC,iBAAiB,CAACpB,cAAcI,KAAK;IAC/D,MAAMiB,WAAW,IAAIxC,QAAQuC,iBAAiB,CAACpB,cAAcC,QAAQ;IAErE,MAAMqB,iBAAiB;QACrBD;QACAF;IACF;IAEA,MAAMI,SAAS,IAAI1C,QAAQ2C,aAAa,CAACF;IAEzC,MAAMG,kBAAkB,CAACC,OAAS;YAChC5C,qBAAqB;gBACnB6C,YAAY;oBACV5C;oBACAC,gBAAgB;wBAAE4C,mBAAmB;oBAAE;iBACxC;gBACDC,mBAAmBpC,OAAOqB,OAAO,CAACgB,aAAa;gBAC/CC,WAAWL,KAAKM,cAAc;YAEhC;SACD;IAED,OAAO;QACLT;QACAE;IACF;AACF"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { OperationArgs } from 'graphql-http'\nimport type { GraphQLInfo } from 'payload/config'\nimport type { SanitizedConfig } from 'payload/types'\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 collections,\n globals,\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAKpC,YAAYA,aAAa,UAAS;AAElC,SACEC,oBAAoB,EACpBC,wBAAwB,EACxBC,eAAe,QACV,+CAA8C;AACrD,OAAOC,oBAAoB,6BAA4B;AACvD,OAAOC,kCAAkC,2CAA0C;AACnF,OAAOC,0BAA0B,mCAAkC;AACnE,OAAOC,uBAAuB,gCAA+B;AAC7D,OAAOC,qBAAqB,8BAA6B;AACzD,OAAOC,iBAAiB,0BAAyB;AACjD,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,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AmB,CAAC,EAAY;YACvD;QACF;IACF;IAEA,MAAMC,QAAQ,IAAItC,QAAQuC,iBAAiB,CAACpB,cAAcI,KAAK;IAC/D,MAAMiB,WAAW,IAAIxC,QAAQuC,iBAAiB,CAACpB,cAAcC,QAAQ;IAErE,MAAMqB,iBAAiB;QACrBD;QACAF;IACF;IAEA,MAAMI,SAAS,IAAI1C,QAAQ2C,aAAa,CAACF;IAEzC,MAAMG,kBAAkB,CAACC,OAAS;YAChC5C,qBAAqB;gBACnB6C,YAAY;oBACV5C;oBACAC,gBAAgB;wBAAE4C,mBAAmB;oBAAE;iBACxC;gBACDC,mBAAmBpC,OAAOqB,OAAO,CAACgB,aAAa;gBAC/CC,WAAWL,KAAKM,cAAc;YAEhC;SACD;IAED,OAAO;QACLT;QACAE;IACF;AACF"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Created by Ivo Meißner on 28.07.17.
3
+ */
4
+ import type { DocumentNode, FieldNode, FragmentDefinitionNode, GraphQLCompositeType, GraphQLDirective, GraphQLField, GraphQLSchema, GraphQLUnionType, InlineFragmentNode, OperationDefinitionNode } from 'graphql';
5
+ import { GraphQLError, GraphQLInterfaceType, GraphQLObjectType, ValidationContext } from 'graphql';
6
+ export type ComplexityEstimatorArgs = {
7
+ args: {
8
+ [key: string]: any;
9
+ };
10
+ childComplexity: number;
11
+ context?: Record<string, any>;
12
+ field: GraphQLField<any, any>;
13
+ node: FieldNode;
14
+ type: GraphQLCompositeType;
15
+ };
16
+ export type ComplexityEstimator = (options: ComplexityEstimatorArgs) => number | void;
17
+ export type Complexity = any;
18
+ export interface QueryComplexityOptions {
19
+ context?: Record<string, any>;
20
+ createError?: (max: number, actual: number) => GraphQLError;
21
+ estimators: Array<ComplexityEstimator>;
22
+ maximumComplexity: number;
23
+ onComplete?: (complexity: number) => void;
24
+ operationName?: string;
25
+ variables?: Record<string, any>;
26
+ }
27
+ export declare function getComplexity(options: {
28
+ context?: Record<string, any>;
29
+ estimators: ComplexityEstimator[];
30
+ operationName?: string;
31
+ query: DocumentNode;
32
+ schema: GraphQLSchema;
33
+ variables?: Record<string, any>;
34
+ }): number;
35
+ export default class QueryComplexity {
36
+ OperationDefinition: Record<string, any>;
37
+ complexity: number;
38
+ context: ValidationContext;
39
+ estimators: Array<ComplexityEstimator>;
40
+ includeDirectiveDef: GraphQLDirective;
41
+ options: QueryComplexityOptions;
42
+ requestContext?: Record<string, any>;
43
+ skipDirectiveDef: GraphQLDirective;
44
+ variableValues: Record<string, any>;
45
+ constructor(context: ValidationContext, options: QueryComplexityOptions);
46
+ createError(): GraphQLError;
47
+ nodeComplexity(node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode, typeDef: GraphQLInterfaceType | GraphQLObjectType | GraphQLUnionType): number;
48
+ onOperationDefinitionEnter(operation: OperationDefinitionNode): void;
49
+ onOperationDefinitionLeave(operation: OperationDefinitionNode): GraphQLError | void;
50
+ }
51
+ //# sourceMappingURL=QueryComplexity.d.ts.map
@@ -0,0 +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,EAAC,MAAM,SAAS,CAAC;AAE1C,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EAGjB,iBAAiB,EAMlB,MAAM,SAAS,CAAA;AAOhB,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,KAAK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AmB,CAAC,CAAA;IACtC,mBAAmB,EAAE,gBAAgB,CAAA;IACrC,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"}
@@ -0,0 +1,270 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-use-before-define */ /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */ /**
2
+ * Created by Ivo Meißner on 28.07.17.
3
+ */ import { GraphQLError, GraphQLInterfaceType, GraphQLObjectType, Kind, TypeInfo, ValidationContext, getNamedType, isAbstractType, isCompositeType, visit, visitWithTypeInfo } from 'graphql';
4
+ import { getArgumentValues, getDirectiveValues, getVariableValues } from 'graphql/execution/values.js';
5
+ function queryComplexityMessage(max, actual) {
6
+ return `The query exceeds the maximum complexity of ${max}. ` + `Actual complexity is ${actual}`;
7
+ }
8
+ export function getComplexity(options) {
9
+ const typeInfo = new TypeInfo(options.schema);
10
+ const errors = [];
11
+ const context = new ValidationContext(options.schema, options.query, typeInfo, (error)=>errors.push(error));
12
+ const visitor = new QueryComplexity(context, {
13
+ // Maximum complexity does not matter since we're only interested in the calculated complexity.
14
+ context: options.context,
15
+ estimators: options.estimators,
16
+ maximumComplexity: Infinity,
17
+ operationName: options.operationName,
18
+ variables: options.variables
19
+ });
20
+ visit(options.query, visitWithTypeInfo(typeInfo, visitor));
21
+ // Throw first error if any
22
+ if (errors.length) {
23
+ throw errors.pop();
24
+ }
25
+ return visitor.complexity;
26
+ }
27
+ export default class QueryComplexity {
28
+ OperationDefinition;
29
+ complexity;
30
+ context;
31
+ estimators;
32
+ includeDirectiveDef;
33
+ options;
34
+ requestContext;
35
+ skipDirectiveDef;
36
+ variableValues;
37
+ constructor(context, options){
38
+ if (!(typeof options.maximumComplexity === 'number' && options.maximumComplexity > 0)) {
39
+ throw new Error('Maximum query complexity must be a positive number');
40
+ }
41
+ this.context = context;
42
+ this.complexity = 0;
43
+ this.options = options;
44
+ this.includeDirectiveDef = this.context.getSchema().getDirective('include');
45
+ this.skipDirectiveDef = this.context.getSchema().getDirective('skip');
46
+ this.estimators = options.estimators;
47
+ this.variableValues = {};
48
+ this.requestContext = options.context;
49
+ this.OperationDefinition = {
50
+ enter: this.onOperationDefinitionEnter,
51
+ leave: this.onOperationDefinitionLeave
52
+ };
53
+ }
54
+ createError() {
55
+ if (typeof this.options.createError === 'function') {
56
+ return this.options.createError(this.options.maximumComplexity, this.complexity);
57
+ }
58
+ return new GraphQLError(queryComplexityMessage(this.options.maximumComplexity, this.complexity));
59
+ }
60
+ nodeComplexity(node, typeDef) {
61
+ if (node.selectionSet) {
62
+ let fields = {};
63
+ if (typeDef instanceof GraphQLObjectType || typeDef instanceof GraphQLInterfaceType) {
64
+ fields = typeDef.getFields();
65
+ }
66
+ // Determine all possible types of the current node
67
+ let possibleTypeNames;
68
+ if (isAbstractType(typeDef)) {
69
+ possibleTypeNames = this.context.getSchema().getPossibleTypes(typeDef).map((t)=>t.name);
70
+ } else {
71
+ possibleTypeNames = [
72
+ typeDef.name
73
+ ];
74
+ }
75
+ // Collect complexities for all possible types individually
76
+ const selectionSetComplexities = node.selectionSet.selections.reduce((complexities, childNode)=>{
77
+ // let nodeComplexity = 0;
78
+ let innerComplexities = complexities;
79
+ let includeNode = true;
80
+ let skipNode = false;
81
+ for (const directive of childNode.directives ?? []){
82
+ const directiveName = directive.name.value;
83
+ switch(directiveName){
84
+ case 'include':
85
+ {
86
+ const values = getDirectiveValues(this.includeDirectiveDef, childNode, this.variableValues || {});
87
+ if (typeof values.if === 'boolean') {
88
+ includeNode = values.if;
89
+ }
90
+ break;
91
+ }
92
+ case 'skip':
93
+ {
94
+ const values = getDirectiveValues(this.skipDirectiveDef, childNode, this.variableValues || {});
95
+ if (typeof values.if === 'boolean') {
96
+ skipNode = values.if;
97
+ }
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ if (!includeNode || skipNode) {
103
+ return complexities;
104
+ }
105
+ switch(childNode.kind){
106
+ case Kind.FIELD:
107
+ {
108
+ const field = fields[childNode.name.value];
109
+ // Invalid field, should be caught by other validation rules
110
+ if (!field) {
111
+ break;
112
+ }
113
+ const fieldType = getNamedType(field.type);
114
+ // Get arguments
115
+ let args;
116
+ try {
117
+ args = getArgumentValues(field, childNode, this.variableValues || {});
118
+ } catch (e) {
119
+ this.context.reportError(e);
120
+ return complexities;
121
+ }
122
+ // Check if we have child complexity
123
+ let childComplexity = 0;
124
+ if (isCompositeType(fieldType)) {
125
+ childComplexity = this.nodeComplexity(childNode, fieldType);
126
+ }
127
+ // Run estimators one after another and return first valid complexity
128
+ // score
129
+ const estimatorArgs = {
130
+ type: typeDef,
131
+ args,
132
+ childComplexity,
133
+ context: this.requestContext,
134
+ field,
135
+ node: childNode
136
+ };
137
+ const validScore = this.estimators.find((estimator)=>{
138
+ const tmpComplexity = estimator(estimatorArgs);
139
+ if (typeof tmpComplexity === 'number' && !isNaN(tmpComplexity)) {
140
+ innerComplexities = addComplexities(tmpComplexity, complexities, possibleTypeNames);
141
+ return true;
142
+ }
143
+ return false;
144
+ });
145
+ if (!validScore) {
146
+ this.context.reportError(new GraphQLError(`No complexity could be calculated for field ${typeDef.name}.${field.name}. ` + 'At least one complexity estimator has to return a complexity score.'));
147
+ return complexities;
148
+ }
149
+ break;
150
+ }
151
+ case Kind.FRAGMENT_SPREAD:
152
+ {
153
+ const fragment = this.context.getFragment(childNode.name.value);
154
+ // Unknown fragment, should be caught by other validation rules
155
+ if (!fragment) {
156
+ break;
157
+ }
158
+ const fragmentType = this.context.getSchema().getType(fragment.typeCondition.name.value);
159
+ // Invalid fragment type, ignore. Should be caught by other validation rules
160
+ if (!isCompositeType(fragmentType)) {
161
+ break;
162
+ }
163
+ const nodeComplexity = this.nodeComplexity(fragment, fragmentType);
164
+ if (isAbstractType(fragmentType)) {
165
+ // Add fragment complexity for all possible types
166
+ innerComplexities = addComplexities(nodeComplexity, complexities, this.context.getSchema().getPossibleTypes(fragmentType).map((t)=>t.name));
167
+ } else {
168
+ // Add complexity for object type
169
+ innerComplexities = addComplexities(nodeComplexity, complexities, [
170
+ fragmentType.name
171
+ ]);
172
+ }
173
+ break;
174
+ }
175
+ case Kind.INLINE_FRAGMENT:
176
+ {
177
+ let inlineFragmentType = typeDef;
178
+ if (childNode.typeCondition && childNode.typeCondition.name) {
179
+ inlineFragmentType = this.context.getSchema().getType(childNode.typeCondition.name.value);
180
+ if (!isCompositeType(inlineFragmentType)) {
181
+ break;
182
+ }
183
+ }
184
+ const nodeComplexity = this.nodeComplexity(childNode, inlineFragmentType);
185
+ if (isAbstractType(inlineFragmentType)) {
186
+ // Add fragment complexity for all possible types
187
+ innerComplexities = addComplexities(nodeComplexity, complexities, this.context.getSchema().getPossibleTypes(inlineFragmentType).map((t)=>t.name));
188
+ } else {
189
+ // Add complexity for object type
190
+ innerComplexities = addComplexities(nodeComplexity, complexities, [
191
+ inlineFragmentType.name
192
+ ]);
193
+ }
194
+ break;
195
+ }
196
+ default:
197
+ {
198
+ innerComplexities = addComplexities(this.nodeComplexity(childNode, typeDef), complexities, possibleTypeNames);
199
+ break;
200
+ }
201
+ }
202
+ return innerComplexities;
203
+ }, {});
204
+ // Only return max complexity of all possible types
205
+ if (!selectionSetComplexities) {
206
+ return NaN;
207
+ }
208
+ return Math.max(...Object.values(selectionSetComplexities), 0);
209
+ }
210
+ return 0;
211
+ }
212
+ onOperationDefinitionEnter(operation) {
213
+ if (typeof this.options.operationName === 'string' && this.options.operationName !== operation.name.value) {
214
+ return;
215
+ }
216
+ // Get variable values from variables that are passed from options, merged
217
+ // with default values defined in the operation
218
+ const { coerced, errors } = getVariableValues(this.context.getSchema(), // We have to create a new array here because input argument is not readonly in graphql ~14.6.0
219
+ operation.variableDefinitions ? [
220
+ ...operation.variableDefinitions
221
+ ] : [], this.options.variables ?? {});
222
+ if (errors && errors.length) {
223
+ // We have input validation errors, report errors and abort
224
+ errors.forEach((error)=>this.context.reportError(error));
225
+ return;
226
+ }
227
+ this.variableValues = coerced;
228
+ switch(operation.operation){
229
+ case 'query':
230
+ this.complexity += this.nodeComplexity(operation, this.context.getSchema().getQueryType());
231
+ break;
232
+ case 'mutation':
233
+ this.complexity += this.nodeComplexity(operation, this.context.getSchema().getMutationType());
234
+ break;
235
+ case 'subscription':
236
+ this.complexity += this.nodeComplexity(operation, this.context.getSchema().getSubscriptionType());
237
+ break;
238
+ default:
239
+ throw new Error(`Query complexity could not be calculated for operation of type ${operation.operation}`);
240
+ }
241
+ }
242
+ onOperationDefinitionLeave(operation) {
243
+ if (typeof this.options.operationName === 'string' && this.options.operationName !== operation.name.value) {
244
+ return;
245
+ }
246
+ if (this.options.onComplete) {
247
+ this.options.onComplete(this.complexity);
248
+ }
249
+ if (this.complexity > this.options.maximumComplexity) {
250
+ return this.context.reportError(this.createError());
251
+ }
252
+ }
253
+ }
254
+ /**
255
+ * Adds a complexity to the complexity map for all possible types
256
+ * @param complexity
257
+ * @param complexityMap
258
+ * @param possibleTypes
259
+ */ function addComplexities(complexity, complexityMap, possibleTypes) {
260
+ for (const type of possibleTypes){
261
+ if (Object.prototype.hasOwnProperty.call(complexityMap, type)) {
262
+ complexityMap[type] += complexity;
263
+ } else {
264
+ complexityMap[type] = complexity;
265
+ }
266
+ }
267
+ return complexityMap;
268
+ }
269
+
270
+ //# sourceMappingURL=QueryComplexity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/packages/graphql-query-complexity/QueryComplexity.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-use-before-define */\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} 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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,SAAS,CAAC,CAAC;QAE7F;IACF;IAEAtD,2BAA2BsD,SAAkC,EAAuB;QAClF,IACE,OAAO,IAAI,CAACpF,OAAO,CAACa,aAAa,KAAK,YACtC,IAAI,CAACb,OAAO,CAACa,aAAa,KAAKuE,UAAU1C,IAAI,CAACY,KAAK,EACnD;YACA;QACF;QAEA,IAAI,IAAI,CAACtD,OAAO,CAAC2F,UAAU,EAAE;YAC3B,IAAI,CAAC3F,OAAO,CAAC2F,UAAU,CAAC,IAAI,CAAC1E,UAAU;QACzC;QAEA,IAAI,IAAI,CAACA,UAAU,GAAG,IAAI,CAACjB,OAAO,CAACW,iBAAiB,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"}
@@ -0,0 +1,5 @@
1
+ import type { ValidationContext } from 'graphql';
2
+ import type { QueryComplexityOptions } from './QueryComplexity.js';
3
+ import QueryComplexity from './QueryComplexity.js';
4
+ export declare function createComplexityRule(options: QueryComplexityOptions): (context: ValidationContext) => QueryComplexity;
5
+ //# sourceMappingURL=createComplexityRule.d.ts.map
@@ -0,0 +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;AAElD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,sBAAsB,GAC9B,CAAC,OAAO,EAAE,iBAAiB,KAAK,eAAe,CAIjD"}
@@ -0,0 +1,8 @@
1
+ import QueryComplexity from './QueryComplexity.js';
2
+ export function createComplexityRule(options) {
3
+ return (context)=>{
4
+ return new QueryComplexity(context, options);
5
+ };
6
+ }
7
+
8
+ //# sourceMappingURL=createComplexityRule.js.map
@@ -0,0 +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"],"rangeMappings":";;;;;","mappings":"AAIA,OAAOA,qBAAqB,uBAAsB;AAElD,OAAO,SAASC,qBACdC,OAA+B;IAE/B,OAAO,CAACC;QACN,OAAO,IAAIH,gBAAgBG,SAASD;IACtC;AACF"}
@@ -0,0 +1,3 @@
1
+ import type { ComplexityEstimator } from '../../QueryComplexity.js';
2
+ export declare const fieldExtensionsEstimator: () => ComplexityEstimator;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/packages/graphql-query-complexity/estimators/fieldExtensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAA2B,MAAM,0BAA0B,CAAA;AAE5F,eAAO,MAAM,wBAAwB,QAAO,mBAW3C,CAAA"}
@@ -0,0 +1,14 @@
1
+ export const fieldExtensionsEstimator = ()=>{
2
+ return (args)=>{
3
+ if (args.field.extensions) {
4
+ // Calculate complexity score
5
+ if (typeof args.field.extensions.complexity === 'number') {
6
+ return args.childComplexity + args.field.extensions.complexity;
7
+ } else if (typeof args.field.extensions.complexity === 'function') {
8
+ return args.field.extensions.complexity(args);
9
+ }
10
+ }
11
+ };
12
+ };
13
+
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/packages/graphql-query-complexity/estimators/fieldExtensions/index.ts"],"sourcesContent":["import type { ComplexityEstimator, ComplexityEstimatorArgs } from '../../QueryComplexity.js'\n\nexport const fieldExtensionsEstimator = (): ComplexityEstimator => {\n return (args: ComplexityEstimatorArgs): number | void => {\n if (args.field.extensions) {\n // Calculate complexity score\n if (typeof args.field.extensions.complexity === 'number') {\n return args.childComplexity + args.field.extensions.complexity\n } else if (typeof args.field.extensions.complexity === 'function') {\n return args.field.extensions.complexity(args)\n }\n }\n }\n}\n"],"names":["fieldExtensionsEstimator","args","field","extensions","complexity","childComplexity"],"rangeMappings":";;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,2BAA2B;IACtC,OAAO,CAACC;QACN,IAAIA,KAAKC,KAAK,CAACC,UAAU,EAAE;YACzB,6BAA6B;YAC7B,IAAI,OAAOF,KAAKC,KAAK,CAACC,UAAU,CAACC,UAAU,KAAK,UAAU;gBACxD,OAAOH,KAAKI,eAAe,GAAGJ,KAAKC,KAAK,CAACC,UAAU,CAACC,UAAU;YAChE,OAAO,IAAI,OAAOH,KAAKC,KAAK,CAACC,UAAU,CAACC,UAAU,KAAK,YAAY;gBACjE,OAAOH,KAAKC,KAAK,CAACC,UAAU,CAACC,UAAU,CAACH;YAC1C;QACF;IACF;AACF,EAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ComplexityEstimator } from '../../QueryComplexity.js';
2
+ export declare const simpleEstimator: (options?: {
3
+ defaultComplexity?: number;
4
+ }) => ComplexityEstimator;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/packages/graphql-query-complexity/estimators/simple/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAA2B,MAAM,0BAA0B,CAAA;AAE5F,eAAO,MAAM,eAAe,aAAc;IAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,mBAM1E,CAAA"}
@@ -0,0 +1,8 @@
1
+ export const simpleEstimator = (options)=>{
2
+ const defaultComplexity = options && typeof options.defaultComplexity === 'number' ? options.defaultComplexity : 1;
3
+ return (args)=>{
4
+ return defaultComplexity + args.childComplexity;
5
+ };
6
+ };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/packages/graphql-query-complexity/estimators/simple/index.ts"],"sourcesContent":["import type { ComplexityEstimator, ComplexityEstimatorArgs } from '../../QueryComplexity.js'\n\nexport const simpleEstimator = (options?: { defaultComplexity?: number }): ComplexityEstimator => {\n const defaultComplexity =\n options && typeof options.defaultComplexity === 'number' ? options.defaultComplexity : 1\n return (args: ComplexityEstimatorArgs): number | void => {\n return defaultComplexity + args.childComplexity\n }\n}\n"],"names":["simpleEstimator","options","defaultComplexity","args","childComplexity"],"rangeMappings":";;;;;","mappings":"AAEA,OAAO,MAAMA,kBAAkB,CAACC;IAC9B,MAAMC,oBACJD,WAAW,OAAOA,QAAQC,iBAAiB,KAAK,WAAWD,QAAQC,iBAAiB,GAAG;IACzF,OAAO,CAACC;QACN,OAAOD,oBAAoBC,KAAKC,eAAe;IACjD;AACF,EAAC"}
@@ -0,0 +1,4 @@
1
+ export { createComplexityRule } from './createComplexityRule.js';
2
+ export { fieldExtensionsEstimator } from './estimators/fieldExtensions/index.js';
3
+ export { simpleEstimator } from './estimators/simple/index.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/graphql-query-complexity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA"}
@@ -0,0 +1,5 @@
1
+ export { createComplexityRule } from './createComplexityRule.js';
2
+ export { fieldExtensionsEstimator } from './estimators/fieldExtensions/index.js';
3
+ export { simpleEstimator } from './estimators/simple/index.js';
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/packages/graphql-query-complexity/index.ts"],"sourcesContent":["export { createComplexityRule } from './createComplexityRule.js'\nexport { fieldExtensionsEstimator } from './estimators/fieldExtensions/index.js'\nexport { simpleEstimator } from './estimators/simple/index.js'\n"],"names":["createComplexityRule","fieldExtensionsEstimator","simpleEstimator"],"rangeMappings":";;","mappings":"AAAA,SAASA,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,wBAAwB,QAAQ,wCAAuC;AAChF,SAASC,eAAe,QAAQ,+BAA8B"}
@@ -0,0 +1,4 @@
1
+ import { GraphQLScalarType } from 'graphql';
2
+ export declare const GraphQLJSON: GraphQLScalarType<any, any>;
3
+ export declare const GraphQLJSONObject: GraphQLScalarType<any, any>;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/graphql-type-json/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAgD3C,eAAO,MAAM,WAAW,6BAQtB,CAAA;AAEF,eAAO,MAAM,iBAAiB,6BAc5B,CAAA"}