@payloadcms/graphql 3.0.0-beta.3 → 3.0.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/withOperators.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\nimport type { FieldAffectingData, NumberField, RadioField, SelectField } from 'payload/types'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLString,\n} from 'graphql'\nimport { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars'\nimport { GraphQLJSON } from 'graphql-type-json'\nimport { optionIsObject } from 'payload/types'\n\nimport combineParentName from '../utilities/combineParentName.js'\nimport formatName from '../utilities/formatName.js'\nimport operators from './operators.js'\n\ntype staticTypes =\n | 'checkbox'\n | 'code'\n | 'date'\n | 'email'\n | 'json'\n | 'number'\n | 'point'\n | 'relationship'\n | 'richText'\n | 'text'\n | 'textarea'\n | 'upload'\n\ntype dynamicTypes = 'radio' | 'select'\n\nconst GeoJSONObject = new GraphQLInputObjectType({\n name: 'GeoJSONObject',\n fields: {\n type: { type: GraphQLString },\n coordinates: {\n type: GraphQLJSON,\n },\n },\n})\n\ntype DefaultsType = {\n [key in staticTypes]: {\n operators: {\n name: string\n type: ((field: FieldAffectingData, parentName: string) => GraphQLType) | GraphQLType\n }[]\n }\n} & {\n [key in dynamicTypes]: {\n operators: {\n name: string\n type: (field: FieldAffectingData, parentName: string) => GraphQLType\n }[]\n }\n}\n\nconst defaults: DefaultsType = {\n checkbox: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLBoolean,\n })),\n ],\n },\n code: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n date: {\n operators: [\n ...[...operators.equality, ...operators.comparison, 'like'].map((operator) => ({\n name: operator,\n type: DateTimeResolver,\n })),\n ],\n },\n email: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: EmailAddressResolver,\n })),\n ],\n },\n json: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.geojson].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n number: {\n operators: [\n ...[...operators.equality, ...operators.comparison].map((operator) => ({\n name: operator,\n type: (field: NumberField): GraphQLType => {\n return field?.name === 'id' ? GraphQLInt : GraphQLFloat\n },\n })),\n ],\n },\n point: {\n operators: [\n ...[...operators.equality, ...operators.comparison, ...operators.geo].map((operator) => ({\n name: operator,\n type: new GraphQLList(GraphQLFloat),\n })),\n ...operators.geojson.map((operator) => ({\n name: operator,\n /**\n * @example:\n * within: {\n * type: \"Polygon\",\n * coordinates: [[\n * [0.0, 0.0],\n * [1.0, 1.0],\n * [1.0, 0.0],\n * [0.0, 0.0],\n * ]],\n * }\n * @example\n * intersects: {\n * type: \"Point\",\n * coordinates: [ 0.5, 0.5 ]\n * }\n */\n type: GeoJSONObject,\n })),\n ],\n },\n radio: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: (field: RadioField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n relationship: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n richText: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n select: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: (field: SelectField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n text: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n textarea: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n upload: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n // array: n/a\n // group: n/a\n // row: n/a\n // collapsible: n/a\n // tabs: n/a\n}\n\nconst listOperators = ['in', 'not_in', 'all']\n\nconst gqlTypeCache: Record<string, GraphQLType> = {}\n\n/**\n * In GraphQL, you can use \"where\" as an argument to filter a collection. Example:\n * { Posts(where: { title: { equals: \"Hello\" } }) { text } }\n * This function defines the operators for a field's condition in the \"where\" argument of the collection (it thus gets called for every field).\n * For example, in the example above, it would control that\n * - \"equals\" is a valid operator for the \"title\" field\n * - the accepted type of the \"equals\" argument has to be a string.\n *\n * @param field the field for which their valid operators inside a \"where\" argument is being defined\n * @param parentName the name of the parent field (if any)\n * @returns all the operators (including their types) which can be used as a condition for a given field inside a where\n */\nexport const withOperators = (\n field: FieldAffectingData,\n parentName: string,\n): GraphQLInputObjectType => {\n if (!defaults?.[field.type]) throw new Error(`Error: ${field.type} has no defaults configured.`)\n\n const name = `${combineParentName(parentName, field.name)}_operator`\n\n // Get the default operators for the field type which are hard-coded above\n const fieldOperators = [...defaults[field.type].operators]\n\n if (!('required' in field) || !field.required) {\n fieldOperators.push({\n name: 'exists',\n type: fieldOperators[0].type,\n })\n }\n\n return new GraphQLInputObjectType({\n name,\n fields: fieldOperators.reduce((objectTypeFields, operator) => {\n // Get the type of the operator. It can be either static, or dynamic (=> a function)\n let gqlType: GraphQLType =\n typeof operator.type === 'function' ? operator.type(field, parentName) : operator.type\n\n // GraphQL does not allow types with duplicate names, so we use this cache to avoid that.\n // Without this, select and radio fields would have the same name, and GraphQL would throw an error\n // This usually only happens if a custom type is returned from the operator.type function\n if (typeof operator.type === 'function' && 'name' in gqlType) {\n if (gqlTypeCache[gqlType.name]) {\n gqlType = gqlTypeCache[gqlType.name]\n } else {\n gqlTypeCache[gqlType.name] = gqlType\n }\n }\n\n if (listOperators.includes(operator.name)) {\n gqlType = new GraphQLList(gqlType)\n } else if (operator.name === 'exists') {\n gqlType = GraphQLBoolean\n }\n\n return {\n ...objectTypeFields,\n [operator.name]: {\n type: gqlType,\n },\n }\n }, {}),\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLString","DateTimeResolver","EmailAddressResolver","GraphQLJSON","optionIsObject","combineParentName","formatName","operators","GeoJSONObject","name","fields","type","coordinates","defaults","checkbox","equality","map","operator","code","partial","date","comparison","email","contains","json","geojson","number","field","point","geo","radio","parentName","values","options","reduce","option","value","relationship","richText","select","text","textarea","upload","listOperators","gqlTypeCache","withOperators","Error","fieldOperators","required","push","objectTypeFields","gqlType","includes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,CAACA,MAAMqB,QAAQ,EAAE;QAC7CD,eAAeE,IAAI,CAAC;YAClBxC,MAAM;YACNE,MAAMoC,cAAc,CAAC,EAAE,CAACpC,IAAI;QAC9B;IACF;IAEA,OAAO,IAAId,uBAAuB;QAChCY;QACAC,QAAQqC,eAAeb,MAAM,CAAC,CAACgB,kBAAkBjC;YAC/C,oFAAoF;YACpF,IAAIkC,UACF,OAAOlC,SAASN,IAAI,KAAK,aAAaM,SAASN,IAAI,CAACgB,OAAOI,cAAcd,SAASN,IAAI;YAExF,yFAAyF;YACzF,mGAAmG;YACnG,yFAAyF;YACzF,IAAI,OAAOM,SAASN,IAAI,KAAK,cAAc,UAAUwC,SAAS;gBAC5D,IAAIP,YAAY,CAACO,QAAQ1C,IAAI,CAAC,EAAE;oBAC9B0C,UAAUP,YAAY,CAACO,QAAQ1C,IAAI,CAAC;gBACtC,OAAO;oBACLmC,YAAY,CAACO,QAAQ1C,IAAI,CAAC,GAAG0C;gBAC/B;YACF;YAEA,IAAIR,cAAcS,QAAQ,CAACnC,SAASR,IAAI,GAAG;gBACzC0C,UAAU,IAAIpD,YAAYoD;YAC5B,OAAO,IAAIlC,SAASR,IAAI,KAAK,UAAU;gBACrC0C,UAAUzD;YACZ;YAEA,OAAO;gBACL,GAAGwD,gBAAgB;gBACnB,CAACjC,SAASR,IAAI,CAAC,EAAE;oBACfE,MAAMwC;gBACR;YACF;QACF,GAAG,CAAC;IACN;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/schema/withOperators.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\nimport type { FieldAffectingData, NumberField, RadioField, SelectField } from 'payload/types'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLString,\n} from 'graphql'\nimport { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars'\nimport { optionIsObject } from 'payload/types'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport combineParentName from '../utilities/combineParentName.js'\nimport formatName from '../utilities/formatName.js'\nimport operators from './operators.js'\n\ntype staticTypes =\n | 'checkbox'\n | 'code'\n | 'date'\n | 'email'\n | 'json'\n | 'number'\n | 'point'\n | 'relationship'\n | 'richText'\n | 'text'\n | 'textarea'\n | 'upload'\n\ntype dynamicTypes = 'radio' | 'select'\n\nconst GeoJSONObject = new GraphQLInputObjectType({\n name: 'GeoJSONObject',\n fields: {\n type: { type: GraphQLString },\n coordinates: {\n type: GraphQLJSON,\n },\n },\n})\n\ntype DefaultsType = {\n [key in staticTypes]: {\n operators: {\n name: string\n type: ((field: FieldAffectingData, parentName: string) => GraphQLType) | GraphQLType\n }[]\n }\n} & {\n [key in dynamicTypes]: {\n operators: {\n name: string\n type: (field: FieldAffectingData, parentName: string) => GraphQLType\n }[]\n }\n}\n\nconst defaults: DefaultsType = {\n checkbox: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLBoolean,\n })),\n ],\n },\n code: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n date: {\n operators: [\n ...[...operators.equality, ...operators.comparison, 'like'].map((operator) => ({\n name: operator,\n type: DateTimeResolver,\n })),\n ],\n },\n email: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: EmailAddressResolver,\n })),\n ],\n },\n json: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.geojson].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n number: {\n operators: [\n ...[...operators.equality, ...operators.comparison].map((operator) => ({\n name: operator,\n type: (field: NumberField): GraphQLType => {\n return field?.name === 'id' ? GraphQLInt : GraphQLFloat\n },\n })),\n ],\n },\n point: {\n operators: [\n ...[...operators.equality, ...operators.comparison, ...operators.geo].map((operator) => ({\n name: operator,\n type: new GraphQLList(GraphQLFloat),\n })),\n ...operators.geojson.map((operator) => ({\n name: operator,\n /**\n * @example:\n * within: {\n * type: \"Polygon\",\n * coordinates: [[\n * [0.0, 0.0],\n * [1.0, 1.0],\n * [1.0, 0.0],\n * [0.0, 0.0],\n * ]],\n * }\n * @example\n * intersects: {\n * type: \"Point\",\n * coordinates: [ 0.5, 0.5 ]\n * }\n */\n type: GeoJSONObject,\n })),\n ],\n },\n radio: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: (field: RadioField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n relationship: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n richText: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\n })),\n ],\n },\n select: {\n operators: [\n ...[...operators.equality, ...operators.contains].map((operator) => ({\n name: operator,\n type: (field: SelectField, parentName): GraphQLType =>\n new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Input`,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n }),\n })),\n ],\n },\n text: {\n operators: [\n ...[...operators.equality, ...operators.partial, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n textarea: {\n operators: [\n ...[...operators.equality, ...operators.partial].map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n upload: {\n operators: [\n ...operators.equality.map((operator) => ({\n name: operator,\n type: GraphQLString,\n })),\n ],\n },\n // array: n/a\n // group: n/a\n // row: n/a\n // collapsible: n/a\n // tabs: n/a\n}\n\nconst listOperators = ['in', 'not_in', 'all']\n\nconst gqlTypeCache: Record<string, GraphQLType> = {}\n\n/**\n * In GraphQL, you can use \"where\" as an argument to filter a collection. Example:\n * { Posts(where: { title: { equals: \"Hello\" } }) { text } }\n * This function defines the operators for a field's condition in the \"where\" argument of the collection (it thus gets called for every field).\n * For example, in the example above, it would control that\n * - \"equals\" is a valid operator for the \"title\" field\n * - the accepted type of the \"equals\" argument has to be a string.\n *\n * @param field the field for which their valid operators inside a \"where\" argument is being defined\n * @param parentName the name of the parent field (if any)\n * @returns all the operators (including their types) which can be used as a condition for a given field inside a where\n */\nexport const withOperators = (\n field: FieldAffectingData,\n parentName: string,\n): GraphQLInputObjectType => {\n if (!defaults?.[field.type]) throw new Error(`Error: ${field.type} has no defaults configured.`)\n\n const name = `${combineParentName(parentName, field.name)}_operator`\n\n // Get the default operators for the field type which are hard-coded above\n const fieldOperators = [...defaults[field.type].operators]\n\n if (!('required' in field) || !field.required) {\n fieldOperators.push({\n name: 'exists',\n type: fieldOperators[0].type,\n })\n }\n\n return new GraphQLInputObjectType({\n name,\n fields: fieldOperators.reduce((objectTypeFields, operator) => {\n // Get the type of the operator. It can be either static, or dynamic (=> a function)\n let gqlType: GraphQLType =\n typeof operator.type === 'function' ? operator.type(field, parentName) : operator.type\n\n // GraphQL does not allow types with duplicate names, so we use this cache to avoid that.\n // Without this, select and radio fields would have the same name, and GraphQL would throw an error\n // This usually only happens if a custom type is returned from the operator.type function\n if (typeof operator.type === 'function' && 'name' in gqlType) {\n if (gqlTypeCache[gqlType.name]) {\n gqlType = gqlTypeCache[gqlType.name]\n } else {\n gqlTypeCache[gqlType.name] = gqlType\n }\n }\n\n if (listOperators.includes(operator.name)) {\n gqlType = new GraphQLList(gqlType)\n } else if (operator.name === 'exists') {\n gqlType = GraphQLBoolean\n }\n\n return {\n ...objectTypeFields,\n [operator.name]: {\n type: gqlType,\n },\n }\n }, {}),\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLString","DateTimeResolver","EmailAddressResolver","optionIsObject","GraphQLJSON","combineParentName","formatName","operators","GeoJSONObject","name","fields","type","coordinates","defaults","checkbox","equality","map","operator","code","partial","date","comparison","email","contains","json","geojson","number","field","point","geo","radio","parentName","values","options","reduce","option","value","relationship","richText","select","text","textarea","upload","listOperators","gqlTypeCache","withOperators","Error","fieldOperators","required","push","objectTypeFields","gqlType","includes"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,aAAa,QACR,UAAS;AAChB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,kBAAiB;AACxE,SAASC,cAAc,QAAQ,gBAAe;AAE9C,SAASC,WAAW,QAAQ,yCAAwC;AACpE,OAAOC,uBAAuB,oCAAmC;AACjE,OAAOC,gBAAgB,6BAA4B;AACnD,OAAOC,eAAe,iBAAgB;AAkBtC,MAAMC,gBAAgB,IAAIX,uBAAuB;IAC/CY,MAAM;IACNC,QAAQ;QACNC,MAAM;YAAEA,MAAMX;QAAc;QAC5BY,aAAa;YACXD,MAAMP;QACR;IACF;AACF;AAkBA,MAAMS,WAAyB;IAC7BC,UAAU;QACRP,WAAW;eACNA,UAAUQ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IACN;AACF,EAAC"}
@@ -1,8 +1,8 @@
1
1
  import type { ObjMap } from 'graphql/jsutils/ObjMap.js';
2
2
  import type { GraphQLFieldConfig } from 'graphql/type/definition.js';
3
- import type { PayloadRequest } from 'payload/types';
3
+ import type { PayloadRequestWithData } from 'payload/types';
4
4
  type PayloadContext = {
5
- req: PayloadRequest;
5
+ req: PayloadRequestWithData;
6
6
  };
7
7
  export declare function wrapCustomFields<TSource>(fields: ObjMap<GraphQLFieldConfig<TSource, PayloadContext>>): ObjMap<GraphQLFieldConfig<TSource, PayloadContext>>;
8
8
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"wrapCustomResolver.d.ts","sourceRoot":"","sources":["../../src/utilities/wrapCustomResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAwB,MAAM,4BAA4B,CAAA;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAInD,KAAK,cAAc,GAAG;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA;AAe7C,wBAAgB,gBAAgB,CAAC,OAAO,EACtC,MAAM,EAAE,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,GAC1D,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAOrD"}
1
+ {"version":3,"file":"wrapCustomResolver.d.ts","sourceRoot":"","sources":["../../src/utilities/wrapCustomResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAwB,MAAM,4BAA4B,CAAA;AAC1F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAI3D,KAAK,cAAc,GAAG;IAAE,GAAG,EAAE,sBAAsB,CAAA;CAAE,CAAA;AAerD,wBAAgB,gBAAgB,CAAC,OAAO,EACtC,MAAM,EAAE,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,GAC1D,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAOrD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/wrapCustomResolver.ts"],"sourcesContent":["import type { ObjMap } from 'graphql/jsutils/ObjMap.js'\nimport type { GraphQLFieldConfig, GraphQLFieldResolver } from 'graphql/type/definition.js'\nimport type { PayloadRequest } from 'payload/types'\n\nimport { isolateObjectProperty } from 'payload/utilities'\n\ntype PayloadContext = { req: PayloadRequest }\n\nfunction wrapCustomResolver<TSource, TArgs, TResult>(\n resolver: GraphQLFieldResolver<TSource, PayloadContext, TArgs, TResult>,\n): GraphQLFieldResolver<TSource, PayloadContext, TArgs, TResult> {\n return (source, args, context, info) => {\n return resolver(\n source,\n args,\n { ...context, req: isolateObjectProperty(context.req, 'transactionID') },\n info,\n )\n }\n}\n\nexport function wrapCustomFields<TSource>(\n fields: ObjMap<GraphQLFieldConfig<TSource, PayloadContext>>,\n): ObjMap<GraphQLFieldConfig<TSource, PayloadContext>> {\n for (const key in fields) {\n if (fields[key].resolve) {\n fields[key].resolve = wrapCustomResolver(fields[key].resolve)\n }\n }\n return fields\n}\n"],"names":["isolateObjectProperty","wrapCustomResolver","resolver","source","args","context","info","req","wrapCustomFields","fields","key","resolve"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,qBAAqB,QAAQ,oBAAmB;AAIzD,SAASC,mBACPC,QAAuE;IAEvE,OAAO,CAACC,QAAQC,MAAMC,SAASC;QAC7B,OAAOJ,SACLC,QACAC,MACA;YAAE,GAAGC,OAAO;YAAEE,KAAKP,sBAAsBK,QAAQE,GAAG,EAAE;QAAiB,GACvED;IAEJ;AACF;AAEA,OAAO,SAASE,iBACdC,MAA2D;IAE3D,IAAK,MAAMC,OAAOD,OAAQ;QACxB,IAAIA,MAAM,CAACC,IAAI,CAACC,OAAO,EAAE;YACvBF,MAAM,CAACC,IAAI,CAACC,OAAO,GAAGV,mBAAmBQ,MAAM,CAACC,IAAI,CAACC,OAAO;QAC9D;IACF;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/wrapCustomResolver.ts"],"sourcesContent":["import type { ObjMap } from 'graphql/jsutils/ObjMap.js'\nimport type { GraphQLFieldConfig, GraphQLFieldResolver } from 'graphql/type/definition.js'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { isolateObjectProperty } from 'payload/utilities'\n\ntype PayloadContext = { req: PayloadRequestWithData }\n\nfunction wrapCustomResolver<TSource, TArgs, TResult>(\n resolver: GraphQLFieldResolver<TSource, PayloadContext, TArgs, TResult>,\n): GraphQLFieldResolver<TSource, PayloadContext, TArgs, TResult> {\n return (source, args, context, info) => {\n return resolver(\n source,\n args,\n { ...context, req: isolateObjectProperty(context.req, 'transactionID') },\n info,\n )\n }\n}\n\nexport function wrapCustomFields<TSource>(\n fields: ObjMap<GraphQLFieldConfig<TSource, PayloadContext>>,\n): ObjMap<GraphQLFieldConfig<TSource, PayloadContext>> {\n for (const key in fields) {\n if (fields[key].resolve) {\n fields[key].resolve = wrapCustomResolver(fields[key].resolve)\n }\n }\n return fields\n}\n"],"names":["isolateObjectProperty","wrapCustomResolver","resolver","source","args","context","info","req","wrapCustomFields","fields","key","resolve"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,qBAAqB,QAAQ,oBAAmB;AAIzD,SAASC,mBACPC,QAAuE;IAEvE,OAAO,CAACC,QAAQC,MAAMC,SAASC;QAC7B,OAAOJ,SACLC,QACAC,MACA;YAAE,GAAGC,OAAO;YAAEE,KAAKP,sBAAsBK,QAAQE,GAAG,EAAE;QAAiB,GACvED;IAEJ;AACF;AAEA,OAAO,SAASE,iBACdC,MAA2D;IAE3D,IAAK,MAAMC,OAAOD,OAAQ;QACxB,IAAIA,MAAM,CAACC,IAAI,CAACC,OAAO,EAAE;YACvBF,MAAM,CAACC,IAAI,CAACC,OAAO,GAAGV,mBAAmBQ,MAAM,CAACC,IAAI,CAACC,OAAO;QAC9D;IACF;IACA,OAAOF;AACT"}
package/package.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "name": "@payloadcms/graphql",
3
- "version": "3.0.0-beta.3",
4
- "main": "./dist/index.js",
5
- "types": "./dist/index.d.ts",
6
- "type": "module",
3
+ "version": "3.0.0-beta.30",
7
4
  "homepage": "https://payloadcms.com",
8
5
  "repository": {
9
6
  "type": "git",
10
7
  "url": "https://github.com/payloadcms/payload.git",
11
8
  "directory": "packages/graphql"
12
9
  },
10
+ "type": "module",
13
11
  "exports": {
14
12
  ".": {
15
13
  "import": "./dist/index.js",
@@ -17,27 +15,26 @@
17
15
  "types": "./dist/index.d.ts"
18
16
  }
19
17
  },
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "graphql-scalars": "1.22.2",
25
+ "pluralize": "8.0.0",
26
+ "ts-essentials": "7.0.3"
27
+ },
20
28
  "devDependencies": {
21
29
  "@types/pluralize": "^0.0.33",
22
- "ts-essentials": "7.0.3",
23
- "@payloadcms/eslint-config": "1.1.1",
24
- "payload": "3.0.0-beta.3"
25
- },
26
- "dependencies": {
27
- "graphql": "16.8.1",
28
30
  "graphql-http": "^1.22.0",
29
- "graphql-playground-html": "1.6.30",
30
- "graphql-query-complexity": "0.12.0",
31
- "graphql-scalars": "1.22.2",
32
- "graphql-type-json": "0.3.2",
33
- "pluralize": "8.0.0"
31
+ "@payloadcms/eslint-config": "1.1.1",
32
+ "payload": "3.0.0-beta.30"
34
33
  },
35
34
  "peerDependencies": {
36
- "payload": "3.0.0-beta.3"
35
+ "graphql": "^16.8.1",
36
+ "payload": "3.0.0-beta.30"
37
37
  },
38
- "files": [
39
- "dist"
40
- ],
41
38
  "scripts": {
42
39
  "build": "pnpm build:swc && pnpm build:types",
43
40
  "build:swc": "swc ./src -d ./dist --config-file .swcrc",
package/src/index.ts DELETED
@@ -1,126 +0,0 @@
1
- /* eslint-disable no-param-reassign */
2
- import type { OperationArgs } from 'graphql-http'
3
- import type { GraphQLInfo } from 'payload/config'
4
- import type { SanitizedConfig } from 'payload/types'
5
-
6
- import * as GraphQL from 'graphql'
7
- import {
8
- createComplexityRule,
9
- fieldExtensionsEstimator,
10
- simpleEstimator,
11
- } from 'graphql-query-complexity'
12
-
13
- import accessResolver from './resolvers/auth/access.js'
14
- import buildFallbackLocaleInputType from './schema/buildFallbackLocaleInputType.js'
15
- import buildLocaleInputType from './schema/buildLocaleInputType.js'
16
- import buildPoliciesType from './schema/buildPoliciesType.js'
17
- import initCollections from './schema/initCollections.js'
18
- import initGlobals from './schema/initGlobals.js'
19
- import { wrapCustomFields } from './utilities/wrapCustomResolver.js'
20
-
21
- export async function configToSchema(config: SanitizedConfig): Promise<{
22
- schema: GraphQL.GraphQLSchema
23
- validationRules: (args: OperationArgs<any>) => GraphQL.ValidationRule[]
24
- }> {
25
- const collections = config.collections.reduce((acc, collection) => {
26
- acc[collection.slug] = {
27
- config: collection,
28
- }
29
-
30
- return acc
31
- }, {})
32
-
33
- const globals = {
34
- config: config.globals,
35
- }
36
-
37
- const graphqlResult: GraphQLInfo = {
38
- Mutation: {
39
- name: 'Mutation',
40
- fields: {},
41
- },
42
- Query: {
43
- name: 'Query',
44
- fields: {},
45
- },
46
- collections,
47
- globals,
48
- types: {
49
- arrayTypes: {},
50
- blockInputTypes: {},
51
- blockTypes: {},
52
- groupTypes: {},
53
- tabTypes: {},
54
- },
55
- }
56
-
57
- if (config.localization) {
58
- graphqlResult.types['localeInputType'] = buildLocaleInputType(config.localization)
59
- graphqlResult.types['fallbackLocaleInputType'] = buildFallbackLocaleInputType(
60
- config.localization,
61
- )
62
- }
63
-
64
- initCollections({ config, graphqlResult })
65
- initGlobals({ config, graphqlResult })
66
-
67
- graphqlResult.Query.fields['Access'] = {
68
- type: buildPoliciesType(config),
69
- resolve: accessResolver(config),
70
- }
71
-
72
- if (typeof config.graphQL.queries === 'function') {
73
- const customQueries = config.graphQL.queries(GraphQL, {
74
- ...graphqlResult,
75
- config,
76
- })
77
- graphqlResult.Query = {
78
- ...graphqlResult.Query,
79
- fields: {
80
- ...graphqlResult.Query.fields,
81
- ...wrapCustomFields((customQueries || {}) as never),
82
- },
83
- }
84
- }
85
-
86
- if (typeof config.graphQL.mutations === 'function') {
87
- const customMutations = config.graphQL.mutations(GraphQL, {
88
- ...graphqlResult,
89
- config,
90
- })
91
- graphqlResult.Mutation = {
92
- ...graphqlResult.Mutation,
93
- fields: {
94
- ...graphqlResult.Mutation.fields,
95
- ...wrapCustomFields((customMutations || {}) as never),
96
- },
97
- }
98
- }
99
-
100
- const query = new GraphQL.GraphQLObjectType(graphqlResult.Query)
101
- const mutation = new GraphQL.GraphQLObjectType(graphqlResult.Mutation)
102
-
103
- const schemaToCreate = {
104
- mutation,
105
- query,
106
- }
107
-
108
- const schema = new GraphQL.GraphQLSchema(schemaToCreate)
109
-
110
- const validationRules = (args) => [
111
- createComplexityRule({
112
- estimators: [
113
- fieldExtensionsEstimator(),
114
- simpleEstimator({ defaultComplexity: 1 }), // Fallback if complexity not set
115
- ],
116
- maximumComplexity: config.graphQL.maxComplexity,
117
- variables: args.variableValues,
118
- // onComplete: (complexity) => { console.log('Query Complexity:', complexity); },
119
- }),
120
- ]
121
-
122
- return {
123
- schema,
124
- validationRules,
125
- }
126
- }