@payloadcms/graphql 3.2.3-canary.673b4b5 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/packages/graphql-query-complexity/QueryComplexity.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n/**\n * Created by Ivo Meißner on 28.07.17.\n */\n\nimport type {\n DocumentNode,\n FieldNode,\n FragmentDefinitionNode,\n FragmentSpreadNode,\n GraphQLCompositeType,\n GraphQLDirective,\n GraphQLField,\n GraphQLFieldMap,\n GraphQLNamedType,\n GraphQLSchema,\n GraphQLUnionType,\n InlineFragmentNode,\n OperationDefinitionNode,\n} from 'graphql'\n\nimport {\n getNamedType,\n GraphQLError,\n GraphQLInterfaceType,\n GraphQLObjectType,\n isAbstractType,\n isCompositeType,\n Kind,\n TypeInfo,\n ValidationContext,\n visit,\n visitWithTypeInfo,\n} from 'graphql'\nimport {\n getArgumentValues,\n getDirectiveValues,\n getVariableValues,\n} from 'graphql/execution/values.js'\n\nexport type ComplexityEstimatorArgs = {\n args: { [key: string]: any }\n childComplexity: number\n context?: Record<string, any>\n field: GraphQLField<any, any>\n node: FieldNode\n type: GraphQLCompositeType\n}\n\nexport type ComplexityEstimator = (options: ComplexityEstimatorArgs) => number | void\n\n// Complexity can be anything that is supported by the configured estimators\nexport type Complexity = any\n\n// Map of complexities for possible types (of Union, Interface types)\ntype ComplexityMap = {\n [typeName: string]: number\n}\n\nexport interface QueryComplexityOptions {\n // Pass request context to the estimators via estimationContext\n context?: Record<string, any>\n\n // The query variables. This is needed because the variables are not available\n // Optional function to create a custom error\n createError?: (max: number, actual: number) => GraphQLError\n\n // An array of complexity estimators to use for estimating the complexity\n estimators: Array<ComplexityEstimator>\n\n // Optional callback function to retrieve the determined query complexity\n // Will be invoked whether the query is rejected or not\n // The maximum allowed query complexity, queries above this threshold will be rejected\n maximumComplexity: number\n\n // This can be used for logging or to implement rate limiting\n onComplete?: (complexity: number) => void\n\n // specify operation name only when pass multi-operation documents\n operationName?: string\n\n // in the visitor of the graphql-js library\n variables?: Record<string, any>\n}\n\nfunction queryComplexityMessage(max: number, actual: number): string {\n return `The query exceeds the maximum complexity of ${max}. ` + `Actual complexity is ${actual}`\n}\n\nexport function getComplexity(options: {\n context?: Record<string, any>\n estimators: ComplexityEstimator[]\n operationName?: string\n query: DocumentNode\n schema: GraphQLSchema\n variables?: Record<string, any>\n}): number {\n const typeInfo = new TypeInfo(options.schema)\n\n const errors: GraphQLError[] = []\n const context = new ValidationContext(options.schema, options.query, typeInfo, (error) =>\n errors.push(error),\n )\n const visitor = new QueryComplexity(context, {\n // Maximum complexity does not matter since we're only interested in the calculated complexity.\n context: options.context,\n estimators: options.estimators,\n maximumComplexity: Infinity,\n operationName: options.operationName,\n variables: options.variables,\n })\n\n visit(options.query, visitWithTypeInfo(typeInfo, visitor))\n\n // Throw first error if any\n if (errors.length) {\n throw errors.pop()\n }\n\n return visitor.complexity\n}\n\nexport class QueryComplexity {\n complexity: number\n context: ValidationContext\n estimators: Array<ComplexityEstimator>\n includeDirectiveDef: GraphQLDirective\n OperationDefinition: Record<string, any>\n options: QueryComplexityOptions\n requestContext?: Record<string, any>\n skipDirectiveDef: GraphQLDirective\n variableValues: Record<string, any>\n\n constructor(context: ValidationContext, options: QueryComplexityOptions) {\n if (!(typeof options.maximumComplexity === 'number' && options.maximumComplexity > 0)) {\n throw new Error('Maximum query complexity must be a positive number')\n }\n\n this.context = context\n this.complexity = 0\n this.options = options\n\n this.includeDirectiveDef = this.context.getSchema().getDirective('include')\n this.skipDirectiveDef = this.context.getSchema().getDirective('skip')\n this.estimators = options.estimators\n this.variableValues = {}\n this.requestContext = options.context\n\n this.OperationDefinition = {\n enter: this.onOperationDefinitionEnter,\n leave: this.onOperationDefinitionLeave,\n }\n }\n\n createError(): GraphQLError {\n if (typeof this.options.createError === 'function') {\n return this.options.createError(this.options.maximumComplexity, this.complexity)\n }\n return new GraphQLError(queryComplexityMessage(this.options.maximumComplexity, this.complexity))\n }\n\n nodeComplexity(\n node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode,\n typeDef: GraphQLInterfaceType | GraphQLObjectType | GraphQLUnionType,\n ): number {\n if (node.selectionSet) {\n let fields: GraphQLFieldMap<any, any> = {}\n if (typeDef instanceof GraphQLObjectType || typeDef instanceof GraphQLInterfaceType) {\n fields = typeDef.getFields()\n }\n\n // Determine all possible types of the current node\n let possibleTypeNames: string[]\n if (isAbstractType(typeDef)) {\n possibleTypeNames = this.context\n .getSchema()\n .getPossibleTypes(typeDef)\n .map((t) => t.name)\n } else {\n possibleTypeNames = [typeDef.name]\n }\n\n // Collect complexities for all possible types individually\n const selectionSetComplexities: ComplexityMap = node.selectionSet.selections.reduce(\n (\n complexities: ComplexityMap,\n childNode: FieldNode | FragmentSpreadNode | InlineFragmentNode,\n ): ComplexityMap => {\n // let nodeComplexity = 0;\n let innerComplexities = complexities\n\n let includeNode = true\n let skipNode = false\n\n for (const directive of childNode.directives ?? []) {\n const directiveName = directive.name.value\n switch (directiveName) {\n case 'include': {\n const values = getDirectiveValues(\n this.includeDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n includeNode = values.if\n }\n break\n }\n case 'skip': {\n const values = getDirectiveValues(\n this.skipDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n skipNode = values.if\n }\n break\n }\n }\n }\n\n if (!includeNode || skipNode) {\n return complexities\n }\n\n switch (childNode.kind) {\n case Kind.FIELD: {\n const field = fields[childNode.name.value]\n // Invalid field, should be caught by other validation rules\n if (!field) {\n break\n }\n const fieldType = getNamedType(field.type)\n\n // Get arguments\n let args: { [key: string]: any }\n try {\n args = getArgumentValues(field, childNode, this.variableValues || {})\n } catch (e) {\n this.context.reportError(e)\n return complexities\n }\n\n // Check if we have child complexity\n let childComplexity = 0\n if (isCompositeType(fieldType)) {\n childComplexity = this.nodeComplexity(childNode, fieldType)\n }\n\n // Run estimators one after another and return first valid complexity\n // score\n const estimatorArgs: ComplexityEstimatorArgs = {\n type: typeDef,\n args,\n childComplexity,\n context: this.requestContext,\n field,\n node: childNode,\n }\n const validScore = this.estimators.find((estimator) => {\n const tmpComplexity = estimator(estimatorArgs)\n\n if (typeof tmpComplexity === 'number' && !isNaN(tmpComplexity)) {\n innerComplexities = addComplexities(\n tmpComplexity,\n complexities,\n possibleTypeNames,\n )\n return true\n }\n\n return false\n })\n if (!validScore) {\n this.context.reportError(\n new GraphQLError(\n `No complexity could be calculated for field ${typeDef.name}.${field.name}. ` +\n 'At least one complexity estimator has to return a complexity score.',\n ),\n )\n return complexities\n }\n break\n }\n case Kind.FRAGMENT_SPREAD: {\n const fragment = this.context.getFragment(childNode.name.value)\n // Unknown fragment, should be caught by other validation rules\n if (!fragment) {\n break\n }\n const fragmentType = this.context\n .getSchema()\n .getType(fragment.typeCondition.name.value)\n // Invalid fragment type, ignore. Should be caught by other validation rules\n if (!isCompositeType(fragmentType)) {\n break\n }\n const nodeComplexity = this.nodeComplexity(fragment, fragmentType)\n if (isAbstractType(fragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(fragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n fragmentType.name,\n ])\n }\n break\n }\n case Kind.INLINE_FRAGMENT: {\n let inlineFragmentType: GraphQLNamedType = typeDef\n if (childNode.typeCondition && childNode.typeCondition.name) {\n inlineFragmentType = this.context\n .getSchema()\n .getType(childNode.typeCondition.name.value)\n if (!isCompositeType(inlineFragmentType)) {\n break\n }\n }\n\n const nodeComplexity = this.nodeComplexity(childNode, inlineFragmentType)\n if (isAbstractType(inlineFragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(inlineFragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n inlineFragmentType.name,\n ])\n }\n break\n }\n default: {\n innerComplexities = addComplexities(\n this.nodeComplexity(childNode, typeDef),\n complexities,\n possibleTypeNames,\n )\n break\n }\n }\n\n return innerComplexities\n },\n {},\n )\n // Only return max complexity of all possible types\n if (!selectionSetComplexities) {\n return NaN\n }\n return Math.max(...Object.values(selectionSetComplexities), 0)\n }\n return 0\n }\n\n onOperationDefinitionEnter(operation: OperationDefinitionNode): void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n // Get variable values from variables that are passed from options, merged\n // with default values defined in the operation\n const { coerced, errors } = getVariableValues(\n this.context.getSchema(),\n // We have to create a new array here because input argument is not readonly in graphql ~14.6.0\n operation.variableDefinitions ? [...operation.variableDefinitions] : [],\n this.options.variables ?? {},\n )\n if (errors && errors.length) {\n // We have input validation errors, report errors and abort\n errors.forEach((error) => this.context.reportError(error))\n return\n }\n this.variableValues = coerced\n\n switch (operation.operation) {\n case 'mutation':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getMutationType(),\n )\n break\n case 'query':\n this.complexity += this.nodeComplexity(operation, this.context.getSchema().getQueryType())\n break\n case 'subscription':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getSubscriptionType(),\n )\n break\n default:\n throw new Error(\n `Query complexity could not be calculated for operation of type ${operation.operation}`,\n )\n }\n }\n\n onOperationDefinitionLeave(operation: OperationDefinitionNode): GraphQLError | void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n if (this.options.onComplete) {\n this.options.onComplete(this.complexity)\n }\n\n if (this.complexity > this.options.maximumComplexity) {\n return this.context.reportError(this.createError())\n }\n }\n}\n\n/**\n * Adds a complexity to the complexity map for all possible types\n * @param complexity\n * @param complexityMap\n * @param possibleTypes\n */\nfunction addComplexities(\n complexity: number,\n complexityMap: ComplexityMap,\n possibleTypes: string[],\n): ComplexityMap {\n for (const type of possibleTypes) {\n if (Object.prototype.hasOwnProperty.call(complexityMap, type)) {\n complexityMap[type] += complexity\n } else {\n complexityMap[type] = complexity\n }\n }\n return complexityMap\n}\n"],"names":["getNamedType","GraphQLError","GraphQLInterfaceType","GraphQLObjectType","isAbstractType","isCompositeType","Kind","TypeInfo","ValidationContext","visit","visitWithTypeInfo","getArgumentValues","getDirectiveValues","getVariableValues","queryComplexityMessage","max","actual","getComplexity","options","typeInfo","schema","errors","context","query","error","push","visitor","QueryComplexity","estimators","maximumComplexity","Infinity","operationName","variables","length","pop","complexity","includeDirectiveDef","OperationDefinition","requestContext","skipDirectiveDef","variableValues","constructor","Error","getSchema","getDirective","enter","onOperationDefinitionEnter","leave","onOperationDefinitionLeave","createError","nodeComplexity","node","typeDef","selectionSet","fields","getFields","possibleTypeNames","getPossibleTypes","map","t","name","selectionSetComplexities","selections","reduce","complexities","childNode","innerComplexities","includeNode","skipNode","directive","directives","directiveName","value","values","if","kind","FIELD","field","fieldType","type","args","e","reportError","childComplexity","estimatorArgs","validScore","find","estimator","tmpComplexity","isNaN","addComplexities","FRAGMENT_SPREAD","fragment","getFragment","fragmentType","getType","typeCondition","INLINE_FRAGMENT","inlineFragmentType","NaN","Math","Object","operation","coerced","variableDefinitions","forEach","getMutationType","getQueryType","getSubscriptionType","onComplete","complexityMap","possibleTypes","prototype","hasOwnProperty","call"],"mappings":"AAAA,qDAAqD,GAErD,+DAA+D,GAC/D;;CAEC,GAkBD,SACEA,YAAY,EACZC,YAAY,EACZC,oBAAoB,EACpBC,iBAAiB,EACjBC,cAAc,EACdC,eAAe,EACfC,IAAI,EACJC,QAAQ,EACRC,iBAAiB,EACjBC,KAAK,EACLC,iBAAiB,QACZ,UAAS;AAChB,SACEC,iBAAiB,EACjBC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U;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"}
1
+ {"version":3,"sources":["../../../src/packages/graphql-query-complexity/QueryComplexity.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n/**\n * Created by Ivo Meißner on 28.07.17.\n */\n\nimport type {\n DocumentNode,\n FieldNode,\n FragmentDefinitionNode,\n FragmentSpreadNode,\n GraphQLCompositeType,\n GraphQLDirective,\n GraphQLField,\n GraphQLFieldMap,\n GraphQLNamedType,\n GraphQLSchema,\n GraphQLUnionType,\n InlineFragmentNode,\n OperationDefinitionNode,\n} from 'graphql'\n\nimport {\n getNamedType,\n GraphQLError,\n GraphQLInterfaceType,\n GraphQLObjectType,\n isAbstractType,\n isCompositeType,\n Kind,\n TypeInfo,\n ValidationContext,\n visit,\n visitWithTypeInfo,\n} from 'graphql'\nimport {\n getArgumentValues,\n getDirectiveValues,\n getVariableValues,\n} from 'graphql/execution/values.js'\n\nexport type ComplexityEstimatorArgs = {\n args: { [key: string]: any }\n childComplexity: number\n context?: Record<string, any>\n field: GraphQLField<any, any>\n node: FieldNode\n type: GraphQLCompositeType\n}\n\nexport type ComplexityEstimator = (options: ComplexityEstimatorArgs) => number | void\n\n// Complexity can be anything that is supported by the configured estimators\nexport type Complexity = any\n\n// Map of complexities for possible types (of Union, Interface types)\ntype ComplexityMap = {\n [typeName: string]: number\n}\n\nexport interface QueryComplexityOptions {\n // Pass request context to the estimators via estimationContext\n context?: Record<string, any>\n\n // The query variables. This is needed because the variables are not available\n // Optional function to create a custom error\n createError?: (max: number, actual: number) => GraphQLError\n\n // An array of complexity estimators to use for estimating the complexity\n estimators: Array<ComplexityEstimator>\n\n // Optional callback function to retrieve the determined query complexity\n // Will be invoked whether the query is rejected or not\n // The maximum allowed query complexity, queries above this threshold will be rejected\n maximumComplexity: number\n\n // This can be used for logging or to implement rate limiting\n onComplete?: (complexity: number) => void\n\n // specify operation name only when pass multi-operation documents\n operationName?: string\n\n // in the visitor of the graphql-js library\n variables?: Record<string, any>\n}\n\nfunction queryComplexityMessage(max: number, actual: number): string {\n return `The query exceeds the maximum complexity of ${max}. ` + `Actual complexity is ${actual}`\n}\n\nexport function getComplexity(options: {\n context?: Record<string, any>\n estimators: ComplexityEstimator[]\n operationName?: string\n query: DocumentNode\n schema: GraphQLSchema\n variables?: Record<string, any>\n}): number {\n const typeInfo = new TypeInfo(options.schema)\n\n const errors: GraphQLError[] = []\n const context = new ValidationContext(options.schema, options.query, typeInfo, (error) =>\n errors.push(error),\n )\n const visitor = new QueryComplexity(context, {\n // Maximum complexity does not matter since we're only interested in the calculated complexity.\n context: options.context,\n estimators: options.estimators,\n maximumComplexity: Infinity,\n operationName: options.operationName,\n variables: options.variables,\n })\n\n visit(options.query, visitWithTypeInfo(typeInfo, visitor))\n\n // Throw first error if any\n if (errors.length) {\n throw errors.pop()\n }\n\n return visitor.complexity\n}\n\nexport class QueryComplexity {\n complexity: number\n context: ValidationContext\n estimators: Array<ComplexityEstimator>\n includeDirectiveDef: GraphQLDirective\n OperationDefinition: Record<string, any>\n options: QueryComplexityOptions\n requestContext?: Record<string, any>\n skipDirectiveDef: GraphQLDirective\n variableValues: Record<string, any>\n\n constructor(context: ValidationContext, options: QueryComplexityOptions) {\n if (!(typeof options.maximumComplexity === 'number' && options.maximumComplexity > 0)) {\n throw new Error('Maximum query complexity must be a positive number')\n }\n\n this.context = context\n this.complexity = 0\n this.options = options\n\n this.includeDirectiveDef = this.context.getSchema().getDirective('include')\n this.skipDirectiveDef = this.context.getSchema().getDirective('skip')\n this.estimators = options.estimators\n this.variableValues = {}\n this.requestContext = options.context\n\n this.OperationDefinition = {\n enter: this.onOperationDefinitionEnter,\n leave: this.onOperationDefinitionLeave,\n }\n }\n\n createError(): GraphQLError {\n if (typeof this.options.createError === 'function') {\n return this.options.createError(this.options.maximumComplexity, this.complexity)\n }\n return new GraphQLError(queryComplexityMessage(this.options.maximumComplexity, this.complexity))\n }\n\n nodeComplexity(\n node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode,\n typeDef: GraphQLInterfaceType | GraphQLObjectType | GraphQLUnionType,\n ): number {\n if (node.selectionSet) {\n let fields: GraphQLFieldMap<any, any> = {}\n if (typeDef instanceof GraphQLObjectType || typeDef instanceof GraphQLInterfaceType) {\n fields = typeDef.getFields()\n }\n\n // Determine all possible types of the current node\n let possibleTypeNames: string[]\n if (isAbstractType(typeDef)) {\n possibleTypeNames = this.context\n .getSchema()\n .getPossibleTypes(typeDef)\n .map((t) => t.name)\n } else {\n possibleTypeNames = [typeDef.name]\n }\n\n // Collect complexities for all possible types individually\n const selectionSetComplexities: ComplexityMap = node.selectionSet.selections.reduce(\n (\n complexities: ComplexityMap,\n childNode: FieldNode | FragmentSpreadNode | InlineFragmentNode,\n ): ComplexityMap => {\n // let nodeComplexity = 0;\n let innerComplexities = complexities\n\n let includeNode = true\n let skipNode = false\n\n for (const directive of childNode.directives ?? []) {\n const directiveName = directive.name.value\n switch (directiveName) {\n case 'include': {\n const values = getDirectiveValues(\n this.includeDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n includeNode = values.if\n }\n break\n }\n case 'skip': {\n const values = getDirectiveValues(\n this.skipDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n skipNode = values.if\n }\n break\n }\n }\n }\n\n if (!includeNode || skipNode) {\n return complexities\n }\n\n switch (childNode.kind) {\n case Kind.FIELD: {\n const field = fields[childNode.name.value]\n // Invalid field, should be caught by other validation rules\n if (!field) {\n break\n }\n const fieldType = getNamedType(field.type)\n\n // Get arguments\n let args: { [key: string]: any }\n try {\n args = getArgumentValues(field, childNode, this.variableValues || {})\n } catch (e) {\n this.context.reportError(e)\n return complexities\n }\n\n // Check if we have child complexity\n let childComplexity = 0\n if (isCompositeType(fieldType)) {\n childComplexity = this.nodeComplexity(childNode, fieldType)\n }\n\n // Run estimators one after another and return first valid complexity\n // score\n const estimatorArgs: ComplexityEstimatorArgs = {\n type: typeDef,\n args,\n childComplexity,\n context: this.requestContext,\n field,\n node: childNode,\n }\n const validScore = this.estimators.find((estimator) => {\n const tmpComplexity = estimator(estimatorArgs)\n\n if (typeof tmpComplexity === 'number' && !isNaN(tmpComplexity)) {\n innerComplexities = addComplexities(\n tmpComplexity,\n complexities,\n possibleTypeNames,\n )\n return true\n }\n\n return false\n })\n if (!validScore) {\n this.context.reportError(\n new GraphQLError(\n `No complexity could be calculated for field ${typeDef.name}.${field.name}. ` +\n 'At least one complexity estimator has to return a complexity score.',\n ),\n )\n return complexities\n }\n break\n }\n case Kind.FRAGMENT_SPREAD: {\n const fragment = this.context.getFragment(childNode.name.value)\n // Unknown fragment, should be caught by other validation rules\n if (!fragment) {\n break\n }\n const fragmentType = this.context\n .getSchema()\n .getType(fragment.typeCondition.name.value)\n // Invalid fragment type, ignore. Should be caught by other validation rules\n if (!isCompositeType(fragmentType)) {\n break\n }\n const nodeComplexity = this.nodeComplexity(fragment, fragmentType)\n if (isAbstractType(fragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(fragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n fragmentType.name,\n ])\n }\n break\n }\n case Kind.INLINE_FRAGMENT: {\n let inlineFragmentType: GraphQLNamedType = typeDef\n if (childNode.typeCondition && childNode.typeCondition.name) {\n inlineFragmentType = this.context\n .getSchema()\n .getType(childNode.typeCondition.name.value)\n if (!isCompositeType(inlineFragmentType)) {\n break\n }\n }\n\n const nodeComplexity = this.nodeComplexity(childNode, inlineFragmentType)\n if (isAbstractType(inlineFragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(inlineFragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n inlineFragmentType.name,\n ])\n }\n break\n }\n default: {\n innerComplexities = addComplexities(\n this.nodeComplexity(childNode, typeDef),\n complexities,\n possibleTypeNames,\n )\n break\n }\n }\n\n return innerComplexities\n },\n {},\n )\n // Only return max complexity of all possible types\n if (!selectionSetComplexities) {\n return NaN\n }\n return Math.max(...Object.values(selectionSetComplexities), 0)\n }\n return 0\n }\n\n onOperationDefinitionEnter(operation: OperationDefinitionNode): void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n // Get variable values from variables that are passed from options, merged\n // with default values defined in the operation\n const { coerced, errors } = getVariableValues(\n this.context.getSchema(),\n // We have to create a new array here because input argument is not readonly in graphql ~14.6.0\n operation.variableDefinitions ? [...operation.variableDefinitions] : [],\n this.options.variables ?? {},\n )\n if (errors && errors.length) {\n // We have input validation errors, report errors and abort\n errors.forEach((error) => this.context.reportError(error))\n return\n }\n this.variableValues = coerced\n\n switch (operation.operation) {\n case 'mutation':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getMutationType(),\n )\n break\n case 'query':\n this.complexity += this.nodeComplexity(operation, this.context.getSchema().getQueryType())\n break\n case 'subscription':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getSubscriptionType(),\n )\n break\n default:\n throw new Error(\n `Query complexity could not be calculated for operation of type ${operation.operation}`,\n )\n }\n }\n\n onOperationDefinitionLeave(operation: OperationDefinitionNode): GraphQLError | void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n if (this.options.onComplete) {\n this.options.onComplete(this.complexity)\n }\n\n if (this.complexity > this.options.maximumComplexity) {\n return this.context.reportError(this.createError())\n }\n }\n}\n\n/**\n * Adds a complexity to the complexity map for all possible types\n * @param complexity\n * @param complexityMap\n * @param possibleTypes\n */\nfunction addComplexities(\n complexity: number,\n complexityMap: ComplexityMap,\n possibleTypes: string[],\n): ComplexityMap {\n for (const type of possibleTypes) {\n if (Object.prototype.hasOwnProperty.call(complexityMap, type)) {\n complexityMap[type] += complexity\n } else {\n complexityMap[type] = complexity\n }\n }\n return complexityMap\n}\n"],"names":["getNamedType","GraphQLError","GraphQLInterfaceType","GraphQLObjectType","isAbstractType","isCompositeType","Kind","TypeInfo","ValidationContext","visit","visitWithTypeInfo","getArgumentValues","getDirectiveValues","getVariableValues","queryComplexityMessage","max","actual","getComplexity","options","typeInfo","schema","errors","context","query","error","push","visitor","QueryComplexity","estimators","maximumComplexity","Infinity","operationName","variables","length","pop","complexity","includeDirectiveDef","OperationDefinition","requestContext","skipDirectiveDef","variableValues","constructor","Error","getSchema","getDirective","enter","onOperationDefinitionEnter","leave","onOperationDefinitionLeave","createError","nodeComplexity","node","typeDef","selectionSet","fields","getFields","possibleTypeNames","getPossibleTypes","map","t","name","selectionSetComplexities","selections","reduce","complexities","childNode","innerComplexities","includeNode","skipNode","directive","directives","directiveName","value","values","if","kind","FIELD","field","fieldType","type","args","e","reportError","childComplexity","estimatorArgs","validScore","find","estimator","tmpComplexity","isNaN","addComplexities","FRAGMENT_SPREAD","fragment","getFragment","fragmentType","getType","typeCondition","INLINE_FRAGMENT","inlineFragmentType","NaN","Math","Object","operation","coerced","variableDefinitions","forEach","getMutationType","getQueryType","getSubscriptionType","onComplete","complexityMap","possibleTypes","prototype","hasOwnProperty","call"],"mappings":"AAAA,qDAAqD,GAErD,+DAA+D,GAC/D;;CAEC,GAkBD,SACEA,YAAY,EACZC,YAAY,EACZC,oBAAoB,EACpBC,iBAAiB,EACjBC,cAAc,EACdC,eAAe,EACfC,IAAI,EACJC,QAAQ,EACRC,iBAAiB,EACjBC,KAAK,EACLC,iBAAiB,QACZ,UAAS;AAChB,SACEC,iBAAiB,EACjBC,kBAAkB,EAClBC,iBAAiB,QACZ,8BAA6B;AA+CpC,SAASC,uBAAuBC,GAAW,EAAEC,MAAc;IACzD,OAAO,CAAC,4CAA4C,EAAED,IAAI,EAAE,CAAC,GAAG,CAAC,qBAAqB,EAAEC,QAAQ;AAClG;AAEA,OAAO,SAASC,cAAcC,OAO7B;IACC,MAAMC,WAAW,IAAIZ,SAASW,QAAQE,MAAM;IAE5C,MAAMC,SAAyB,EAAE;IACjC,MAAMC,UAAU,IAAId,kBAAkBU,QAAQE,MAAM,EAAEF,QAAQK,KAAK,EAAEJ,UAAU,CAACK,QAC9EH,OAAOI,IAAI,CAACD;IAEd,MAAME,UAAU,IAAIC,gBAAgBL,SAAS;QAC3C,+FAA+F;QAC/FA,SAASJ,QAAQI,OAAO;QACxBM,YAAYV,QAAQU,UAAU;QAC9BC,mBAAmBC;QACnBC,eAAeb,QAAQa,aAAa;QACpCC,WAAWd,QAAQc,SAAS;IAC9B;IAEAvB,MAAMS,QAAQK,KAAK,EAAEb,kBAAkBS,UAAUO;IAEjD,2BAA2B;IAC3B,IAAIL,OAAOY,MAAM,EAAE;QACjB,MAAMZ,OAAOa,GAAG;IAClB;IAEA,OAAOR,QAAQS,UAAU;AAC3B;AAEA,OAAO,MAAMR;IACXQ,WAAkB;IAClBb,QAA0B;IAC1BM,WAAsC;IACtCQ,oBAAqC;IACrCC,oBAAwC;IACxCnB,QAA+B;IAC/BoB,eAAoC;IACpCC,i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UAAUA,SAAS,EAAE;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"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/packages/graphql-type-json/index.ts"],"sourcesContent":["import { GraphQLScalarType } from 'graphql'\nimport { Kind, print } from 'graphql/language/index.js'\n\nfunction identity(value) {\n return value\n}\n\nfunction ensureObject(value) {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(`JSONObject cannot represent non-object value: ${value}`)\n }\n\n return value\n}\n\nfunction parseObject(typeName, ast, variables) {\n const value = Object.create(null)\n ast.fields.forEach((field) => {\n value[field.name.value] = parseLiteral(typeName, field.value, variables)\n })\n\n return value\n}\n\nfunction parseLiteral(typeName, ast, variables) {\n switch (ast.kind) {\n case Kind.BOOLEAN:\n case Kind.STRING:\n return ast.value\n case Kind.FLOAT:\n case Kind.INT:\n return parseFloat(ast.value)\n case Kind.LIST:\n return ast.values.map((n) => parseLiteral(typeName, n, variables))\n case Kind.NULL:\n return null\n case Kind.OBJECT:\n return parseObject(typeName, ast, variables)\n case Kind.VARIABLE:\n return variables ? variables[ast.name.value] : undefined\n default:\n throw new TypeError(`${typeName} cannot represent value: ${print(ast)}`)\n }\n}\n\n// This named export is intended for users of CommonJS. Users of ES modules\n// should instead use the default export.\nexport const GraphQLJSON = new GraphQLScalarType({\n name: 'JSON',\n description:\n 'The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n parseLiteral: (ast, variables) => parseLiteral('JSON', ast, variables),\n parseValue: identity,\n serialize: identity,\n specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n\nexport const GraphQLJSONObject = new GraphQLScalarType({\n name: 'JSONObject',\n description:\n 'The `JSONObject` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n parseLiteral: (ast, variables) => {\n if (ast.kind !== Kind.OBJECT) {\n throw new TypeError(`JSONObject cannot represent non-object value: ${print(ast)}`)\n }\n\n return parseObject('JSONObject', ast, variables)\n },\n parseValue: ensureObject,\n serialize: ensureObject,\n specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n"],"names":["GraphQLScalarType","Kind","print","identity","value","ensureObject","Array","isArray","TypeError","parseObject","typeName","ast","variables","Object","create","fields","forEach","field","name","parseLiteral","kind","BOOLEAN","STRING","FLOAT","INT","parseFloat","LIST","values","map","n","NULL","OBJECT","VARIABLE","undefined","GraphQLJSON","description","parseValue","serialize","specifiedByURL","GraphQLJSONObject"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,IAAI,EAAEC,KAAK,QAAQ,4BAA2B;AAEvD,S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,aACE;IACFhB,cAAc,CAACR,KAAKC,YAAcO,aAAa,QAAQR,KAAKC;IAC5DwB,YAAYjC;IACZkC,WAAWlC;IACXmC,gBAAgB;AAClB,GAAE;AAEF,OAAO,MAAMC,oBAAoB,IAAIvC,kBAAkB;IACrDkB,MAAM;IACNiB,aACE;IACFhB,cAAc,CAACR,KAAKC;QAClB,IAAID,IAAIS,IAAI,KAAKnB,KAAK8B,MAAM,EAAE;YAC5B,MAAM,IAAIvB,UAAU,CAAC,8CAA8C,EAAEN,MAAMS,KAAK,CAAC;QACnF;QAEA,OAAOF,YAAY,cAAcE,KAAKC;IACxC;IACAwB,YAAY/B;IACZgC,WAAWhC;IACXiC,gBAAgB;AAClB,GAAE"}
1
+ {"version":3,"sources":["../../../src/packages/graphql-type-json/index.ts"],"sourcesContent":["import { GraphQLScalarType } from 'graphql'\nimport { Kind, print } from 'graphql/language/index.js'\n\nfunction identity(value) {\n return value\n}\n\nfunction ensureObject(value) {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(`JSONObject cannot represent non-object value: ${value}`)\n }\n\n return value\n}\n\nfunction parseObject(typeName, ast, variables) {\n const value = Object.create(null)\n ast.fields.forEach((field) => {\n value[field.name.value] = parseLiteral(typeName, field.value, variables)\n })\n\n return value\n}\n\nfunction parseLiteral(typeName, ast, variables) {\n switch (ast.kind) {\n case Kind.BOOLEAN:\n case Kind.STRING:\n return ast.value\n case Kind.FLOAT:\n case Kind.INT:\n return parseFloat(ast.value)\n case Kind.LIST:\n return ast.values.map((n) => parseLiteral(typeName, n, variables))\n case Kind.NULL:\n return null\n case Kind.OBJECT:\n return parseObject(typeName, ast, variables)\n case Kind.VARIABLE:\n return variables ? variables[ast.name.value] : undefined\n default:\n throw new TypeError(`${typeName} cannot represent value: ${print(ast)}`)\n }\n}\n\n// This named export is intended for users of CommonJS. Users of ES modules\n// should instead use the default export.\nexport const GraphQLJSON = new GraphQLScalarType({\n name: 'JSON',\n description:\n 'The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n parseLiteral: (ast, variables) => parseLiteral('JSON', ast, variables),\n parseValue: identity,\n serialize: identity,\n specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n\nexport const GraphQLJSONObject = new GraphQLScalarType({\n name: 'JSONObject',\n description:\n 'The `JSONObject` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n parseLiteral: (ast, variables) => {\n if (ast.kind !== Kind.OBJECT) {\n throw new TypeError(`JSONObject cannot represent non-object value: ${print(ast)}`)\n }\n\n return parseObject('JSONObject', ast, variables)\n },\n parseValue: ensureObject,\n serialize: ensureObject,\n specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n"],"names":["GraphQLScalarType","Kind","print","identity","value","ensureObject","Array","isArray","TypeError","parseObject","typeName","ast","variables","Object","create","fields","forEach","field","name","parseLiteral","kind","BOOLEAN","STRING","FLOAT","INT","parseFloat","LIST","values","map","n","NULL","OBJECT","VARIABLE","undefined","GraphQLJSON","description","parseValue","serialize","specifiedByURL","GraphQLJSONObject"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,IAAI,EAAEC,KAAK,QAAQ,4BAA2B;AAEvD,SAASC,SAASC,KAAK;IACrB,OAAOA;AACT;AAEA,SAASC,aAAaD,KAAK;IACzB,IAAI,OAAOA,UAAU,YAAYA,UAAU,QAAQE,MAAMC,OAAO,CAACH,QAAQ;QACvE,MAAM,IAAII,UAAU,CAAC,8CAA8C,EAAEJ,OAAO;IAC9E;IAEA,OAAOA;AACT;AAEA,SAASK,YAAYC,QAAQ,EAAEC,GAAG,EAAEC,SAAS;IAC3C,MAAMR,QAAQS,OAAOC,MAAM,CAAC;IAC5BH,IAAII,MAAM,CAACC,OAAO,CAAC,CAACC;QAClBb,KAA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xC;IACAwB,YAAY/B;IACZgC,WAAWhC;IACXiC,gBAAgB;AAClB,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/buildMutationInputType.ts"],"sourcesContent":["import type { GraphQLInputFieldConfig, GraphQLScalarType, GraphQLType } from 'graphql'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GraphQLInfo,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLNonNull,\n GraphQLString,\n} from 'graphql'\nimport { flattenTopLevelFields, toWords } from 'payload'\nimport { fieldAffectsData, optionIsObject, tabHasName } from 'payload/shared'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { groupOrTabHasRequiredSubfield } from '../utilities/groupOrTabHasRequiredSubfield.js'\nimport { withNullableType } from './withNullableType.js'\n\nconst idFieldTypes = {\n number: GraphQLInt,\n text: GraphQLString,\n}\n\nexport const getCollectionIDType = (\n type: keyof typeof idFieldTypes,\n collection: SanitizedCollectionConfig,\n): GraphQLScalarType => {\n const idField = flattenTopLevelFields(collection.fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (!idField) {\n return idFieldTypes[type]\n }\n\n return idFieldTypes[idField.type]\n}\n\nexport type InputObjectTypeConfig = {\n [path: string]: GraphQLInputFieldConfig\n}\n\ntype BuildMutationInputTypeArgs = {\n config: SanitizedConfig\n fields: Field[]\n forceNullable?: boolean\n graphqlResult: GraphQLInfo\n name: string\n parentName: string\n}\n\nexport function buildMutationInputType({\n name,\n config,\n fields,\n forceNullable = false,\n graphqlResult,\n parentName,\n}: BuildMutationInputTypeArgs): GraphQLInputObjectType | null {\n const fieldToSchemaMap = {\n array: (inputObjectTypeConfig: InputObjectTypeConfig, field: ArrayField) => {\n const fullName = combineParentName(parentName, toWords(field.name, true))\n let type: GraphQLList<GraphQLType> | GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: field.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) {\n return inputObjectTypeConfig\n }\n\n type = new GraphQLList(withNullableType(field, type, forceNullable))\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n blocks: (inputObjectTypeConfig: InputObjectTypeConfig, field: BlocksField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: GraphQLJSON },\n }),\n checkbox: (inputObjectTypeConfig: InputObjectTypeConfig, field: CheckboxField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: GraphQLBoolean },\n }),\n code: (inputObjectTypeConfig: InputObjectTypeConfig, field: CodeField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n collapsible: (inputObjectTypeConfig: InputObjectTypeConfig, field: CollapsibleField) =>\n field.fields.reduce((acc, subField: CollapsibleField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(acc, subField)\n }\n return acc\n }, inputObjectTypeConfig),\n date: (inputObjectTypeConfig: InputObjectTypeConfig, field: DateField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n email: (inputObjectTypeConfig: InputObjectTypeConfig, field: EmailField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n group: (inputObjectTypeConfig: InputObjectTypeConfig, field: GroupField) => {\n const requiresAtLeastOneField = groupOrTabHasRequiredSubfield(field)\n const fullName = combineParentName(parentName, toWords(field.name, true))\n let type: GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: field.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) {\n return inputObjectTypeConfig\n }\n\n if (requiresAtLeastOneField) {\n type = new GraphQLNonNull(type)\n }\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n json: (inputObjectTypeConfig: InputObjectTypeConfig, field: JSONField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n number: (inputObjectTypeConfig: InputObjectTypeConfig, field: NumberField) => {\n const type = field.name === 'id' ? GraphQLInt : GraphQLFloat\n return {\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(type) : type,\n forceNullable,\n ),\n },\n }\n },\n point: (inputObjectTypeConfig: InputObjectTypeConfig, field: PointField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, new GraphQLList(GraphQLFloat), forceNullable) },\n }),\n radio: (inputObjectTypeConfig: InputObjectTypeConfig, field: RadioField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n relationship: (inputObjectTypeConfig: InputObjectTypeConfig, field: RelationshipField) => {\n const { relationTo } = field\n type PayloadGraphQLRelationshipType =\n | GraphQLInputObjectType\n | GraphQLList<GraphQLScalarType>\n | GraphQLScalarType\n let type: PayloadGraphQLRelationshipType\n\n if (Array.isArray(relationTo)) {\n const fullName = `${combineParentName(\n parentName,\n toWords(field.name, true),\n )}RelationshipInput`\n type = new GraphQLInputObjectType({\n name: fullName,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${fullName}RelationTo`,\n values: relationTo.reduce(\n (values, option) => ({\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n })\n } else {\n type = getCollectionIDType(\n config.db.defaultIDType,\n graphqlResult.collections[relationTo].config,\n )\n }\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type: field.hasMany ? new GraphQLList(type) : type },\n }\n },\n richText: (inputObjectTypeConfig: InputObjectTypeConfig, field: RichTextField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n row: (inputObjectTypeConfig: InputObjectTypeConfig, field: RowField) =>\n field.fields.reduce((acc, subField: Field) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(acc, subField)\n }\n return acc\n }, inputObjectTypeConfig),\n select: (inputObjectTypeConfig: InputObjectTypeConfig, field: SelectField) => {\n const formattedName = `${combineParentName(parentName, field.name)}_MutationInput`\n let type: GraphQLType = new GraphQLEnumType({\n name: formattedName,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n })\n\n type = field.hasMany ? new GraphQLList(type) : type\n type = withNullableType(field, type, forceNullable)\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n tabs: (inputObjectTypeConfig: InputObjectTypeConfig, field: TabsField) => {\n return field.tabs.reduce((acc, tab) => {\n if (tabHasName(tab)) {\n const fullName = combineParentName(parentName, toWords(tab.name, true))\n const requiresAtLeastOneField = groupOrTabHasRequiredSubfield(field)\n let type: GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: tab.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) {\n return acc\n }\n\n if (requiresAtLeastOneField) {\n type = new GraphQLNonNull(type)\n }\n return {\n ...acc,\n [tab.name]: { type },\n }\n }\n\n return {\n ...acc,\n ...tab.fields.reduce((subFieldSchema, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(subFieldSchema, subField)\n }\n return subFieldSchema\n }, acc),\n }\n }, inputObjectTypeConfig)\n },\n text: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextField) => ({\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,\n forceNullable,\n ),\n },\n }),\n textarea: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextareaField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n upload: (inputObjectTypeConfig: InputObjectTypeConfig, field: UploadField) => {\n const { relationTo } = field\n type PayloadGraphQLRelationshipType =\n | GraphQLInputObjectType\n | GraphQLList<GraphQLScalarType>\n | GraphQLScalarType\n let type: PayloadGraphQLRelationshipType\n\n if (Array.isArray(relationTo)) {\n const fullName = `${combineParentName(\n parentName,\n toWords(field.name, true),\n )}RelationshipInput`\n type = new GraphQLInputObjectType({\n name: fullName,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${fullName}RelationTo`,\n values: relationTo.reduce(\n (values, option) => ({\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n })\n } else {\n type = getCollectionIDType(\n config.db.defaultIDType,\n graphqlResult.collections[relationTo].config,\n )\n }\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type: field.hasMany ? new GraphQLList(type) : type },\n }\n },\n }\n\n const fieldName = formatName(name)\n\n const fieldSchemas = fields.reduce((inputObjectTypeConfig, field) => {\n const fieldSchema = fieldToSchemaMap[field.type]\n\n if (typeof fieldSchema !== 'function') {\n return inputObjectTypeConfig\n }\n\n const schema = fieldSchema(inputObjectTypeConfig, field)\n if (Object.keys(schema).length === 0) {\n return inputObjectTypeConfig\n }\n\n return {\n ...inputObjectTypeConfig,\n ...fieldSchema(inputObjectTypeConfig, field),\n }\n }, {})\n\n if (Object.keys(fieldSchemas).length === 0) {\n return null\n }\n\n return new GraphQLInputObjectType({\n name: `mutation${fieldName}Input`,\n fields: fieldSchemas,\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLNonNull","GraphQLString","flattenTopLevelFields","toWords","fieldAffectsData","optionIsObject","tabHasName","GraphQLJSON","combineParentName","formatName","groupOrTabHasRequiredSubfield","withNullableType","idFieldTypes","number","text","getCollectionIDType","type","collection","idField","fields","find","field","name","buildMutationInputType","config","forceNullable","graphqlResult","parentName","fieldToSchemaMap","array","inputObjectTypeConfig","fullName","blocks","checkbox","code","collapsible","reduce","acc","subField","addSubField","date","email","group","requiresAtLeastOneField","json","hasMany","point","radio","relationship","relationTo","Array","isArray","values","option","value","db","defaultIDType","collections","richText","row","select","formattedName","options","tabs","tab","subFieldSchema","textarea","upload","fieldName","fieldSchemas","fieldSchema","schema","Object","keys","length"],"mappings":"AA4BA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,aAAa,QACR,UAAS;AAChB,SAASC,qBAAqB,EAAEC,OAAO,QAAQ,UAAS;AACxD,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,UAAU,QAAQ,iBAAgB;AAE7E,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,6BAA6B,QAAQ,gDAA+C;AAC7F,SAASC,gBAAgB,QAAQ,wBAAuB;AAExD,MAAMC,eAAe;IACnBC,QAAQf;IACRgB,MAAMb;AACR;AAEA,OAAO,MAAMc,sBAAsB,CACjCC,MACAC;IAEA,MAAMC,UAAUhB,sBAAsBe,WAAWE,MAAM,EAAEC,IAAI,CAC3D,CAACC,QAAUjB,iBAAiBiB,UAAUA,MAAMC,IAAI,KAAK;IAGvD,IAAI,CAACJ,SAAS;QACZ,OAAON,YAAY,CAACI,KAAK;IAC3B;IAEA,OAAOJ,YAAY,CAACM,QAAQF,I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AAE8C,UAAU,KAAK,CAAC;QACjCjD,QAAQkD;IACV;AACF"}
1
+ {"version":3,"sources":["../../src/schema/buildMutationInputType.ts"],"sourcesContent":["import type { GraphQLInputFieldConfig, GraphQLScalarType, GraphQLType } from 'graphql'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GraphQLInfo,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInputObjectType,\n GraphQLInt,\n GraphQLList,\n GraphQLNonNull,\n GraphQLString,\n} from 'graphql'\nimport { flattenTopLevelFields, toWords } from 'payload'\nimport { fieldAffectsData, optionIsObject, tabHasName } from 'payload/shared'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { groupOrTabHasRequiredSubfield } from '../utilities/groupOrTabHasRequiredSubfield.js'\nimport { withNullableType } from './withNullableType.js'\n\nconst idFieldTypes = {\n number: GraphQLInt,\n text: GraphQLString,\n}\n\nexport const getCollectionIDType = (\n type: keyof typeof idFieldTypes,\n collection: SanitizedCollectionConfig,\n): GraphQLScalarType => {\n const idField = flattenTopLevelFields(collection.fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (!idField) {\n return idFieldTypes[type]\n }\n\n return idFieldTypes[idField.type]\n}\n\nexport type InputObjectTypeConfig = {\n [path: string]: GraphQLInputFieldConfig\n}\n\ntype BuildMutationInputTypeArgs = {\n config: SanitizedConfig\n fields: Field[]\n forceNullable?: boolean\n graphqlResult: GraphQLInfo\n name: string\n parentName: string\n}\n\nexport function buildMutationInputType({\n name,\n config,\n fields,\n forceNullable = false,\n graphqlResult,\n parentName,\n}: BuildMutationInputTypeArgs): GraphQLInputObjectType | null {\n const fieldToSchemaMap = {\n array: (inputObjectTypeConfig: InputObjectTypeConfig, field: ArrayField) => {\n const fullName = combineParentName(parentName, toWords(field.name, true))\n let type: GraphQLList<GraphQLType> | GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: field.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) {\n return inputObjectTypeConfig\n }\n\n type = new GraphQLList(withNullableType(field, type, forceNullable))\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n blocks: (inputObjectTypeConfig: InputObjectTypeConfig, field: BlocksField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: GraphQLJSON },\n }),\n checkbox: (inputObjectTypeConfig: InputObjectTypeConfig, field: CheckboxField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: GraphQLBoolean },\n }),\n code: (inputObjectTypeConfig: InputObjectTypeConfig, field: CodeField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n collapsible: (inputObjectTypeConfig: InputObjectTypeConfig, field: CollapsibleField) =>\n field.fields.reduce((acc, subField: CollapsibleField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(acc, subField)\n }\n return acc\n }, inputObjectTypeConfig),\n date: (inputObjectTypeConfig: InputObjectTypeConfig, field: DateField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n email: (inputObjectTypeConfig: InputObjectTypeConfig, field: EmailField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n group: (inputObjectTypeConfig: InputObjectTypeConfig, field: GroupField) => {\n const requiresAtLeastOneField = groupOrTabHasRequiredSubfield(field)\n const fullName = combineParentName(parentName, toWords(field.name, true))\n let type: GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: field.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) {\n return inputObjectTypeConfig\n }\n\n if (requiresAtLeastOneField) {\n type = new GraphQLNonNull(type)\n }\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n json: (inputObjectTypeConfig: InputObjectTypeConfig, field: JSONField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n number: (inputObjectTypeConfig: InputObjectTypeConfig, field: NumberField) => {\n const type = field.name === 'id' ? GraphQLInt : GraphQLFloat\n return {\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(type) : type,\n forceNullable,\n ),\n },\n }\n },\n point: (inputObjectTypeConfig: InputObjectTypeConfig, field: PointField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, new GraphQLList(GraphQLFloat), forceNullable) },\n }),\n radio: (inputObjectTypeConfig: InputObjectTypeConfig, field: RadioField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n relationship: (inputObjectTypeConfig: InputObjectTypeConfig, field: RelationshipField) => {\n const { relationTo } = field\n type PayloadGraphQLRelationshipType =\n | GraphQLInputObjectType\n | GraphQLList<GraphQLScalarType>\n | GraphQLScalarType\n let type: PayloadGraphQLRelationshipType\n\n if (Array.isArray(relationTo)) {\n const fullName = `${combineParentName(\n parentName,\n toWords(field.name, true),\n )}RelationshipInput`\n type = new GraphQLInputObjectType({\n name: fullName,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${fullName}RelationTo`,\n values: relationTo.reduce(\n (values, option) => ({\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n })\n } else {\n type = getCollectionIDType(\n config.db.defaultIDType,\n graphqlResult.collections[relationTo].config,\n )\n }\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type: field.hasMany ? new GraphQLList(type) : type },\n }\n },\n richText: (inputObjectTypeConfig: InputObjectTypeConfig, field: RichTextField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n row: (inputObjectTypeConfig: InputObjectTypeConfig, field: RowField) =>\n field.fields.reduce((acc, subField: Field) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(acc, subField)\n }\n return acc\n }, inputObjectTypeConfig),\n select: (inputObjectTypeConfig: InputObjectTypeConfig, field: SelectField) => {\n const formattedName = `${combineParentName(parentName, field.name)}_MutationInput`\n let type: GraphQLType = new GraphQLEnumType({\n name: formattedName,\n values: field.options.reduce((values, option) => {\n if (optionIsObject(option)) {\n return {\n ...values,\n [formatName(option.value)]: {\n value: option.value,\n },\n }\n }\n\n return {\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }\n }, {}),\n })\n\n type = field.hasMany ? new GraphQLList(type) : type\n type = withNullableType(field, type, forceNullable)\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type },\n }\n },\n tabs: (inputObjectTypeConfig: InputObjectTypeConfig, field: TabsField) => {\n return field.tabs.reduce((acc, tab) => {\n if (tabHasName(tab)) {\n const fullName = combineParentName(parentName, toWords(tab.name, true))\n const requiresAtLeastOneField = groupOrTabHasRequiredSubfield(field)\n let type: GraphQLType = buildMutationInputType({\n name: fullName,\n config,\n fields: tab.fields,\n graphqlResult,\n parentName: fullName,\n })\n\n if (!type) {\n return acc\n }\n\n if (requiresAtLeastOneField) {\n type = new GraphQLNonNull(type)\n }\n return {\n ...acc,\n [tab.name]: { type },\n }\n }\n\n return {\n ...acc,\n ...tab.fields.reduce((subFieldSchema, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(subFieldSchema, subField)\n }\n return subFieldSchema\n }, acc),\n }\n }, inputObjectTypeConfig)\n },\n text: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextField) => ({\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,\n forceNullable,\n ),\n },\n }),\n textarea: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextareaField) => ({\n ...inputObjectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n upload: (inputObjectTypeConfig: InputObjectTypeConfig, field: UploadField) => {\n const { relationTo } = field\n type PayloadGraphQLRelationshipType =\n | GraphQLInputObjectType\n | GraphQLList<GraphQLScalarType>\n | GraphQLScalarType\n let type: PayloadGraphQLRelationshipType\n\n if (Array.isArray(relationTo)) {\n const fullName = `${combineParentName(\n parentName,\n toWords(field.name, true),\n )}RelationshipInput`\n type = new GraphQLInputObjectType({\n name: fullName,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${fullName}RelationTo`,\n values: relationTo.reduce(\n (values, option) => ({\n ...values,\n [formatName(option)]: {\n value: option,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n })\n } else {\n type = getCollectionIDType(\n config.db.defaultIDType,\n graphqlResult.collections[relationTo].config,\n )\n }\n\n return {\n ...inputObjectTypeConfig,\n [field.name]: { type: field.hasMany ? new GraphQLList(type) : type },\n }\n },\n }\n\n const fieldName = formatName(name)\n\n const fieldSchemas = fields.reduce((inputObjectTypeConfig, field) => {\n const fieldSchema = fieldToSchemaMap[field.type]\n\n if (typeof fieldSchema !== 'function') {\n return inputObjectTypeConfig\n }\n\n const schema = fieldSchema(inputObjectTypeConfig, field)\n if (Object.keys(schema).length === 0) {\n return inputObjectTypeConfig\n }\n\n return {\n ...inputObjectTypeConfig,\n ...fieldSchema(inputObjectTypeConfig, field),\n }\n }, {})\n\n if (Object.keys(fieldSchemas).length === 0) {\n return null\n }\n\n return new GraphQLInputObjectType({\n name: `mutation${fieldName}Input`,\n fields: fieldSchemas,\n })\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInputObjectType","GraphQLInt","GraphQLList","GraphQLNonNull","GraphQLString","flattenTopLevelFields","toWords","fieldAffectsData","optionIsObject","tabHasName","GraphQLJSON","combineParentName","formatName","groupOrTabHasRequiredSubfield","withNullableType","idFieldTypes","number","text","getCollectionIDType","type","collection","idField","fields","find","field","name","buildMutationInputType","config","forceNullable","graphqlResult","parentName","fieldToSchemaMap","array","inputObjectTypeConfig","fullName","blocks","checkbox","code","collapsible","reduce","acc","subField","addSubField","date","email","group","requiresAtLeastOneField","json","hasMany","point","radio","relationship","relationTo","Array","isArray","values","option","value","db","defaultIDType","collections","richText","row","select","formattedName","options","tabs","tab","subFieldSchema","textarea","upload","fieldName","fieldSchemas","fieldSchema","schema","Object","keys","length"],"mappings":"AA4BA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,aAAa,QACR,UAAS;AAChB,SAASC,qBAAqB,EAAEC,OAAO,QAAQ,UAAS;AACxD,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,UAAU,QAAQ,iBAAgB;AAE7E,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,6BAA6B,QAAQ,gDAA+C;AAC7F,SAASC,gBAAgB,QAAQ,wBAAuB;AAExD,MAAMC,eAAe;IACnBC,QAAQf;IACRgB,MAAMb;AACR;AAEA,OAAO,MAAMc,sBAAsB,CACjCC,MACAC;IAEA,MAAMC,UAAUhB,sBAAsBe,WAAWE,MAAM,EAAEC,IAAI,CAC3D,CAACC,QAAUjB,iBAAiBiB,UAAUA,MAAMC,IAAI,KAAK;IAGvD,IAAI,CAACJ,SAAS;QACZ,OAAON,YAAY,CAACI,KAAK;IAC3B;IAEA,OAAOJ,YAAY,CAACM,QAAQF,IAAI,CAAC;AACnC,EAAC;A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"}
@@ -264,6 +264,7 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
264
264
  }
265
265
  });
266
266
  } else {
267
+ ;
267
268
  ({ type } = graphqlResult.collections[relationTo].graphQL);
268
269
  }
269
270
  // If the relationshipType is undefined at this point,
@@ -554,6 +555,7 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
554
555
  }
555
556
  });
556
557
  } else {
558
+ ;
557
559
  ({ type } = graphqlResult.collections[relationTo].graphQL);
558
560
  }
559
561
  // If the relationshipType is undefined at this point,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/buildObjectType.ts"],"sourcesContent":["import type { GraphQLFieldConfig, GraphQLType } from 'graphql'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GraphQLInfo,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextAdapter,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInt,\n GraphQLList,\n GraphQLNonNull,\n GraphQLObjectType,\n GraphQLString,\n GraphQLUnionType,\n} from 'graphql'\nimport { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars'\nimport { combineQueries, createDataloaderCacheKey, MissingEditorProp, toWords } from 'payload'\nimport { tabHasName } from 'payload/shared'\n\nimport type { Context } from '../resolvers/types.js'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { formatOptions } from '../utilities/formatOptions.js'\nimport { isFieldNullable } from './isFieldNullable.js'\nimport { withNullableType } from './withNullableType.js'\n\nexport type ObjectTypeConfig = {\n [path: string]: GraphQLFieldConfig<any, any>\n}\n\ntype Args = {\n baseFields?: ObjectTypeConfig\n config: SanitizedConfig\n fields: Field[]\n forceNullable?: boolean\n graphqlResult: GraphQLInfo\n name: string\n parentName: string\n}\n\nexport function buildObjectType({\n name,\n baseFields = {},\n config,\n fields,\n forceNullable,\n graphqlResult,\n parentName,\n}: Args): GraphQLObjectType {\n const fieldToSchemaMap = {\n array: (objectTypeConfig: ObjectTypeConfig, field: ArrayField) => {\n const interfaceName =\n field?.interfaceName || combineParentName(parentName, toWords(field.name, true))\n\n if (!graphqlResult.types.arrayTypes[interfaceName]) {\n const objectType = buildObjectType({\n name: interfaceName,\n config,\n fields: field.fields,\n forceNullable: isFieldNullable(field, forceNullable),\n graphqlResult,\n parentName: interfaceName,\n })\n\n if (Object.keys(objectType.getFields()).length) {\n graphqlResult.types.arrayTypes[interfaceName] = objectType\n }\n }\n\n if (!graphqlResult.types.arrayTypes[interfaceName]) {\n return objectTypeConfig\n }\n\n const arrayType = new GraphQLList(\n new GraphQLNonNull(graphqlResult.types.arrayTypes[interfaceName]),\n )\n\n return {\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, arrayType) },\n }\n },\n blocks: (objectTypeConfig: ObjectTypeConfig, field: BlocksField) => {\n const blockTypes: GraphQLObjectType<any, any>[] = field.blocks.reduce((acc, block) => {\n if (!graphqlResult.types.blockTypes[block.slug]) {\n const interfaceName =\n block?.interfaceName || block?.graphQL?.singularName || toWords(block.slug, true)\n\n const objectType = buildObjectType({\n name: interfaceName,\n config,\n fields: [\n ...block.fields,\n {\n name: 'blockType',\n type: 'text',\n },\n ],\n forceNullable,\n graphqlResult,\n parentName: interfaceName,\n })\n\n if (Object.keys(objectType.getFields()).length) {\n graphqlResult.types.blockTypes[block.slug] = objectType\n }\n }\n\n if (graphqlResult.types.blockTypes[block.slug]) {\n acc.push(graphqlResult.types.blockTypes[block.slug])\n }\n\n return acc\n }, [])\n\n if (blockTypes.length === 0) {\n return objectTypeConfig\n }\n\n const fullName = combineParentName(parentName, toWords(field.name, true))\n\n const type = new GraphQLList(\n new GraphQLNonNull(\n new GraphQLUnionType({\n name: fullName,\n resolveType: (data) => graphqlResult.types.blockTypes[data.blockType].name,\n types: blockTypes,\n }),\n ),\n )\n\n return {\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, type) },\n }\n },\n checkbox: (objectTypeConfig: ObjectTypeConfig, field: CheckboxField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLBoolean, forceNullable) },\n }),\n code: (objectTypeConfig: ObjectTypeConfig, field: CodeField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n collapsible: (objectTypeConfig: ObjectTypeConfig, field: CollapsibleField) =>\n field.fields.reduce((objectTypeConfigWithCollapsibleFields, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(objectTypeConfigWithCollapsibleFields, subField)\n }\n return objectTypeConfigWithCollapsibleFields\n }, objectTypeConfig),\n date: (objectTypeConfig: ObjectTypeConfig, field: DateField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, DateTimeResolver, forceNullable) },\n }),\n email: (objectTypeConfig: ObjectTypeConfig, field: EmailField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, EmailAddressResolver, forceNullable) },\n }),\n group: (objectTypeConfig: ObjectTypeConfig, field: GroupField) => {\n const interfaceName =\n field?.interfaceName || combineParentName(parentName, toWords(field.name, true))\n\n if (!graphqlResult.types.groupTypes[interfaceName]) {\n const objectType = buildObjectType({\n name: interfaceName,\n config,\n fields: field.fields,\n forceNullable: isFieldNullable(field, forceNullable),\n graphqlResult,\n parentName: interfaceName,\n })\n\n if (Object.keys(objectType.getFields()).length) {\n graphqlResult.types.groupTypes[interfaceName] = objectType\n }\n }\n\n if (!graphqlResult.types.groupTypes[interfaceName]) {\n return objectTypeConfig\n }\n\n return {\n ...objectTypeConfig,\n [field.name]: {\n type: graphqlResult.types.groupTypes[interfaceName],\n resolve: (parent, args, context: Context) => {\n return {\n ...parent[field.name],\n _id: parent._id ?? parent.id,\n }\n },\n },\n }\n },\n join: (objectTypeConfig: ObjectTypeConfig, field: JoinField) => {\n const joinName = combineParentName(parentName, toWords(field.name, true))\n\n const joinType = {\n type: new GraphQLObjectType({\n name: joinName,\n fields: {\n docs: {\n type: new GraphQLList(graphqlResult.collections[field.collection].graphQL.type),\n },\n hasNextPage: { type: GraphQLBoolean },\n },\n }),\n args: {\n limit: {\n type: GraphQLInt,\n },\n sort: {\n type: GraphQLString,\n },\n where: {\n type: graphqlResult.collections[field.collection].graphQL.whereInputType,\n },\n },\n extensions: { complexity: 10 },\n async resolve(parent, args, context: Context) {\n const { collection } = field\n const { limit, sort, where } = args\n const { req } = context\n\n const fullWhere = combineQueries(where, {\n [field.on]: { equals: parent._id ?? parent.id },\n })\n\n const results = await req.payload.find({\n collection,\n depth: 0,\n fallbackLocale: req.fallbackLocale,\n limit,\n locale: req.locale,\n req,\n sort,\n where: fullWhere,\n })\n\n return results\n },\n }\n\n return {\n ...objectTypeConfig,\n [field.name]: joinType,\n }\n },\n json: (objectTypeConfig: ObjectTypeConfig, field: JSONField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n number: (objectTypeConfig: ObjectTypeConfig, field: NumberField) => {\n const type = field?.name === 'id' ? GraphQLInt : GraphQLFloat\n return {\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field?.hasMany === true ? new GraphQLList(type) : type,\n forceNullable,\n ),\n },\n }\n },\n point: (objectTypeConfig: ObjectTypeConfig, field: PointField) => ({\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n new GraphQLList(new GraphQLNonNull(GraphQLFloat)),\n forceNullable,\n ),\n },\n }),\n radio: (objectTypeConfig: ObjectTypeConfig, field: RadioField) => ({\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n new GraphQLEnumType({\n name: combineParentName(parentName, field.name),\n values: formatOptions(field),\n }),\n forceNullable,\n ),\n },\n }),\n relationship: (objectTypeConfig: ObjectTypeConfig, field: RelationshipField) => {\n const { relationTo } = field\n const isRelatedToManyCollections = Array.isArray(relationTo)\n const hasManyValues = field.hasMany\n const relationshipName = combineParentName(parentName, toWords(field.name, true))\n\n let type\n let relationToType = null\n\n const graphQLCollections = config.collections.filter(\n (collectionConfig) => collectionConfig.graphQL !== false,\n )\n\n if (Array.isArray(relationTo)) {\n relationToType = new GraphQLEnumType({\n name: `${relationshipName}_RelationTo`,\n values: relationTo\n .filter((relation) =>\n graphQLCollections.some((collection) => collection.slug === relation),\n )\n .reduce(\n (relations, relation) => ({\n ...relations,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n })\n\n // Only pass collections that are GraphQL enabled\n const types = relationTo\n .filter((relation) =>\n graphQLCollections.some((collection) => collection.slug === relation),\n )\n .map((relation) => graphqlResult.collections[relation]?.graphQL.type)\n\n type = new GraphQLObjectType({\n name: `${relationshipName}_Relationship`,\n fields: {\n relationTo: {\n type: relationToType,\n },\n value: {\n type: new GraphQLUnionType({\n name: relationshipName,\n resolveType(data) {\n return graphqlResult.collections[data.collection].graphQL.type.name\n },\n types,\n }),\n },\n },\n })\n } else {\n ;({ type } = graphqlResult.collections[relationTo].graphQL)\n }\n\n // If the relationshipType is undefined at this point,\n // it can be assumed that this blockType can have a relationship\n // to itself. Therefore, we set the relationshipType equal to the blockType\n // that is currently being created.\n\n type = type || newlyCreatedBlockType\n\n const relationshipArgs: {\n draft?: unknown\n fallbackLocale?: unknown\n limit?: unknown\n locale?: unknown\n page?: unknown\n where?: unknown\n } = {}\n\n const relationsUseDrafts = (Array.isArray(relationTo) ? relationTo : [relationTo])\n .filter((relation) => graphQLCollections.some((collection) => collection.slug === relation))\n .some((relation) => graphqlResult.collections[relation].config.versions?.drafts)\n\n if (relationsUseDrafts) {\n relationshipArgs.draft = {\n type: GraphQLBoolean,\n }\n }\n\n if (config.localization) {\n relationshipArgs.locale = {\n type: graphqlResult.types.localeInputType,\n }\n\n relationshipArgs.fallbackLocale = {\n type: graphqlResult.types.fallbackLocaleInputType,\n }\n }\n\n const relationship = {\n type: withNullableType(\n field,\n hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type,\n forceNullable,\n ),\n args: relationshipArgs,\n extensions: { complexity: 10 },\n async resolve(parent, args, context: Context) {\n const value = parent[field.name]\n const locale = args.locale || context.req.locale\n const fallbackLocale = args.fallbackLocale || context.req.fallbackLocale\n let relatedCollectionSlug = field.relationTo\n const draft = Boolean(args.draft ?? context.req.query?.draft)\n\n if (hasManyValues) {\n const results = []\n const resultPromises = []\n\n const createPopulationPromise = async (relatedDoc, i) => {\n let id = relatedDoc\n let collectionSlug = field.relationTo\n const isValidGraphQLCollection = isRelatedToManyCollections\n ? graphQLCollections.some((collection) => collectionSlug.includes(collection.slug))\n : graphQLCollections.some((collection) => collectionSlug === collection.slug)\n\n if (isValidGraphQLCollection) {\n if (isRelatedToManyCollections) {\n collectionSlug = relatedDoc.relationTo\n id = relatedDoc.value\n }\n\n const result = await context.req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug: collectionSlug as string,\n currentDepth: 0,\n depth: 0,\n docID: id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: false,\n showHiddenFields: false,\n transactionID: context.req.transactionID,\n }),\n )\n\n if (result) {\n if (isRelatedToManyCollections) {\n results[i] = {\n relationTo: collectionSlug,\n value: {\n ...result,\n collection: collectionSlug,\n },\n }\n } else {\n results[i] = result\n }\n }\n }\n }\n\n if (value) {\n value.forEach((relatedDoc, i) => {\n resultPromises.push(createPopulationPromise(relatedDoc, i))\n })\n }\n\n await Promise.all(resultPromises)\n return results\n }\n\n let id = value\n if (isRelatedToManyCollections && value) {\n id = value.value\n relatedCollectionSlug = value.relationTo\n }\n\n if (id) {\n if (\n graphQLCollections.some((collection) => collection.slug === relatedCollectionSlug)\n ) {\n const relatedDocument = await context.req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug: relatedCollectionSlug as string,\n currentDepth: 0,\n depth: 0,\n docID: id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: false,\n showHiddenFields: false,\n transactionID: context.req.transactionID,\n }),\n )\n\n if (relatedDocument) {\n if (isRelatedToManyCollections) {\n return {\n relationTo: relatedCollectionSlug,\n value: {\n ...relatedDocument,\n collection: relatedCollectionSlug,\n },\n }\n }\n\n return relatedDocument\n }\n }\n\n return null\n }\n\n return null\n },\n }\n\n return {\n ...objectTypeConfig,\n [field.name]: relationship,\n }\n },\n richText: (objectTypeConfig: ObjectTypeConfig, field: RichTextField) => ({\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(field, GraphQLJSON, forceNullable),\n args: {\n depth: {\n type: GraphQLInt,\n },\n },\n async resolve(parent, args, context: Context) {\n let depth = config.defaultDepth\n if (typeof args.depth !== 'undefined') {\n depth = args.depth\n }\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n // RichText fields have their own depth argument in GraphQL.\n // This is why the populationPromise (which populates richtext fields like uploads and relationships)\n // is run here again, with the provided depth.\n // In the graphql find.ts resolver, the depth is then hard-coded to 0.\n // Effectively, this means that the populationPromise for GraphQL is only run here, and not in the find.ts resolver / normal population promise.\n if (editor?.graphQLPopulationPromises) {\n const fieldPromises = []\n const populationPromises = []\n const populateDepth =\n field?.maxDepth !== undefined && field?.maxDepth < depth ? field?.maxDepth : depth\n\n editor?.graphQLPopulationPromises({\n context,\n depth: populateDepth,\n draft: args.draft,\n field,\n fieldPromises,\n findMany: false,\n flattenLocales: false,\n overrideAccess: false,\n populationPromises,\n req: context.req,\n showHiddenFields: false,\n siblingDoc: parent,\n })\n await Promise.all(fieldPromises)\n await Promise.all(populationPromises)\n }\n\n return parent[field.name]\n },\n },\n }),\n row: (objectTypeConfig: ObjectTypeConfig, field: RowField) =>\n field.fields.reduce((objectTypeConfigWithRowFields, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(objectTypeConfigWithRowFields, subField)\n }\n return objectTypeConfigWithRowFields\n }, objectTypeConfig),\n select: (objectTypeConfig: ObjectTypeConfig, field: SelectField) => {\n const fullName = combineParentName(parentName, field.name)\n\n let type: GraphQLType = new GraphQLEnumType({\n name: fullName,\n values: formatOptions(field),\n })\n\n type = field.hasMany ? new GraphQLList(new GraphQLNonNull(type)) : type\n type = withNullableType(field, type, forceNullable)\n\n return {\n ...objectTypeConfig,\n [field.name]: { type },\n }\n },\n tabs: (objectTypeConfig: ObjectTypeConfig, field: TabsField) =>\n field.tabs.reduce((tabSchema, tab) => {\n if (tabHasName(tab)) {\n const interfaceName =\n tab?.interfaceName || combineParentName(parentName, toWords(tab.name, true))\n\n if (!graphqlResult.types.groupTypes[interfaceName]) {\n const objectType = buildObjectType({\n name: interfaceName,\n config,\n fields: tab.fields,\n forceNullable,\n graphqlResult,\n parentName: interfaceName,\n })\n\n if (Object.keys(objectType.getFields()).length) {\n graphqlResult.types.groupTypes[interfaceName] = objectType\n }\n }\n\n if (!graphqlResult.types.groupTypes[interfaceName]) {\n return tabSchema\n }\n\n return {\n ...tabSchema,\n [tab.name]: {\n type: graphqlResult.types.groupTypes[interfaceName],\n resolve(parent, args, context: Context) {\n return {\n ...parent[tab.name],\n _id: parent._id ?? parent.id,\n }\n },\n },\n }\n }\n\n return {\n ...tabSchema,\n ...tab.fields.reduce((subFieldSchema, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(subFieldSchema, subField)\n }\n return subFieldSchema\n }, tabSchema),\n }\n }, objectTypeConfig),\n text: (objectTypeConfig: ObjectTypeConfig, field: TextField) => ({\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,\n forceNullable,\n ),\n },\n }),\n textarea: (objectTypeConfig: ObjectTypeConfig, field: TextareaField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n upload: (objectTypeConfig: ObjectTypeConfig, field: UploadField) => {\n const { relationTo } = field\n const isRelatedToManyCollections = Array.isArray(relationTo)\n const hasManyValues = field.hasMany\n const relationshipName = combineParentName(parentName, toWords(field.name, true))\n\n let type\n let relationToType = null\n\n if (Array.isArray(relationTo)) {\n relationToType = new GraphQLEnumType({\n name: `${relationshipName}_RelationTo`,\n values: relationTo.reduce(\n (relations, relation) => ({\n ...relations,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n })\n\n const types = relationTo.map((relation) => graphqlResult.collections[relation].graphQL.type)\n\n type = new GraphQLObjectType({\n name: `${relationshipName}_Relationship`,\n fields: {\n relationTo: {\n type: relationToType,\n },\n value: {\n type: new GraphQLUnionType({\n name: relationshipName,\n resolveType(data) {\n return graphqlResult.collections[data.collection].graphQL.type.name\n },\n types,\n }),\n },\n },\n })\n } else {\n ;({ type } = graphqlResult.collections[relationTo].graphQL)\n }\n\n // If the relationshipType is undefined at this point,\n // it can be assumed that this blockType can have a relationship\n // to itself. Therefore, we set the relationshipType equal to the blockType\n // that is currently being created.\n\n type = type || newlyCreatedBlockType\n\n const relationshipArgs: {\n draft?: unknown\n fallbackLocale?: unknown\n limit?: unknown\n locale?: unknown\n page?: unknown\n where?: unknown\n } = {}\n\n const relationsUseDrafts = (Array.isArray(relationTo) ? relationTo : [relationTo]).some(\n (relation) => graphqlResult.collections[relation].config.versions?.drafts,\n )\n\n if (relationsUseDrafts) {\n relationshipArgs.draft = {\n type: GraphQLBoolean,\n }\n }\n\n if (config.localization) {\n relationshipArgs.locale = {\n type: graphqlResult.types.localeInputType,\n }\n\n relationshipArgs.fallbackLocale = {\n type: graphqlResult.types.fallbackLocaleInputType,\n }\n }\n\n const relationship = {\n type: withNullableType(\n field,\n hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type,\n forceNullable,\n ),\n args: relationshipArgs,\n extensions: { complexity: 10 },\n async resolve(parent, args, context: Context) {\n const value = parent[field.name]\n const locale = args.locale || context.req.locale\n const fallbackLocale = args.fallbackLocale || context.req.fallbackLocale\n let relatedCollectionSlug = field.relationTo\n const draft = Boolean(args.draft ?? context.req.query?.draft)\n\n if (hasManyValues) {\n const results = []\n const resultPromises = []\n\n const createPopulationPromise = async (relatedDoc, i) => {\n let id = relatedDoc\n let collectionSlug = field.relationTo\n\n if (isRelatedToManyCollections) {\n collectionSlug = relatedDoc.relationTo\n id = relatedDoc.value\n }\n\n const result = await context.req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug,\n currentDepth: 0,\n depth: 0,\n docID: id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: false,\n showHiddenFields: false,\n transactionID: context.req.transactionID,\n }),\n )\n\n if (result) {\n if (isRelatedToManyCollections) {\n results[i] = {\n relationTo: collectionSlug,\n value: {\n ...result,\n collection: collectionSlug,\n },\n }\n } else {\n results[i] = result\n }\n }\n }\n\n if (value) {\n value.forEach((relatedDoc, i) => {\n resultPromises.push(createPopulationPromise(relatedDoc, i))\n })\n }\n\n await Promise.all(resultPromises)\n return results\n }\n\n let id = value\n if (isRelatedToManyCollections && value) {\n id = value.value\n relatedCollectionSlug = value.relationTo\n }\n\n if (id) {\n const relatedDocument = await context.req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug: relatedCollectionSlug,\n currentDepth: 0,\n depth: 0,\n docID: id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: false,\n showHiddenFields: false,\n transactionID: context.req.transactionID,\n }),\n )\n\n if (relatedDocument) {\n if (isRelatedToManyCollections) {\n return {\n relationTo: relatedCollectionSlug,\n value: {\n ...relatedDocument,\n collection: relatedCollectionSlug,\n },\n }\n }\n\n return relatedDocument\n }\n\n return null\n }\n\n return null\n },\n }\n\n return {\n ...objectTypeConfig,\n [field.name]: relationship,\n }\n },\n }\n\n const objectSchema = {\n name,\n fields: () =>\n fields.reduce((objectTypeConfig, field) => {\n const fieldSchema = fieldToSchemaMap[field.type]\n\n if (typeof fieldSchema !== 'function') {\n return objectTypeConfig\n }\n\n return {\n ...objectTypeConfig,\n ...fieldSchema(objectTypeConfig, field),\n }\n }, baseFields),\n }\n\n const newlyCreatedBlockType = new GraphQLObjectType(objectSchema)\n\n return newlyCreatedBlockType\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInt","GraphQLList","GraphQLNonNull","GraphQLObjectType","GraphQLString","GraphQLUnionType","DateTimeResolver","EmailAddressResolver","combineQueries","createDataloaderCacheKey","MissingEditorProp","toWords","tabHasName","GraphQLJSON","combineParentName","formatName","formatOptions","isFieldNullable","withNullableType","buildObjectType","name","baseFields","config","fields","forceNullable","graphqlResult","parentName","fieldToSchemaMap","array","objectTypeConfig","field","interfaceName","types","arrayTypes","objectType","Object","keys","getFields","length","arrayType","type","blocks","blockTypes","reduce","acc","block","slug","graphQL","singularName","push","fullName","resolveType","data","blockType","checkbox","code","collapsible","objectTypeConfigWithCollapsibleFields","subField","addSubField","date","email","group","groupTypes","resolve","parent","args","context","_id","id","join","joinName","joinType","docs","collections","collection","hasNextPage","limit","sort","where","whereInputType","extensions","complexity","req","fullWhere","on","equals","results","payload","find","depth","fallbackLocale","locale","json","number","hasMany","point","radio","values","relationship","relationTo","isRelatedToManyCollections","Array","isArray","hasManyValues","relationshipName","relationToType","graphQLCollections","filter","collectionConfig","relation","some","relations","value","map","newlyCreatedBlockType","relationshipArgs","relationsUseDrafts","versions","drafts","draft","localization","localeInputType","fallbackLocaleInputType","relatedCollectionSlug","Boolean","query","resultPromises","createPopulationPromise","relatedDoc","i","collectionSlug","isValidGraphQLCollection","includes","result","payloadDataLoader","load","currentDepth","docID","overrideAccess","showHiddenFields","transactionID","forEach","Promise","all","relatedDocument","richText","defaultDepth","editor","Error","graphQLPopulationPromises","fieldPromises","populationPromises","populateDepth","maxDepth","undefined","findMany","flattenLocales","siblingDoc","row","objectTypeConfigWithRowFields","select","tabs","tabSchema","tab","subFieldSchema","text","textarea","upload","objectSchema","fieldSchema"],"mappings":"AA6BA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,iBAAiB,EACjBC,aAAa,EACbC,gBAAgB,QACX,UAAS;AAChB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,kBAAiB;AACxE,SAASC,cAAc,EAAEC,wBAAwB,EAAEC,iBAAiB,EAAEC,OAAO,QAAQ,UAAS;AAC9F,SAASC,UAAU,QAAQ,iBAAgB;AAI3C,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,gBAAgB,QAAQ,wBAAuB;AAgBxD,OAAO,SAASC,gBAAgB,EAC9BC,IAAI,EACJC,aAAa,CAAC,CAAC,EACfC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,UAAU,EACL;IACL,MAAMC,mBAAmB;QACvBC,OAAO,CAACC,kBAAoCC;YAC1C,MAAMC,gBACJD,OAAOC,iBAAiBjB,kBAAkBY,YAAYf,QAAQmB,MAAMV,IAAI,EAAE;YAE5E,IAAI,CAACK,cAAcO,KAAK,CAACC,UAAU,CAACF,cAAc,EAAE;gBAClD,MAAMG,aAAaf,gBAAgB;oBACjCC,MAAMW;oBACNT;oBACAC,QAAQO,MAAMP,MAAM;oBACpBC,eAAeP,gBAAgBa,OAAON;oBACtCC;oBACAC,YAAYK;gBACd;gBAEA,IAAII,OAAOC,IAAI,CAACF,WAAWG,SAAS,IAAIC,MAAM,EAAE;oBAC9Cb,cAAcO,KAAK,CAACC,UAAU,CAACF,cAAc,GAAGG;gBAClD;YACF;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BAEA,OAAOqB;wBACT;wBAEA,OAAO;oBACT;oBAEA,OAAO;gBACT;YACF;YAEA,OAAO;gBACL,GAAGpH,gBAAgB;gBACnB,CAACC,MAAMV,IAAI,CAAC,EAAE+E;YAChB;QACF;IACF;IAEA,MAAMsE,eAAe;QACnBrJ;QACAG,QAAQ,IACNA,OAAOoB,MAAM,CAAC,CAACd,kBAAkBC;gBAC/B,MAAM4I,cAAc/I,gBAAgB,CAACG,MAAMU,IAAI,CAAC;gBAEhD,IAAI,OAAOkI,gBAAgB,YAAY;oBACrC,OAAO7I;gBACT;gBAEA,OAAO;oBACL,GAAGA,gBAAgB;oBACnB,GAAG6I,YAAY7I,kBAAkBC,MAAM;gBACzC;YACF,GAAGT;IACP;IAEA,MAAM8F,wBAAwB,IAAIhH,kBAAkBsK;IAEpD,OAAOtD;AACT"}
1
+ {"version":3,"sources":["../../src/schema/buildObjectType.ts"],"sourcesContent":["import type { GraphQLFieldConfig, GraphQLType } from 'graphql'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GraphQLInfo,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextAdapter,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport {\n GraphQLBoolean,\n GraphQLEnumType,\n GraphQLFloat,\n GraphQLInt,\n GraphQLList,\n GraphQLNonNull,\n GraphQLObjectType,\n GraphQLString,\n GraphQLUnionType,\n} from 'graphql'\nimport { DateTimeResolver, EmailAddressResolver } from 'graphql-scalars'\nimport { combineQueries, createDataloaderCacheKey, MissingEditorProp, toWords } from 'payload'\nimport { tabHasName } from 'payload/shared'\n\nimport type { Context } from '../resolvers/types.js'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { formatOptions } from '../utilities/formatOptions.js'\nimport { isFieldNullable } from './isFieldNullable.js'\nimport { withNullableType } from './withNullableType.js'\n\nexport type ObjectTypeConfig = {\n [path: string]: GraphQLFieldConfig<any, any>\n}\n\ntype Args = {\n baseFields?: ObjectTypeConfig\n config: SanitizedConfig\n fields: Field[]\n forceNullable?: boolean\n graphqlResult: GraphQLInfo\n name: string\n parentName: string\n}\n\nexport function buildObjectType({\n name,\n baseFields = {},\n config,\n fields,\n forceNullable,\n graphqlResult,\n parentName,\n}: Args): GraphQLObjectType {\n const fieldToSchemaMap = {\n array: (objectTypeConfig: ObjectTypeConfig, field: ArrayField) => {\n const interfaceName =\n field?.interfaceName || combineParentName(parentName, toWords(field.name, true))\n\n if (!graphqlResult.types.arrayTypes[interfaceName]) {\n const objectType = buildObjectType({\n name: interfaceName,\n config,\n fields: field.fields,\n forceNullable: isFieldNullable(field, forceNullable),\n graphqlResult,\n parentName: interfaceName,\n })\n\n if (Object.keys(objectType.getFields()).length) {\n graphqlResult.types.arrayTypes[interfaceName] = objectType\n }\n }\n\n if (!graphqlResult.types.arrayTypes[interfaceName]) {\n return objectTypeConfig\n }\n\n const arrayType = new GraphQLList(\n new GraphQLNonNull(graphqlResult.types.arrayTypes[interfaceName]),\n )\n\n return {\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, arrayType) },\n }\n },\n blocks: (objectTypeConfig: ObjectTypeConfig, field: BlocksField) => {\n const blockTypes: GraphQLObjectType<any, any>[] = field.blocks.reduce((acc, block) => {\n if (!graphqlResult.types.blockTypes[block.slug]) {\n const interfaceName =\n block?.interfaceName || block?.graphQL?.singularName || toWords(block.slug, true)\n\n const objectType = buildObjectType({\n name: interfaceName,\n config,\n fields: [\n ...block.fields,\n {\n name: 'blockType',\n type: 'text',\n },\n ],\n forceNullable,\n graphqlResult,\n parentName: interfaceName,\n })\n\n if (Object.keys(objectType.getFields()).length) {\n graphqlResult.types.blockTypes[block.slug] = objectType\n }\n }\n\n if (graphqlResult.types.blockTypes[block.slug]) {\n acc.push(graphqlResult.types.blockTypes[block.slug])\n }\n\n return acc\n }, [])\n\n if (blockTypes.length === 0) {\n return objectTypeConfig\n }\n\n const fullName = combineParentName(parentName, toWords(field.name, true))\n\n const type = new GraphQLList(\n new GraphQLNonNull(\n new GraphQLUnionType({\n name: fullName,\n resolveType: (data) => graphqlResult.types.blockTypes[data.blockType].name,\n types: blockTypes,\n }),\n ),\n )\n\n return {\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, type) },\n }\n },\n checkbox: (objectTypeConfig: ObjectTypeConfig, field: CheckboxField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLBoolean, forceNullable) },\n }),\n code: (objectTypeConfig: ObjectTypeConfig, field: CodeField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n collapsible: (objectTypeConfig: ObjectTypeConfig, field: CollapsibleField) =>\n field.fields.reduce((objectTypeConfigWithCollapsibleFields, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(objectTypeConfigWithCollapsibleFields, subField)\n }\n return objectTypeConfigWithCollapsibleFields\n }, objectTypeConfig),\n date: (objectTypeConfig: ObjectTypeConfig, field: DateField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, DateTimeResolver, forceNullable) },\n }),\n email: (objectTypeConfig: ObjectTypeConfig, field: EmailField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, EmailAddressResolver, forceNullable) },\n }),\n group: (objectTypeConfig: ObjectTypeConfig, field: GroupField) => {\n const interfaceName =\n field?.interfaceName || combineParentName(parentName, toWords(field.name, true))\n\n if (!graphqlResult.types.groupTypes[interfaceName]) {\n const objectType = buildObjectType({\n name: interfaceName,\n config,\n fields: field.fields,\n forceNullable: isFieldNullable(field, forceNullable),\n graphqlResult,\n parentName: interfaceName,\n })\n\n if (Object.keys(objectType.getFields()).length) {\n graphqlResult.types.groupTypes[interfaceName] = objectType\n }\n }\n\n if (!graphqlResult.types.groupTypes[interfaceName]) {\n return objectTypeConfig\n }\n\n return {\n ...objectTypeConfig,\n [field.name]: {\n type: graphqlResult.types.groupTypes[interfaceName],\n resolve: (parent, args, context: Context) => {\n return {\n ...parent[field.name],\n _id: parent._id ?? parent.id,\n }\n },\n },\n }\n },\n join: (objectTypeConfig: ObjectTypeConfig, field: JoinField) => {\n const joinName = combineParentName(parentName, toWords(field.name, true))\n\n const joinType = {\n type: new GraphQLObjectType({\n name: joinName,\n fields: {\n docs: {\n type: new GraphQLList(graphqlResult.collections[field.collection].graphQL.type),\n },\n hasNextPage: { type: GraphQLBoolean },\n },\n }),\n args: {\n limit: {\n type: GraphQLInt,\n },\n sort: {\n type: GraphQLString,\n },\n where: {\n type: graphqlResult.collections[field.collection].graphQL.whereInputType,\n },\n },\n extensions: { complexity: 10 },\n async resolve(parent, args, context: Context) {\n const { collection } = field\n const { limit, sort, where } = args\n const { req } = context\n\n const fullWhere = combineQueries(where, {\n [field.on]: { equals: parent._id ?? parent.id },\n })\n\n const results = await req.payload.find({\n collection,\n depth: 0,\n fallbackLocale: req.fallbackLocale,\n limit,\n locale: req.locale,\n req,\n sort,\n where: fullWhere,\n })\n\n return results\n },\n }\n\n return {\n ...objectTypeConfig,\n [field.name]: joinType,\n }\n },\n json: (objectTypeConfig: ObjectTypeConfig, field: JSONField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLJSON, forceNullable) },\n }),\n number: (objectTypeConfig: ObjectTypeConfig, field: NumberField) => {\n const type = field?.name === 'id' ? GraphQLInt : GraphQLFloat\n return {\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field?.hasMany === true ? new GraphQLList(type) : type,\n forceNullable,\n ),\n },\n }\n },\n point: (objectTypeConfig: ObjectTypeConfig, field: PointField) => ({\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n new GraphQLList(new GraphQLNonNull(GraphQLFloat)),\n forceNullable,\n ),\n },\n }),\n radio: (objectTypeConfig: ObjectTypeConfig, field: RadioField) => ({\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n new GraphQLEnumType({\n name: combineParentName(parentName, field.name),\n values: formatOptions(field),\n }),\n forceNullable,\n ),\n },\n }),\n relationship: (objectTypeConfig: ObjectTypeConfig, field: RelationshipField) => {\n const { relationTo } = field\n const isRelatedToManyCollections = Array.isArray(relationTo)\n const hasManyValues = field.hasMany\n const relationshipName = combineParentName(parentName, toWords(field.name, true))\n\n let type\n let relationToType = null\n\n const graphQLCollections = config.collections.filter(\n (collectionConfig) => collectionConfig.graphQL !== false,\n )\n\n if (Array.isArray(relationTo)) {\n relationToType = new GraphQLEnumType({\n name: `${relationshipName}_RelationTo`,\n values: relationTo\n .filter((relation) =>\n graphQLCollections.some((collection) => collection.slug === relation),\n )\n .reduce(\n (relations, relation) => ({\n ...relations,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n })\n\n // Only pass collections that are GraphQL enabled\n const types = relationTo\n .filter((relation) =>\n graphQLCollections.some((collection) => collection.slug === relation),\n )\n .map((relation) => graphqlResult.collections[relation]?.graphQL.type)\n\n type = new GraphQLObjectType({\n name: `${relationshipName}_Relationship`,\n fields: {\n relationTo: {\n type: relationToType,\n },\n value: {\n type: new GraphQLUnionType({\n name: relationshipName,\n resolveType(data) {\n return graphqlResult.collections[data.collection].graphQL.type.name\n },\n types,\n }),\n },\n },\n })\n } else {\n ;({ type } = graphqlResult.collections[relationTo].graphQL)\n }\n\n // If the relationshipType is undefined at this point,\n // it can be assumed that this blockType can have a relationship\n // to itself. Therefore, we set the relationshipType equal to the blockType\n // that is currently being created.\n\n type = type || newlyCreatedBlockType\n\n const relationshipArgs: {\n draft?: unknown\n fallbackLocale?: unknown\n limit?: unknown\n locale?: unknown\n page?: unknown\n where?: unknown\n } = {}\n\n const relationsUseDrafts = (Array.isArray(relationTo) ? relationTo : [relationTo])\n .filter((relation) => graphQLCollections.some((collection) => collection.slug === relation))\n .some((relation) => graphqlResult.collections[relation].config.versions?.drafts)\n\n if (relationsUseDrafts) {\n relationshipArgs.draft = {\n type: GraphQLBoolean,\n }\n }\n\n if (config.localization) {\n relationshipArgs.locale = {\n type: graphqlResult.types.localeInputType,\n }\n\n relationshipArgs.fallbackLocale = {\n type: graphqlResult.types.fallbackLocaleInputType,\n }\n }\n\n const relationship = {\n type: withNullableType(\n field,\n hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type,\n forceNullable,\n ),\n args: relationshipArgs,\n extensions: { complexity: 10 },\n async resolve(parent, args, context: Context) {\n const value = parent[field.name]\n const locale = args.locale || context.req.locale\n const fallbackLocale = args.fallbackLocale || context.req.fallbackLocale\n let relatedCollectionSlug = field.relationTo\n const draft = Boolean(args.draft ?? context.req.query?.draft)\n\n if (hasManyValues) {\n const results = []\n const resultPromises = []\n\n const createPopulationPromise = async (relatedDoc, i) => {\n let id = relatedDoc\n let collectionSlug = field.relationTo\n const isValidGraphQLCollection = isRelatedToManyCollections\n ? graphQLCollections.some((collection) => collectionSlug.includes(collection.slug))\n : graphQLCollections.some((collection) => collectionSlug === collection.slug)\n\n if (isValidGraphQLCollection) {\n if (isRelatedToManyCollections) {\n collectionSlug = relatedDoc.relationTo\n id = relatedDoc.value\n }\n\n const result = await context.req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug: collectionSlug as string,\n currentDepth: 0,\n depth: 0,\n docID: id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: false,\n showHiddenFields: false,\n transactionID: context.req.transactionID,\n }),\n )\n\n if (result) {\n if (isRelatedToManyCollections) {\n results[i] = {\n relationTo: collectionSlug,\n value: {\n ...result,\n collection: collectionSlug,\n },\n }\n } else {\n results[i] = result\n }\n }\n }\n }\n\n if (value) {\n value.forEach((relatedDoc, i) => {\n resultPromises.push(createPopulationPromise(relatedDoc, i))\n })\n }\n\n await Promise.all(resultPromises)\n return results\n }\n\n let id = value\n if (isRelatedToManyCollections && value) {\n id = value.value\n relatedCollectionSlug = value.relationTo\n }\n\n if (id) {\n if (\n graphQLCollections.some((collection) => collection.slug === relatedCollectionSlug)\n ) {\n const relatedDocument = await context.req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug: relatedCollectionSlug as string,\n currentDepth: 0,\n depth: 0,\n docID: id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: false,\n showHiddenFields: false,\n transactionID: context.req.transactionID,\n }),\n )\n\n if (relatedDocument) {\n if (isRelatedToManyCollections) {\n return {\n relationTo: relatedCollectionSlug,\n value: {\n ...relatedDocument,\n collection: relatedCollectionSlug,\n },\n }\n }\n\n return relatedDocument\n }\n }\n\n return null\n }\n\n return null\n },\n }\n\n return {\n ...objectTypeConfig,\n [field.name]: relationship,\n }\n },\n richText: (objectTypeConfig: ObjectTypeConfig, field: RichTextField) => ({\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(field, GraphQLJSON, forceNullable),\n args: {\n depth: {\n type: GraphQLInt,\n },\n },\n async resolve(parent, args, context: Context) {\n let depth = config.defaultDepth\n if (typeof args.depth !== 'undefined') {\n depth = args.depth\n }\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n // RichText fields have their own depth argument in GraphQL.\n // This is why the populationPromise (which populates richtext fields like uploads and relationships)\n // is run here again, with the provided depth.\n // In the graphql find.ts resolver, the depth is then hard-coded to 0.\n // Effectively, this means that the populationPromise for GraphQL is only run here, and not in the find.ts resolver / normal population promise.\n if (editor?.graphQLPopulationPromises) {\n const fieldPromises = []\n const populationPromises = []\n const populateDepth =\n field?.maxDepth !== undefined && field?.maxDepth < depth ? field?.maxDepth : depth\n\n editor?.graphQLPopulationPromises({\n context,\n depth: populateDepth,\n draft: args.draft,\n field,\n fieldPromises,\n findMany: false,\n flattenLocales: false,\n overrideAccess: false,\n populationPromises,\n req: context.req,\n showHiddenFields: false,\n siblingDoc: parent,\n })\n await Promise.all(fieldPromises)\n await Promise.all(populationPromises)\n }\n\n return parent[field.name]\n },\n },\n }),\n row: (objectTypeConfig: ObjectTypeConfig, field: RowField) =>\n field.fields.reduce((objectTypeConfigWithRowFields, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(objectTypeConfigWithRowFields, subField)\n }\n return objectTypeConfigWithRowFields\n }, objectTypeConfig),\n select: (objectTypeConfig: ObjectTypeConfig, field: SelectField) => {\n const fullName = combineParentName(parentName, field.name)\n\n let type: GraphQLType = new GraphQLEnumType({\n name: fullName,\n values: formatOptions(field),\n })\n\n type = field.hasMany ? new GraphQLList(new GraphQLNonNull(type)) : type\n type = withNullableType(field, type, forceNullable)\n\n return {\n ...objectTypeConfig,\n [field.name]: { type },\n }\n },\n tabs: (objectTypeConfig: ObjectTypeConfig, field: TabsField) =>\n field.tabs.reduce((tabSchema, tab) => {\n if (tabHasName(tab)) {\n const interfaceName =\n tab?.interfaceName || combineParentName(parentName, toWords(tab.name, true))\n\n if (!graphqlResult.types.groupTypes[interfaceName]) {\n const objectType = buildObjectType({\n name: interfaceName,\n config,\n fields: tab.fields,\n forceNullable,\n graphqlResult,\n parentName: interfaceName,\n })\n\n if (Object.keys(objectType.getFields()).length) {\n graphqlResult.types.groupTypes[interfaceName] = objectType\n }\n }\n\n if (!graphqlResult.types.groupTypes[interfaceName]) {\n return tabSchema\n }\n\n return {\n ...tabSchema,\n [tab.name]: {\n type: graphqlResult.types.groupTypes[interfaceName],\n resolve(parent, args, context: Context) {\n return {\n ...parent[tab.name],\n _id: parent._id ?? parent.id,\n }\n },\n },\n }\n }\n\n return {\n ...tabSchema,\n ...tab.fields.reduce((subFieldSchema, subField) => {\n const addSubField = fieldToSchemaMap[subField.type]\n if (addSubField) {\n return addSubField(subFieldSchema, subField)\n }\n return subFieldSchema\n }, tabSchema),\n }\n }, objectTypeConfig),\n text: (objectTypeConfig: ObjectTypeConfig, field: TextField) => ({\n ...objectTypeConfig,\n [field.name]: {\n type: withNullableType(\n field,\n field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,\n forceNullable,\n ),\n },\n }),\n textarea: (objectTypeConfig: ObjectTypeConfig, field: TextareaField) => ({\n ...objectTypeConfig,\n [field.name]: { type: withNullableType(field, GraphQLString, forceNullable) },\n }),\n upload: (objectTypeConfig: ObjectTypeConfig, field: UploadField) => {\n const { relationTo } = field\n const isRelatedToManyCollections = Array.isArray(relationTo)\n const hasManyValues = field.hasMany\n const relationshipName = combineParentName(parentName, toWords(field.name, true))\n\n let type\n let relationToType = null\n\n if (Array.isArray(relationTo)) {\n relationToType = new GraphQLEnumType({\n name: `${relationshipName}_RelationTo`,\n values: relationTo.reduce(\n (relations, relation) => ({\n ...relations,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n })\n\n const types = relationTo.map((relation) => graphqlResult.collections[relation].graphQL.type)\n\n type = new GraphQLObjectType({\n name: `${relationshipName}_Relationship`,\n fields: {\n relationTo: {\n type: relationToType,\n },\n value: {\n type: new GraphQLUnionType({\n name: relationshipName,\n resolveType(data) {\n return graphqlResult.collections[data.collection].graphQL.type.name\n },\n types,\n }),\n },\n },\n })\n } else {\n ;({ type } = graphqlResult.collections[relationTo].graphQL)\n }\n\n // If the relationshipType is undefined at this point,\n // it can be assumed that this blockType can have a relationship\n // to itself. Therefore, we set the relationshipType equal to the blockType\n // that is currently being created.\n\n type = type || newlyCreatedBlockType\n\n const relationshipArgs: {\n draft?: unknown\n fallbackLocale?: unknown\n limit?: unknown\n locale?: unknown\n page?: unknown\n where?: unknown\n } = {}\n\n const relationsUseDrafts = (Array.isArray(relationTo) ? relationTo : [relationTo]).some(\n (relation) => graphqlResult.collections[relation].config.versions?.drafts,\n )\n\n if (relationsUseDrafts) {\n relationshipArgs.draft = {\n type: GraphQLBoolean,\n }\n }\n\n if (config.localization) {\n relationshipArgs.locale = {\n type: graphqlResult.types.localeInputType,\n }\n\n relationshipArgs.fallbackLocale = {\n type: graphqlResult.types.fallbackLocaleInputType,\n }\n }\n\n const relationship = {\n type: withNullableType(\n field,\n hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type,\n forceNullable,\n ),\n args: relationshipArgs,\n extensions: { complexity: 10 },\n async resolve(parent, args, context: Context) {\n const value = parent[field.name]\n const locale = args.locale || context.req.locale\n const fallbackLocale = args.fallbackLocale || context.req.fallbackLocale\n let relatedCollectionSlug = field.relationTo\n const draft = Boolean(args.draft ?? context.req.query?.draft)\n\n if (hasManyValues) {\n const results = []\n const resultPromises = []\n\n const createPopulationPromise = async (relatedDoc, i) => {\n let id = relatedDoc\n let collectionSlug = field.relationTo\n\n if (isRelatedToManyCollections) {\n collectionSlug = relatedDoc.relationTo\n id = relatedDoc.value\n }\n\n const result = await context.req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug,\n currentDepth: 0,\n depth: 0,\n docID: id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: false,\n showHiddenFields: false,\n transactionID: context.req.transactionID,\n }),\n )\n\n if (result) {\n if (isRelatedToManyCollections) {\n results[i] = {\n relationTo: collectionSlug,\n value: {\n ...result,\n collection: collectionSlug,\n },\n }\n } else {\n results[i] = result\n }\n }\n }\n\n if (value) {\n value.forEach((relatedDoc, i) => {\n resultPromises.push(createPopulationPromise(relatedDoc, i))\n })\n }\n\n await Promise.all(resultPromises)\n return results\n }\n\n let id = value\n if (isRelatedToManyCollections && value) {\n id = value.value\n relatedCollectionSlug = value.relationTo\n }\n\n if (id) {\n const relatedDocument = await context.req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug: relatedCollectionSlug,\n currentDepth: 0,\n depth: 0,\n docID: id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: false,\n showHiddenFields: false,\n transactionID: context.req.transactionID,\n }),\n )\n\n if (relatedDocument) {\n if (isRelatedToManyCollections) {\n return {\n relationTo: relatedCollectionSlug,\n value: {\n ...relatedDocument,\n collection: relatedCollectionSlug,\n },\n }\n }\n\n return relatedDocument\n }\n\n return null\n }\n\n return null\n },\n }\n\n return {\n ...objectTypeConfig,\n [field.name]: relationship,\n }\n },\n }\n\n const objectSchema = {\n name,\n fields: () =>\n fields.reduce((objectTypeConfig, field) => {\n const fieldSchema = fieldToSchemaMap[field.type]\n\n if (typeof fieldSchema !== 'function') {\n return objectTypeConfig\n }\n\n return {\n ...objectTypeConfig,\n ...fieldSchema(objectTypeConfig, field),\n }\n }, baseFields),\n }\n\n const newlyCreatedBlockType = new GraphQLObjectType(objectSchema)\n\n return newlyCreatedBlockType\n}\n"],"names":["GraphQLBoolean","GraphQLEnumType","GraphQLFloat","GraphQLInt","GraphQLList","GraphQLNonNull","GraphQLObjectType","GraphQLString","GraphQLUnionType","DateTimeResolver","EmailAddressResolver","combineQueries","createDataloaderCacheKey","MissingEditorProp","toWords","tabHasName","GraphQLJSON","combineParentName","formatName","formatOptions","isFieldNullable","withNullableType","buildObjectType","name","baseFields","config","fields","forceNullable","graphqlResult","parentName","fieldToSchemaMap","array","objectTypeConfig","field","interfaceName","types","arrayTypes","objectType","Object","keys","getFields","length","arrayType","type","blocks","blockTypes","reduce","acc","block","slug","graphQL","singularName","push","fullName","resolveType","data","blockType","checkbox","code","collapsible","objectTypeConfigWithCollapsibleFields","subField","addSubField","date","email","group","groupTypes","resolve","parent","args","context","_id","id","join","joinName","joinType","docs","collections","collection","hasNextPage","limit","sort","where","whereInputType","extensions","complexity","req","fullWhere","on","equals","results","payload","find","depth","fallbackLocale","locale","json","number","hasMany","point","radio","values","relationship","relationTo","isRelatedToManyCollections","Array","isArray","hasManyValues","relationshipName","relationToType","graphQLCollections","filter","collectionConfig","relation","some","relations","value","map","newlyCreatedBlockType","relationshipArgs","relationsUseDrafts","versions","drafts","draft","localization","localeInputType","fallbackLocaleInputType","relatedCollectionSlug","Boolean","query","resultPromises","createPopulationPromise","relatedDoc","i","collectionSlug","isValidGraphQLCollection","includes","result","payloadDataLoader","load","currentDepth","docID","overrideAccess","showHiddenFields","transactionID","forEach","Promise","all","relatedDocument","richText","defaultDepth","editor","Error","graphQLPopulationPromises","fieldPromises","populationPromises","populateDepth","maxDepth","undefined","findMany","flattenLocales","siblingDoc","row","objectTypeConfigWithRowFields","select","tabs","tabSchema","tab","subFieldSchema","text","textarea","upload","objectSchema","fieldSchema"],"mappings":"AA6BA,SACEA,cAAc,EACdC,eAAe,EACfC,YAAY,EACZC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,iBAAiB,EACjBC,aAAa,EACbC,gBAAgB,QACX,UAAS;AAChB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,kBAAiB;AACxE,SAASC,cAAc,EAAEC,wBAAwB,EAAEC,iBAAiB,EAAEC,OAAO,QAAQ,UAAS;AAC9F,SAASC,UAAU,QAAQ,iBAAgB;AAI3C,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,gBAAgB,QAAQ,wBAAuB;AAgBxD,OAAO,SAASC,gBAAgB,EAC9BC,IAAI,EACJC,aAAa,CAAC,CAAC,EACfC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,UAAU,EACL;IACL,MAAMC,mBAAmB;QACvBC,OAAO,CAACC,kBAAoCC;YAC1C,MAAMC,gBACJD,OAAOC,iBAAiBjB,kBAAkBY,YAAYf,QAAQmB,MAAMV,IAAI,EAAE;YAE5E,IAAI,CAACK,cAAcO,KAAK,CAACC,UAAU,CAACF,cAAc,EAAE;gBAClD,MAAMG,aAAaf,gBAAgB;oBACjCC,MAAMW;oBACNT;oBACAC,QAAQO,MAAMP,MAAM;oBACpBC,eAAeP,g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BAC1C;wBAGF,IAAII,iBAAiB;4BACnB,IAAI5C,4BAA4B;gCAC9B,OAAO;oCACLD,YAAYwB;oCACZX,OAAO;wCACL,GAAGgC,eAAe;wCAClBtE,YAAYiD;oCACd;gCACF;4BACF;4BAEA,OAAOqB;wBACT;wBAEA,OAAO;oBACT;oBAEA,OAAO;gBACT;YACF;YAEA,OAAO;gBACL,GAAGpH,gBAAgB;gBACnB,CAACC,MAAMV,IAAI,CAAC,EAAE+E;YAChB;QACF;IACF;IAEA,MAAMsE,eAAe;QACnBrJ;QACAG,QAAQ,IACNA,OAAOoB,MAAM,CAAC,CAACd,kBAAkBC;gBAC/B,MAAM4I,cAAc/I,gBAAgB,CAACG,MAAMU,IAAI,CAAC;gBAEhD,IAAI,OAAOkI,gBAAgB,YAAY;oBACrC,OAAO7I;gBACT;gBAEA,OAAO;oBACL,GAAGA,gBAAgB;oBACnB,GAAG6I,YAAY7I,kBAAkBC,MAAM;gBACzC;YACF,GAAGT;IACP;IAEA,MAAM8F,wBAAwB,IAAIhH,kBAAkBsK;IAEpD,OAAOtD;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/buildPoliciesType.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport { GraphQLBoolean, GraphQLNonNull, GraphQLObjectType } from 'graphql'\nimport { toWords } from 'payload'\n\nimport { GraphQLJSONObject } from '../packages/graphql-type-json/index.js'\nimport { formatName } from '../utilities/formatName.js'\n\ntype OperationType = 'create' | 'delete' | 'read' | 'readVersions' | 'unlock' | 'update'\n\ntype AccessScopes = 'docAccess' | undefined\n\ntype ObjectTypeFields = {\n [key in 'fields' | OperationType]?: { type: GraphQLObjectType }\n}\n\nconst buildFields = (label, fieldsToBuild) =>\n fieldsToBuild.reduce((builtFields, field) => {\n const includeField = !field.hidden && field.type !== 'ui'\n if (includeField) {\n if (field.name) {\n const fieldName = formatName(field.name)\n\n const objectTypeFields: ObjectTypeFields = ['create', 'read', 'update', 'delete'].reduce(\n (operations, operation) => {\n const capitalizedOperation = operation.charAt(0).toUpperCase() + operation.slice(1)\n\n return {\n ...operations,\n [operation]: {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}_${capitalizedOperation}`,\n fields: {\n permission: {\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n },\n }),\n },\n }\n },\n {},\n )\n\n if (field.fields) {\n objectTypeFields.fields = {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}_Fields`,\n fields: buildFields(`${label}_${fieldName}`, field.fields),\n }),\n }\n }\n\n return {\n ...builtFields,\n [field.name]: {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}`,\n fields: objectTypeFields,\n }),\n },\n }\n }\n\n if (!field.name && field.fields) {\n const subFields = buildFields(label, field.fields)\n\n return {\n ...builtFields,\n ...subFields,\n }\n }\n\n if (field.type === 'tabs') {\n return field.tabs.reduce(\n (fieldsWithTabFields, tab) => {\n return {\n ...fieldsWithTabFields,\n ...buildFields(label, tab.fields),\n }\n },\n { ...builtFields },\n )\n }\n }\n return builtFields\n }, {})\n\ntype BuildEntityPolicy = {\n entityFields: Field[]\n name: string\n operations: OperationType[]\n scope: AccessScopes\n}\nexport const buildEntityPolicy = (args: BuildEntityPolicy) => {\n const { name, entityFields, operations, scope } = args\n\n const fieldsTypeName = toWords(`${name}-${scope || ''}-Fields`, true)\n const fields = {\n fields: {\n type: new GraphQLObjectType({\n name: fieldsTypeName,\n fields: buildFields(fieldsTypeName, entityFields),\n }),\n },\n }\n\n operations.forEach((operation) => {\n const operationTypeName = toWords(`${name}-${operation}-${scope || 'Access'}`, true)\n\n fields[operation] = {\n type: new GraphQLObjectType({\n name: operationTypeName,\n fields: {\n permission: { type: new GraphQLNonNull(GraphQLBoolean) },\n where: { type: GraphQLJSONObject },\n },\n }),\n }\n })\n\n return fields\n}\n\ntype BuildPolicyType = {\n scope?: AccessScopes\n typeSuffix?: string\n} & (\n | {\n entity: CollectionConfig\n type: 'collection'\n }\n | {\n entity: GlobalConfig\n type: 'global'\n }\n)\nexport function buildPolicyType(args: BuildPolicyType): GraphQLObjectType {\n const { type, entity, scope, typeSuffix } = args\n const { slug, fields, graphQL, versions } = entity\n\n let operations = []\n\n if (graphQL === false) {\n return null\n }\n\n if (type === 'collection') {\n operations = ['create', 'read', 'update', 'delete']\n\n if (\n entity.auth &&\n typeof entity.auth === 'object' &&\n typeof entity.auth.maxLoginAttempts !== 'undefined' &&\n entity.auth.maxLoginAttempts !== 0\n ) {\n operations.push('unlock')\n }\n\n if (versions) {\n operations.push('readVersions')\n }\n\n const collectionTypeName = formatName(`${slug}${typeSuffix || ''}`)\n\n return new GraphQLObjectType({\n name: collectionTypeName,\n fields: buildEntityPolicy({\n name: slug,\n entityFields: fields,\n operations,\n scope,\n }),\n })\n }\n\n // else create global type\n operations = ['read', 'update']\n\n if (entity.versions) {\n operations.push('readVersions')\n }\n\n const globalTypeName = formatName(`${global?.graphQL?.name || slug}${typeSuffix || ''}`)\n\n return new GraphQLObjectType({\n name: globalTypeName,\n fields: buildEntityPolicy({\n name: entity.graphQL ? entity?.graphQL?.name || slug : slug,\n entityFields: entity.fields,\n operations,\n scope,\n }),\n })\n}\n\nexport function buildPoliciesType(config: SanitizedConfig): GraphQLObjectType {\n const fields = {\n canAccessAdmin: {\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n }\n\n Object.values(config.collections).forEach((collection: SanitizedCollectionConfig) => {\n if (collection.graphQL === false) {\n return\n }\n const collectionPolicyType = buildPolicyType({\n type: 'collection',\n entity: collection,\n typeSuffix: 'Access',\n })\n\n fields[formatName(collection.slug)] = {\n type: collectionPolicyType,\n }\n })\n\n Object.values(config.globals).forEach((global: SanitizedGlobalConfig) => {\n if (global.graphQL === false) {\n return\n }\n const globalPolicyType = buildPolicyType({\n type: 'global',\n entity: global,\n typeSuffix: 'Access',\n })\n\n fields[formatName(global.slug)] = {\n type: globalPolicyType,\n }\n })\n\n return new GraphQLObjectType({\n name: 'Access',\n fields,\n })\n}\n"],"names":["GraphQLBoolean","GraphQLNonNull","GraphQLObjectType","toWords","GraphQLJSONObject","formatName","buildFields","label","fieldsToBuild","reduce","builtFields","field","includeField","hidden","type","name","fieldName","objectTypeFields","operations","operation","capitalizedOperation","charAt","toUpperCase","slice","fields","permission","subFields","tabs","fieldsWithTabFields","tab","buildEntityPolicy","args","entityFields","scope","fieldsTypeName","forEach","operationTypeName","where","buildPolicyType","entity","typeSuffix","slug","graphQL","versions","auth","maxLoginAttempts","push","collectionTypeName","globalTypeName","global","buildPoliciesType","config","canAccessAdmin","Object","values","collections","collection","collectionPolicyType","globals","globalPolicyType"],"mappings":"AASA,SAASA,cAAc,EAAEC,cAAc,EAAEC,iBAAiB,QAAQ,UAAS;AAC3E,SAASC,OAAO,QAAQ,UAAS;AAEjC,SAASC,iBAAiB,QAAQ,yCAAwC;AAC1E,SAASC,UAAU,QAAQ,6BAA4B;AAUvD,MAAMC,cAAc,CAACC,OAAOC,gBAC1BA,cAAcC,MAAM,CAAC,CAACC,aAAaC;QACjC,MAAMC,eAAe,CAACD,MAAME,MAAM,IAAIF,MAAMG,IAAI,KAAK;QACrD,IAAIF,cAAc;YAChB,IAAID,MAAMI,IAAI,EAAE;gBACd,MAAMC,YAAYX,WAAWM,MAAMI,IAAI;gBAEvC,MAAME,mBAAqC;oBAAC;oBAAU;oBAAQ;oBAAU;iBAAS,CAACR,MAAM,CACtF,CAACS,YAAYC;oBACX,MAAMC,uBAAuBD,UAAUE,MAAM,CAAC,GAAGC,WAAW,KAAKH,UAAUI,KAAK,CAAC;oBAEjF,OAAO;wBACL,GAAGL,UAAU;wBACb,CAACC,UAAU,EAAE;4BACXL,MAAM,IAAIZ,kBAAkB;gCAC1Ba,MAAM,CAAC,EAAER,MAAM,CAAC,EAAES,UAAU,CAAC,EAAEI,qBAAqB,CAAC;gCACrDI,QAAQ;oCACNC,YAAY;wCACVX,MAA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ollectionConfig,\n Field,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport { GraphQLBoolean, GraphQLNonNull, GraphQLObjectType } from 'graphql'\nimport { toWords } from 'payload'\n\nimport { GraphQLJSONObject } from '../packages/graphql-type-json/index.js'\nimport { formatName } from '../utilities/formatName.js'\n\ntype OperationType = 'create' | 'delete' | 'read' | 'readVersions' | 'unlock' | 'update'\n\ntype AccessScopes = 'docAccess' | undefined\n\ntype ObjectTypeFields = {\n [key in 'fields' | OperationType]?: { type: GraphQLObjectType }\n}\n\nconst buildFields = (label, fieldsToBuild) =>\n fieldsToBuild.reduce((builtFields, field) => {\n const includeField = !field.hidden && field.type !== 'ui'\n if (includeField) {\n if (field.name) {\n const fieldName = formatName(field.name)\n\n const objectTypeFields: ObjectTypeFields = ['create', 'read', 'update', 'delete'].reduce(\n (operations, operation) => {\n const capitalizedOperation = operation.charAt(0).toUpperCase() + operation.slice(1)\n\n return {\n ...operations,\n [operation]: {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}_${capitalizedOperation}`,\n fields: {\n permission: {\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n },\n }),\n },\n }\n },\n {},\n )\n\n if (field.fields) {\n objectTypeFields.fields = {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}_Fields`,\n fields: buildFields(`${label}_${fieldName}`, field.fields),\n }),\n }\n }\n\n return {\n ...builtFields,\n [field.name]: {\n type: new GraphQLObjectType({\n name: `${label}_${fieldName}`,\n fields: objectTypeFields,\n }),\n },\n }\n }\n\n if (!field.name && field.fields) {\n const subFields = buildFields(label, field.fields)\n\n return {\n ...builtFields,\n ...subFields,\n }\n }\n\n if (field.type === 'tabs') {\n return field.tabs.reduce(\n (fieldsWithTabFields, tab) => {\n return {\n ...fieldsWithTabFields,\n ...buildFields(label, tab.fields),\n }\n },\n { ...builtFields },\n )\n }\n }\n return builtFields\n }, {})\n\ntype BuildEntityPolicy = {\n entityFields: Field[]\n name: string\n operations: OperationType[]\n scope: AccessScopes\n}\nexport const buildEntityPolicy = (args: BuildEntityPolicy) => {\n const { name, entityFields, operations, scope } = args\n\n const fieldsTypeName = toWords(`${name}-${scope || ''}-Fields`, true)\n const fields = {\n fields: {\n type: new GraphQLObjectType({\n name: fieldsTypeName,\n fields: buildFields(fieldsTypeName, entityFields),\n }),\n },\n }\n\n operations.forEach((operation) => {\n const operationTypeName = toWords(`${name}-${operation}-${scope || 'Access'}`, true)\n\n fields[operation] = {\n type: new GraphQLObjectType({\n name: operationTypeName,\n fields: {\n permission: { type: new GraphQLNonNull(GraphQLBoolean) },\n where: { type: GraphQLJSONObject },\n },\n }),\n }\n })\n\n return fields\n}\n\ntype BuildPolicyType = {\n scope?: AccessScopes\n typeSuffix?: string\n} & (\n | {\n entity: CollectionConfig\n type: 'collection'\n }\n | {\n entity: GlobalConfig\n type: 'global'\n }\n)\nexport function buildPolicyType(args: BuildPolicyType): GraphQLObjectType {\n const { type, entity, scope, typeSuffix } = args\n const { slug, fields, graphQL, versions } = entity\n\n let operations = []\n\n if (graphQL === false) {\n return null\n }\n\n if (type === 'collection') {\n operations = ['create', 'read', 'update', 'delete']\n\n if (\n entity.auth &&\n typeof entity.auth === 'object' &&\n typeof entity.auth.maxLoginAttempts !== 'undefined' &&\n entity.auth.maxLoginAttempts !== 0\n ) {\n operations.push('unlock')\n }\n\n if (versions) {\n operations.push('readVersions')\n }\n\n const collectionTypeName = formatName(`${slug}${typeSuffix || ''}`)\n\n return new GraphQLObjectType({\n name: collectionTypeName,\n fields: buildEntityPolicy({\n name: slug,\n entityFields: fields,\n operations,\n scope,\n }),\n })\n }\n\n // else create global type\n operations = ['read', 'update']\n\n if (entity.versions) {\n operations.push('readVersions')\n }\n\n const globalTypeName = formatName(`${global?.graphQL?.name || slug}${typeSuffix || ''}`)\n\n return new GraphQLObjectType({\n name: globalTypeName,\n fields: buildEntityPolicy({\n name: entity.graphQL ? entity?.graphQL?.name || slug : slug,\n entityFields: entity.fields,\n operations,\n scope,\n }),\n })\n}\n\nexport function buildPoliciesType(config: SanitizedConfig): GraphQLObjectType {\n const fields = {\n canAccessAdmin: {\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n }\n\n Object.values(config.collections).forEach((collection: SanitizedCollectionConfig) => {\n if (collection.graphQL === false) {\n return\n }\n const collectionPolicyType = buildPolicyType({\n type: 'collection',\n entity: collection,\n typeSuffix: 'Access',\n })\n\n fields[formatName(collection.slug)] = {\n type: collectionPolicyType,\n }\n })\n\n Object.values(config.globals).forEach((global: SanitizedGlobalConfig) => {\n if (global.graphQL === false) {\n return\n }\n const globalPolicyType = buildPolicyType({\n type: 'global',\n entity: global,\n typeSuffix: 'Access',\n })\n\n fields[formatName(global.slug)] = {\n type: globalPolicyType,\n }\n })\n\n return new GraphQLObjectType({\n name: 'Access',\n fields,\n })\n}\n"],"names":["GraphQLBoolean","GraphQLNonNull","GraphQLObjectType","toWords","GraphQLJSONObject","formatName","buildFields","label","fieldsToBuild","reduce","builtFields","field","includeField","hidden","type","name","fieldName","objectTypeFields","operations","operation","capitalizedOperation","charAt","toUpperCase","slice","fields","permission","subFields","tabs","fieldsWithTabFields","tab","buildEntityPolicy","args","entityFields","scope","fieldsTypeName","forEach","operationTypeName","where","buildPolicyType","entity","typeSuffix","slug","graphQL","versions","auth","maxLoginAttempts","push","collectionTypeName","globalTypeName","global","buildPoliciesType","config","canAccessAdmin","Object","values","collections","collection","collectionPolicyType","globals","globalPolicyType"],"mappings":"AASA,SAASA,cAAc,EAAEC,cAAc,EAAEC,iBAAiB,QAAQ,UAAS;AAC3E,SAASC,OAAO,QAAQ,UAAS;AAEjC,SAASC,iBAAiB,QAAQ,yCAAwC;AAC1E,SAASC,UAAU,QAAQ,6BAA4B;AAUvD,MAAMC,cAAc,CAACC,OAAOC,gBAC1BA,cAAcC,MAAM,CAAC,CAACC,aAAaC;QACjC,MAAMC,eAAe,CAACD,MAAME,MAAM,IAAIF,MAAMG,IA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OAAOC,MAAM,CAACH,OAAOO,OAAO,EAAEvB,OAAO,CAAC,CAACc;QACrC,IAAIA,QAAOP,OAAO,KAAK,OAAO;YAC5B;QACF;QACA,MAAMiB,mBAAmBrB,gBAAgB;YACvCxB,MAAM;YACNyB,QAAQU;YACRT,YAAY;QACd;QAEAhB,MAAM,CAACnB,WAAW4C,QAAOR,IAAI,EAAE,GAAG;YAChC3B,MAAM6C;QACR;IACF;IAEA,OAAO,IAAIzD,kBAAkB;QAC3Ba,MAAM;QACNS;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/buildWhereInputType.ts"],"sourcesContent":["import type { Field, FieldAffectingData } from 'payload'\n\nimport { GraphQLInputObjectType, GraphQLList } from 'graphql'\nimport { flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData, fieldHasSubFields, fieldIsPresentationalOnly } from 'payload/shared'\n\nimport { formatName } from '../utilities/formatName.js'\nimport { fieldToSchemaMap } from './fieldToWhereInputSchemaMap.js'\nimport { withOperators } from './withOperators.js'\n\ntype Args = {\n fields: Field[]\n name: string\n parentName: string\n}\n\n/** This does as the function name suggests. It builds a where GraphQL input type\n * for all the fields which are passed to the function.\n * Each field has different operators which may be valid for a where input type.\n * For example, a text field may have a \"contains\" operator, but a number field\n * may not.\n *\n * buildWhereInputType is similar to buildObjectType and operates\n * on a field basis with a few distinct differences.\n *\n * 1. Everything needs to be a GraphQLInputObjectType or scalar / enum\n * 2. Relationships, groups, repeaters and flex content are not\n * directly searchable. Instead, we need to build a chained pathname\n * using dot notation so MongoDB can properly search nested paths.\n */\nexport const buildWhereInputType = ({ name, fields, parentName }: Args): GraphQLInputObjectType => {\n // This is the function that builds nested paths for all\n // field types with nested paths.\n\n const idField = flattenTopLevelFields(fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n const fieldTypes = fields.reduce((schema, field) => {\n if (!fieldIsPresentationalOnly(field) && !field.hidden) {\n const getFieldSchema = fieldToSchemaMap({\n parentName,\n })[field.type]\n\n if (getFieldSchema) {\n const fieldSchema = getFieldSchema(field)\n\n if (fieldHasSubFields(field) || field.type === 'tabs') {\n return {\n ...schema,\n ...fieldSchema.reduce(\n (subFields, subField) => ({\n ...subFields,\n [formatName(subField.key)]: subField.type,\n }),\n {},\n ),\n }\n }\n\n return {\n ...schema,\n [formatName(field.name)]: fieldSchema,\n }\n }\n }\n\n return schema\n }, {})\n\n if (!idField) {\n fieldTypes.id = {\n type: withOperators({ name: 'id', type: 'text' } as FieldAffectingData, parentName),\n }\n }\n\n const fieldName = formatName(name)\n\n const recursiveFields = {\n AND: {\n type: new GraphQLList(\n new GraphQLInputObjectType({\n name: `${fieldName}_where_and`,\n fields: () => ({\n ...fieldTypes,\n ...recursiveFields,\n }),\n }),\n ),\n },\n OR: {\n type: new GraphQLList(\n new GraphQLInputObjectType({\n name: `${fieldName}_where_or`,\n fields: () => ({\n ...fieldTypes,\n ...recursiveFields,\n }),\n }),\n ),\n },\n }\n\n return new GraphQLInputObjectType({\n name: `${fieldName}_where`,\n fields: {\n ...fieldTypes,\n ...recursiveFields,\n },\n })\n}\n"],"names":["GraphQLInputObjectType","GraphQLList","flattenTopLevelFields","fieldAffectsData","fieldHasSubFields","fieldIsPresentationalOnly","formatName","fieldToSchemaMap","withOperators","buildWhereInputType","name","fields","parentName","idField","find","field","fieldTypes","reduce","schema","hidden","getFieldSchema","type","fieldSchema","subFields","subField","key","id","fieldName","recursiveFields","AND","OR"],"mappings":"AAEA,SAASA,sBAAsB,EAAEC,WAAW,QAAQ,UAAS;AAC7D,SAASC,qBAAqB,QAAQ,UAAS;AAC/C,SAASC,gBAAgB,EAAEC,iBAAiB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAE/F,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,gBAAgB,QAAQ,kCAAiC;AAClE,SAASC,aAAa,QAAQ,qBAAoB;AAQlD;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,sBAAsB,CAAC,EAAEC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zBU,MAAM,CAAC,EAAEiB,UAAU,SAAS,CAAC;gBAC7BhB,QAAQ,IAAO,CAAA;wBACb,GAAGK,UAAU;wBACb,GAAGY,eAAe;oBACpB,CAAA;YACF;QAEJ;IACF;IAEA,OAAO,IAAI5B,uBAAuB;QAChCU,MAAM,CAAC,EAAEiB,UAAU,MAAM,CAAC;QAC1BhB,QAAQ;YACN,GAAGK,UAAU;YACb,GAAGY,eAAe;QACpB;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/schema/buildWhereInputType.ts"],"sourcesContent":["import type { Field, FieldAffectingData } from 'payload'\n\nimport { GraphQLInputObjectType, GraphQLList } from 'graphql'\nimport { flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData, fieldHasSubFields, fieldIsPresentationalOnly } from 'payload/shared'\n\nimport { formatName } from '../utilities/formatName.js'\nimport { fieldToSchemaMap } from './fieldToWhereInputSchemaMap.js'\nimport { withOperators } from './withOperators.js'\n\ntype Args = {\n fields: Field[]\n name: string\n parentName: string\n}\n\n/** This does as the function name suggests. It builds a where GraphQL input type\n * for all the fields which are passed to the function.\n * Each field has different operators which may be valid for a where input type.\n * For example, a text field may have a \"contains\" operator, but a number field\n * may not.\n *\n * buildWhereInputType is similar to buildObjectType and operates\n * on a field basis with a few distinct differences.\n *\n * 1. Everything needs to be a GraphQLInputObjectType or scalar / enum\n * 2. Relationships, groups, repeaters and flex content are not\n * directly searchable. Instead, we need to build a chained pathname\n * using dot notation so MongoDB can properly search nested paths.\n */\nexport const buildWhereInputType = ({ name, fields, parentName }: Args): GraphQLInputObjectType => {\n // This is the function that builds nested paths for all\n // field types with nested paths.\n\n const idField = flattenTopLevelFields(fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n const fieldTypes = fields.reduce((schema, field) => {\n if (!fieldIsPresentationalOnly(field) && !field.hidden) {\n const getFieldSchema = fieldToSchemaMap({\n parentName,\n })[field.type]\n\n if (getFieldSchema) {\n const fieldSchema = getFieldSchema(field)\n\n if (fieldHasSubFields(field) || field.type === 'tabs') {\n return {\n ...schema,\n ...fieldSchema.reduce(\n (subFields, subField) => ({\n ...subFields,\n [formatName(subField.key)]: subField.type,\n }),\n {},\n ),\n }\n }\n\n return {\n ...schema,\n [formatName(field.name)]: fieldSchema,\n }\n }\n }\n\n return schema\n }, {})\n\n if (!idField) {\n fieldTypes.id = {\n type: withOperators({ name: 'id', type: 'text' } as FieldAffectingData, parentName),\n }\n }\n\n const fieldName = formatName(name)\n\n const recursiveFields = {\n AND: {\n type: new GraphQLList(\n new GraphQLInputObjectType({\n name: `${fieldName}_where_and`,\n fields: () => ({\n ...fieldTypes,\n ...recursiveFields,\n }),\n }),\n ),\n },\n OR: {\n type: new GraphQLList(\n new GraphQLInputObjectType({\n name: `${fieldName}_where_or`,\n fields: () => ({\n ...fieldTypes,\n ...recursiveFields,\n }),\n }),\n ),\n },\n }\n\n return new GraphQLInputObjectType({\n name: `${fieldName}_where`,\n fields: {\n ...fieldTypes,\n ...recursiveFields,\n },\n })\n}\n"],"names":["GraphQLInputObjectType","GraphQLList","flattenTopLevelFields","fieldAffectsData","fieldHasSubFields","fieldIsPresentationalOnly","formatName","fieldToSchemaMap","withOperators","buildWhereInputType","name","fields","parentName","idField","find","field","fieldTypes","reduce","schema","hidden","getFieldSchema","type","fieldSchema","subFields","subField","key","id","fieldName","recursiveFields","AND","OR"],"mappings":"AAEA,SAASA,sBAAsB,EAAEC,WAAW,QAAQ,UAAS;AAC7D,SAASC,qBAAqB,QAAQ,UAAS;AAC/C,SAASC,gBAAgB,EAAEC,iBAAiB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAE/F,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,gBAAgB,QAAQ,kCAAiC;AAClE,SAASC,aAAa,QAAQ,qBAAoB;AAQlD;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,sBAAsB,CAAC,EAAEC,IAAI,EAAEC,MAAM,EAAEC,UAAU,EAAQ;IACpE,wDAA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AO,CAAA;wBACb,GAAGK,UAAU;wBACb,GAAGY,eAAe;oBACpB,CAAA;YACF;QAEJ;IACF;IAEA,OAAO,IAAI5B,uBAAuB;QAChCU,MAAM,GAAGiB,UAAU,MAAM,CAAC;QAC1BhB,QAAQ;YACN,GAAGK,UAAU;YACb,GAAGY,eAAe;QACpB;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/fieldToWhereInputSchemaMap.ts"],"sourcesContent":["import type {\n ArrayField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport { GraphQLEnumType, GraphQLInputObjectType } from 'graphql'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { recursivelyBuildNestedPaths } from './recursivelyBuildNestedPaths.js'\nimport { withOperators } from './withOperators.js'\n\ntype Args = {\n nestedFieldName?: string\n parentName: string\n}\n\nexport const fieldToSchemaMap = ({ nestedFieldName, parentName }: Args): any => ({\n array: (field: ArrayField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n checkbox: (field: CheckboxField) => ({\n type: withOperators(field, parentName),\n }),\n code: (field: CodeField) => ({\n type: withOperators(field, parentName),\n }),\n collapsible: (field: CollapsibleField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n date: (field: DateField) => ({\n type: withOperators(field, parentName),\n }),\n email: (field: EmailField) => ({\n type: withOperators(field, parentName),\n }),\n group: (field: GroupField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n json: (field: JSONField) => ({\n type: withOperators(field, parentName),\n }),\n number: (field: NumberField) => ({\n type: withOperators(field, parentName),\n }),\n point: (field: PointField) => ({\n type: withOperators(field, parentName),\n }),\n radio: (field: RadioField) => ({\n type: withOperators(field, parentName),\n }),\n relationship: (field: RelationshipField) => {\n if (Array.isArray(field.relationTo)) {\n return {\n type: new GraphQLInputObjectType({\n name: `${combineParentName(parentName, field.name)}_Relation`,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Relation_RelationTo`,\n values: field.relationTo.reduce(\n (values, relation) => ({\n ...values,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n }),\n }\n }\n\n return {\n type: withOperators(field, parentName),\n }\n },\n richText: (field: RichTextField) => ({\n type: withOperators(field, parentName),\n }),\n row: (field: RowField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n select: (field: SelectField) => ({\n type: withOperators(field, parentName),\n }),\n tabs: (field: TabsField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n text: (field: TextField) => ({\n type: withOperators(field, parentName),\n }),\n textarea: (field: TextareaField) => ({\n type: withOperators(field, parentName),\n }),\n upload: (field: UploadField) => {\n if (Array.isArray(field.relationTo)) {\n return {\n type: new GraphQLInputObjectType({\n name: `${combineParentName(parentName, field.name)}_Relation`,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Relation_RelationTo`,\n values: field.relationTo.reduce(\n (values, relation) => ({\n ...values,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n }),\n }\n }\n\n return {\n type: withOperators(field, parentName),\n }\n },\n})\n"],"names":["GraphQLEnumType","GraphQLInputObjectType","GraphQLJSON","combineParentName","formatName","recursivelyBuildNestedPaths","withOperators","fieldToSchemaMap","nestedFieldName","parentName","array","field","nestedFieldName2","checkbox","type","code","collapsible","date","email","group","json","number","point","radio","relationship","Array","isArray","relationTo","name","fields","values","reduce","relation","value","richText","row","select","tabs","text","textarea","upload"],"mappings":"AAsBA,SAASA,eAAe,EAAEC,sBAAsB,QAAQ,UAAS;AAEjE,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,2BAA2B,QAAQ,mCAAkC;AAC9E,SAASC,aAAa,QAAQ,qBAAoB;AAOlD,OAAO,MAAMC,mBAAmB,CAAC,EAAEC,eAAe,EAAEC,UAAU,EAAQ,GAAW,CAAA;QAC/EC,OAAO,CAACC,QACNN,4BAA4B;gBAC1BM;gBACAC,kBAAkBJ;gBAClBC;YACF;QACFI,UAAU,CAACF,QAA0B,CAAA;gBACnCG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAM,MAAM,CAACJ,QAAsB,CAAA;gBAC3BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAO,aAAa,CAACL,QACZN,4BAA4B;gBAC1BM;gBACAC,kBAAkBJ;gBAClBC;YACF;QACFQ,MAAM,CAACN,QAAsB,CAAA;gBAC3BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAS,OAAO,CAACP,QAAuB,CAAA;gBAC7BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAU,OAAO,CAACR,QACNN,4BAA4B;gBAC1BM;gBACAC,kBAAkBJ;gBAClBC;YACF;QACFW,MAAM,CAACT,QAAsB,CAAA;gBAC3BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAY,QAAQ,CAACV,QAAwB,CAAA;gBAC/BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAa,OAAO,CAACX,QAAuB,CAAA;gBAC7BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAc,OAAO,CAACZ,QAAuB,CAAA;gBAC7BG,MAAMR,cAAcK,OAA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AAuB;wBAC/B2B,MAAM,CAAC,EAAEzB,kBAAkBM,YAAYE,MAAMiB,IAAI,EAAE,SAAS,CAAC;wBAC7DC,QAAQ;4BACNF,YAAY;gCACVb,MAAM,IAAId,gBAAgB;oCACxB4B,MAAM,CAAC,EAAEzB,kBAAkBM,YAAYE,MAAMiB,IAAI,EAAE,oBAAoB,CAAC;oCACxEE,QAAQnB,MAAMgB,UAAU,CAACI,MAAM,CAC7B,CAACD,QAAQE,WAAc,CAAA;4CACrB,GAAGF,MAAM;4CACT,CAAC1B,WAAW4B,UAAU,EAAE;gDACtBC,OAAOD;4CACT;wCACF,CAAA,GACA,CAAC;gCAEL;4BACF;4BACAC,OAAO;gCAAEnB,MAAMZ;4BAAY;wBAC7B;oBACF;gBACF;YACF;YAEA,OAAO;gBACLY,MAAMR,cAAcK,OAAOF;YAC7B;QACF;IACF,CAAA,EAAE"}
1
+ {"version":3,"sources":["../../src/schema/fieldToWhereInputSchemaMap.ts"],"sourcesContent":["import type {\n ArrayField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport { GraphQLEnumType, GraphQLInputObjectType } from 'graphql'\n\nimport { GraphQLJSON } from '../packages/graphql-type-json/index.js'\nimport { combineParentName } from '../utilities/combineParentName.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { recursivelyBuildNestedPaths } from './recursivelyBuildNestedPaths.js'\nimport { withOperators } from './withOperators.js'\n\ntype Args = {\n nestedFieldName?: string\n parentName: string\n}\n\nexport const fieldToSchemaMap = ({ nestedFieldName, parentName }: Args): any => ({\n array: (field: ArrayField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n checkbox: (field: CheckboxField) => ({\n type: withOperators(field, parentName),\n }),\n code: (field: CodeField) => ({\n type: withOperators(field, parentName),\n }),\n collapsible: (field: CollapsibleField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n date: (field: DateField) => ({\n type: withOperators(field, parentName),\n }),\n email: (field: EmailField) => ({\n type: withOperators(field, parentName),\n }),\n group: (field: GroupField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n json: (field: JSONField) => ({\n type: withOperators(field, parentName),\n }),\n number: (field: NumberField) => ({\n type: withOperators(field, parentName),\n }),\n point: (field: PointField) => ({\n type: withOperators(field, parentName),\n }),\n radio: (field: RadioField) => ({\n type: withOperators(field, parentName),\n }),\n relationship: (field: RelationshipField) => {\n if (Array.isArray(field.relationTo)) {\n return {\n type: new GraphQLInputObjectType({\n name: `${combineParentName(parentName, field.name)}_Relation`,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Relation_RelationTo`,\n values: field.relationTo.reduce(\n (values, relation) => ({\n ...values,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n }),\n }\n }\n\n return {\n type: withOperators(field, parentName),\n }\n },\n richText: (field: RichTextField) => ({\n type: withOperators(field, parentName),\n }),\n row: (field: RowField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n select: (field: SelectField) => ({\n type: withOperators(field, parentName),\n }),\n tabs: (field: TabsField) =>\n recursivelyBuildNestedPaths({\n field,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n text: (field: TextField) => ({\n type: withOperators(field, parentName),\n }),\n textarea: (field: TextareaField) => ({\n type: withOperators(field, parentName),\n }),\n upload: (field: UploadField) => {\n if (Array.isArray(field.relationTo)) {\n return {\n type: new GraphQLInputObjectType({\n name: `${combineParentName(parentName, field.name)}_Relation`,\n fields: {\n relationTo: {\n type: new GraphQLEnumType({\n name: `${combineParentName(parentName, field.name)}_Relation_RelationTo`,\n values: field.relationTo.reduce(\n (values, relation) => ({\n ...values,\n [formatName(relation)]: {\n value: relation,\n },\n }),\n {},\n ),\n }),\n },\n value: { type: GraphQLJSON },\n },\n }),\n }\n }\n\n return {\n type: withOperators(field, parentName),\n }\n },\n})\n"],"names":["GraphQLEnumType","GraphQLInputObjectType","GraphQLJSON","combineParentName","formatName","recursivelyBuildNestedPaths","withOperators","fieldToSchemaMap","nestedFieldName","parentName","array","field","nestedFieldName2","checkbox","type","code","collapsible","date","email","group","json","number","point","radio","relationship","Array","isArray","relationTo","name","fields","values","reduce","relation","value","richText","row","select","tabs","text","textarea","upload"],"mappings":"AAsBA,SAASA,eAAe,EAAEC,sBAAsB,QAAQ,UAAS;AAEjE,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,2BAA2B,QAAQ,mCAAkC;AAC9E,SAASC,aAAa,QAAQ,qBAAoB;AAOlD,OAAO,MAAMC,mBAAmB,CAAC,EAAEC,eAAe,EAAEC,UAAU,EAAQ,GAAW,CAAA;QAC/EC,OAAO,CAACC,QACNN,4BAA4B;gBAC1BM;gBACAC,kBAAkBJ;gBAClBC;YACF;QACFI,UAAU,CAACF,QAA0B,CAAA;gBACnCG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAM,MAAM,CAACJ,QAAsB,CAAA;gBAC3BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAO,aAAa,CAACL,QACZN,4BAA4B;gBAC1BM;gBACAC,kBAAkBJ;gBAClBC;YACF;QACFQ,MAAM,CAACN,QAAsB,CAAA;gBAC3BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAS,OAAO,CAACP,QAAuB,CAAA;gBAC7BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACAU,OAAO,CAACR,QACNN,4BAA4B;gBAC1BM;gBACAC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M;gBACAC,kBAAkBJ;gBAClBC;YACF;QACF6B,MAAM,CAAC3B,QAAsB,CAAA;gBAC3BG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACA8B,UAAU,CAAC5B,QAA0B,CAAA;gBACnCG,MAAMR,cAAcK,OAAOF;YAC7B,CAAA;QACA+B,QAAQ,CAAC7B;YACP,IAAIc,MAAMC,OAAO,CAACf,MAAMgB,UAAU,GAAG;gBACnC,OAAO;oBACLb,MAAM,IAAIb,uBAAuB;wBAC/B2B,MAAM,GAAGzB,kBAAkBM,YAAYE,MAAMiB,IAAI,EAAE,SAAS,CAAC;wBAC7DC,QAAQ;4BACNF,YAAY;gCACVb,MAAM,IAAId,gBAAgB;oCACxB4B,MAAM,GAAGzB,kBAAkBM,YAAYE,MAAMiB,IAAI,EAAE,oBAAoB,CAAC;oCACxEE,QAAQnB,MAAMgB,UAAU,CAACI,MAAM,CAC7B,CAACD,QAAQE,WAAc,CAAA;4CACrB,GAAGF,MAAM;4CACT,CAAC1B,WAAW4B,UAAU,EAAE;gDACtBC,OAAOD;4CACT;wCACF,CAAA,GACA,CAAC;gCAEL;4BACF;4BACAC,OAAO;gCAAEnB,MAAMZ;4BAAY;wBAC7B;oBACF;gBACF;YACF;YAEA,OAAO;gBACLY,MAAMR,cAAcK,OAAOF;YAC7B;QACF;IACF,CAAA,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"initCollections.d.ts","sourceRoot":"","sources":["../../src/schema/initCollections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,WAAW,EAEX,eAAe,EAChB,MAAM,SAAS,CAAA;AAyChB,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,eAAe,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;CAC3B,CAAA;AACD,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,0BAA0B,GAAG,IAAI,CAqd3F"}
1
+ {"version":3,"file":"initCollections.d.ts","sourceRoot":"","sources":["../../src/schema/initCollections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,WAAW,EAEX,eAAe,EAChB,MAAM,SAAS,CAAA;AAyChB,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,eAAe,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;CAC3B,CAAA;AACD,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,0BAA0B,GAAG,IAAI,CA6d3F"}
@@ -89,12 +89,12 @@ export function initCollections({ config, graphqlResult }) {
89
89
  const mutationInputFields = [
90
90
  ...fields
91
91
  ];
92
- if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {
92
+ if (collectionConfig.auth && (!collectionConfig.auth.disableLocalStrategy || typeof collectionConfig.auth.disableLocalStrategy === 'object' && collectionConfig.auth.disableLocalStrategy.optionalPassword)) {
93
93
  mutationInputFields.push({
94
94
  name: 'password',
95
95
  type: 'text',
96
96
  label: 'Password',
97
- required: true
97
+ required: !(typeof collectionConfig.auth.disableLocalStrategy === 'object' && collectionConfig.auth.disableLocalStrategy.optionalPassword)
98
98
  });
99
99
  }
100
100
  const createMutationInputType = buildMutationInputType({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/initCollections.ts"],"sourcesContent":["import type {\n Collection,\n Field,\n GraphQLInfo,\n SanitizedCollectionConfig,\n SanitizedConfig,\n} from 'payload'\n\nimport {\n GraphQLBoolean,\n GraphQLInt,\n GraphQLNonNull,\n GraphQLObjectType,\n GraphQLString,\n} from 'graphql'\nimport { buildVersionCollectionFields, flattenTopLevelFields, formatNames, toWords } from 'payload'\nimport { fieldAffectsData, getLoginOptions } from 'payload/shared'\n\nimport type { ObjectTypeConfig } from './buildObjectType.js'\n\nimport { forgotPassword } from '../resolvers/auth/forgotPassword.js'\nimport { init } from '../resolvers/auth/init.js'\nimport { login } from '../resolvers/auth/login.js'\nimport { logout } from '../resolvers/auth/logout.js'\nimport { me } from '../resolvers/auth/me.js'\nimport { refresh } from '../resolvers/auth/refresh.js'\nimport { resetPassword } from '../resolvers/auth/resetPassword.js'\nimport { unlock } from '../resolvers/auth/unlock.js'\nimport { verifyEmail } from '../resolvers/auth/verifyEmail.js'\nimport { countResolver } from '../resolvers/collections/count.js'\nimport { createResolver } from '../resolvers/collections/create.js'\nimport { getDeleteResolver } from '../resolvers/collections/delete.js'\nimport { docAccessResolver } from '../resolvers/collections/docAccess.js'\nimport { duplicateResolver } from '../resolvers/collections/duplicate.js'\nimport { findResolver } from '../resolvers/collections/find.js'\nimport { findByIDResolver } from '../resolvers/collections/findByID.js'\nimport { findVersionByIDResolver } from '../resolvers/collections/findVersionByID.js'\nimport { findVersionsResolver } from '../resolvers/collections/findVersions.js'\nimport { restoreVersionResolver } from '../resolvers/collections/restoreVersion.js'\nimport { updateResolver } from '../resolvers/collections/update.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { buildMutationInputType, getCollectionIDType } from './buildMutationInputType.js'\nimport { buildObjectType } from './buildObjectType.js'\nimport { buildPaginatedListType } from './buildPaginatedListType.js'\nimport { buildPolicyType } from './buildPoliciesType.js'\nimport { buildWhereInputType } from './buildWhereInputType.js'\n\ntype InitCollectionsGraphQLArgs = {\n config: SanitizedConfig\n graphqlResult: GraphQLInfo\n}\nexport function initCollections({ config, graphqlResult }: InitCollectionsGraphQLArgs): void {\n Object.keys(graphqlResult.collections).forEach((slug) => {\n const collection: Collection = graphqlResult.collections[slug]\n const {\n config: collectionConfig,\n config: { fields, graphQL = {} as SanitizedCollectionConfig['graphQL'], versions },\n } = collection\n\n if (!graphQL) {\n return\n }\n\n let singularName\n let pluralName\n const fromSlug = formatNames(collection.config.slug)\n if (graphQL.singularName) {\n singularName = toWords(graphQL.singularName, true)\n } else {\n singularName = fromSlug.singular\n }\n if (graphQL.pluralName) {\n pluralName = toWords(graphQL.pluralName, true)\n } else {\n pluralName = fromSlug.plural\n }\n\n // For collections named 'Media' or similar,\n // there is a possibility that the singular name\n // will equal the plural name. Append `all` to the beginning\n // of potential conflicts\n if (singularName === pluralName) {\n pluralName = `all${singularName}`\n }\n\n collection.graphQL = {} as Collection['graphQL']\n\n const hasIDField =\n flattenTopLevelFields(fields).findIndex(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) > -1\n\n const idType = getCollectionIDType(config.db.defaultIDType, collectionConfig)\n\n const baseFields: ObjectTypeConfig = {}\n\n const whereInputFields = [...fields]\n\n if (!hasIDField) {\n baseFields.id = { type: new GraphQLNonNull(idType) }\n whereInputFields.push({\n name: 'id',\n type: config.db.defaultIDType as 'text',\n })\n }\n\n const forceNullableObjectType = Boolean(versions?.drafts)\n\n collection.graphQL.type = buildObjectType({\n name: singularName,\n baseFields,\n config,\n fields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: singularName,\n })\n\n collection.graphQL.paginatedType = buildPaginatedListType(pluralName, collection.graphQL.type)\n\n collection.graphQL.whereInputType = buildWhereInputType({\n name: singularName,\n fields: whereInputFields,\n parentName: singularName,\n })\n\n const mutationInputFields = [...fields]\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n mutationInputFields.push({\n name: 'password',\n type: 'text',\n label: 'Password',\n required: true,\n })\n }\n\n const createMutationInputType = buildMutationInputType({\n name: singularName,\n config,\n fields: mutationInputFields,\n graphqlResult,\n parentName: singularName,\n })\n if (createMutationInputType) {\n collection.graphQL.mutationInputType = new GraphQLNonNull(createMutationInputType)\n }\n\n const updateMutationInputType = buildMutationInputType({\n name: `${singularName}Update`,\n config,\n fields: mutationInputFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n ),\n forceNullable: true,\n graphqlResult,\n parentName: `${singularName}Update`,\n })\n if (updateMutationInputType) {\n collection.graphQL.updateMutationInputType = new GraphQLNonNull(updateMutationInputType)\n }\n\n graphqlResult.Query.fields[singularName] = {\n type: collection.graphQL.type,\n args: {\n id: { type: new GraphQLNonNull(idType) },\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findByIDResolver(collection),\n }\n\n graphqlResult.Query.fields[pluralName] = {\n type: buildPaginatedListType(pluralName, collection.graphQL.type),\n args: {\n draft: { type: GraphQLBoolean },\n where: { type: collection.graphQL.whereInputType },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n limit: { type: GraphQLInt },\n page: { type: GraphQLInt },\n sort: { type: GraphQLString },\n },\n resolve: findResolver(collection),\n }\n\n graphqlResult.Query.fields[`count${pluralName}`] = {\n type: new GraphQLObjectType({\n name: `count${pluralName}`,\n fields: {\n totalDocs: { type: GraphQLInt },\n },\n }),\n args: {\n draft: { type: GraphQLBoolean },\n where: { type: collection.graphQL.whereInputType },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: countResolver(collection),\n }\n\n graphqlResult.Query.fields[`docAccess${singularName}`] = {\n type: buildPolicyType({\n type: 'collection',\n entity: collectionConfig,\n scope: 'docAccess',\n typeSuffix: 'DocAccess',\n }),\n args: {\n id: { type: new GraphQLNonNull(idType) },\n },\n resolve: docAccessResolver(collection),\n }\n\n graphqlResult.Mutation.fields[`create${singularName}`] = {\n type: collection.graphQL.type,\n args: {\n ...(createMutationInputType\n ? { data: { type: collection.graphQL.mutationInputType } }\n : {}),\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: createResolver(collection),\n }\n\n graphqlResult.Mutation.fields[`update${singularName}`] = {\n type: collection.graphQL.type,\n args: {\n id: { type: new GraphQLNonNull(idType) },\n autosave: { type: GraphQLBoolean },\n ...(updateMutationInputType\n ? { data: { type: collection.graphQL.updateMutationInputType } }\n : {}),\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: updateResolver(collection),\n }\n\n graphqlResult.Mutation.fields[`delete${singularName}`] = {\n type: collection.graphQL.type,\n args: {\n id: { type: new GraphQLNonNull(idType) },\n },\n resolve: getDeleteResolver(collection),\n }\n\n if (collectionConfig.disableDuplicate !== true) {\n graphqlResult.Mutation.fields[`duplicate${singularName}`] = {\n type: collection.graphQL.type,\n args: {\n id: { type: new GraphQLNonNull(idType) },\n },\n resolve: duplicateResolver(collection),\n }\n }\n\n if (collectionConfig.versions) {\n const versionIDType = config.db.defaultIDType === 'text' ? GraphQLString : GraphQLInt\n const versionCollectionFields: Field[] = [\n ...buildVersionCollectionFields(config, collectionConfig),\n {\n name: 'id',\n type: config.db.defaultIDType as 'text',\n },\n {\n name: 'createdAt',\n type: 'date',\n label: 'Created At',\n },\n {\n name: 'updatedAt',\n type: 'date',\n label: 'Updated At',\n },\n ]\n\n collection.graphQL.versionType = buildObjectType({\n name: `${singularName}Version`,\n config,\n fields: versionCollectionFields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: `${singularName}Version`,\n })\n\n graphqlResult.Query.fields[`version${formatName(singularName)}`] = {\n type: collection.graphQL.versionType,\n args: {\n id: { type: versionIDType },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findVersionByIDResolver(collection),\n }\n graphqlResult.Query.fields[`versions${pluralName}`] = {\n type: buildPaginatedListType(\n `versions${formatName(pluralName)}`,\n collection.graphQL.versionType,\n ),\n args: {\n where: {\n type: buildWhereInputType({\n name: `versions${singularName}`,\n fields: versionCollectionFields,\n parentName: `versions${singularName}`,\n }),\n },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n limit: { type: GraphQLInt },\n page: { type: GraphQLInt },\n sort: { type: GraphQLString },\n },\n resolve: findVersionsResolver(collection),\n }\n graphqlResult.Mutation.fields[`restoreVersion${formatName(singularName)}`] = {\n type: collection.graphQL.type,\n args: {\n id: { type: versionIDType },\n draft: { type: GraphQLBoolean },\n },\n resolve: restoreVersionResolver(collection),\n }\n }\n\n if (collectionConfig.auth) {\n const authFields: Field[] =\n collectionConfig.auth.disableLocalStrategy ||\n (collectionConfig.auth.loginWithUsername &&\n !collectionConfig.auth.loginWithUsername.allowEmailLogin &&\n !collectionConfig.auth.loginWithUsername.requireEmail)\n ? []\n : [\n {\n name: 'email',\n type: 'email',\n required: true,\n },\n ]\n collection.graphQL.JWT = buildObjectType({\n name: formatName(`${slug}JWT`),\n config,\n fields: [\n ...collectionConfig.fields.filter((field) => fieldAffectsData(field) && field.saveToJWT),\n ...authFields,\n {\n name: 'collection',\n type: 'text',\n required: true,\n },\n ],\n graphqlResult,\n parentName: formatName(`${slug}JWT`),\n })\n\n graphqlResult.Query.fields[`me${singularName}`] = {\n type: new GraphQLObjectType({\n name: formatName(`${slug}Me`),\n fields: {\n collection: {\n type: GraphQLString,\n },\n exp: {\n type: GraphQLInt,\n },\n strategy: {\n type: GraphQLString,\n },\n token: {\n type: GraphQLString,\n },\n user: {\n type: collection.graphQL.type,\n },\n },\n }),\n resolve: me(collection),\n }\n\n graphqlResult.Query.fields[`initialized${singularName}`] = {\n type: GraphQLBoolean,\n resolve: init(collection.config.slug),\n }\n\n graphqlResult.Mutation.fields[`refreshToken${singularName}`] = {\n type: new GraphQLObjectType({\n name: formatName(`${slug}Refreshed${singularName}`),\n fields: {\n exp: {\n type: GraphQLInt,\n },\n refreshedToken: {\n type: GraphQLString,\n },\n strategy: {\n type: GraphQLString,\n },\n user: {\n type: collection.graphQL.JWT,\n },\n },\n }),\n resolve: refresh(collection),\n }\n\n graphqlResult.Mutation.fields[`logout${singularName}`] = {\n type: GraphQLString,\n resolve: logout(collection),\n }\n\n if (!collectionConfig.auth.disableLocalStrategy) {\n const authArgs = {}\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(\n collectionConfig.auth.loginWithUsername,\n )\n\n if (canLoginWithEmail) {\n authArgs['email'] = { type: new GraphQLNonNull(GraphQLString) }\n }\n if (canLoginWithUsername) {\n authArgs['username'] = { type: new GraphQLNonNull(GraphQLString) }\n }\n\n if (collectionConfig.auth.maxLoginAttempts > 0) {\n graphqlResult.Mutation.fields[`unlock${singularName}`] = {\n type: new GraphQLNonNull(GraphQLBoolean),\n args: authArgs,\n resolve: unlock(collection),\n }\n }\n\n graphqlResult.Mutation.fields[`login${singularName}`] = {\n type: new GraphQLObjectType({\n name: formatName(`${slug}LoginResult`),\n fields: {\n exp: {\n type: GraphQLInt,\n },\n token: {\n type: GraphQLString,\n },\n user: {\n type: collection.graphQL.type,\n },\n },\n }),\n args: {\n ...authArgs,\n password: { type: GraphQLString },\n },\n resolve: login(collection),\n }\n\n graphqlResult.Mutation.fields[`forgotPassword${singularName}`] = {\n type: new GraphQLNonNull(GraphQLBoolean),\n args: {\n disableEmail: { type: GraphQLBoolean },\n expiration: { type: GraphQLInt },\n ...authArgs,\n },\n resolve: forgotPassword(collection),\n }\n\n graphqlResult.Mutation.fields[`resetPassword${singularName}`] = {\n type: new GraphQLObjectType({\n name: formatName(`${slug}ResetPassword`),\n fields: {\n token: { type: GraphQLString },\n user: { type: collection.graphQL.type },\n },\n }),\n args: {\n password: { type: GraphQLString },\n token: { type: GraphQLString },\n },\n resolve: resetPassword(collection),\n }\n\n graphqlResult.Mutation.fields[`verifyEmail${singularName}`] = {\n type: GraphQLBoolean,\n args: {\n token: { type: GraphQLString },\n },\n resolve: verifyEmail(collection),\n }\n }\n }\n })\n}\n"],"names":["GraphQLBoolean","GraphQLInt","GraphQLNonNull","GraphQLObjectType","GraphQLString","buildVersionCollectionFields","flattenTopLevelFields","formatNames","toWords","fieldAffectsData","getLoginOptions","forgotPassword","init","login","logout","me","refresh","resetPassword","unlock","verifyEmail","countResolver","createResolver","getDeleteResolver","docAccessResolver","duplicateResolver","findResolver","findByIDResolver","findVersionByIDResolver","findVersionsResolver","restoreVersionResolver","updateResolver","formatName","buildMutationInputType","getCollectionIDType","buildObjectType","buildPaginatedListType","buildPolicyType","buildWhereInputType","initCollections","config","graphqlResult","Object","keys","collections","forEach","slug","collection","collectionConfig","fields","graphQL","versions","singularName","pluralName","fromSlug","singular","plural","hasIDField","findIndex","field","name","idType","db","defaultIDType","baseFields","whereInputFields","id","type","push","forceNullableObjectType","Boolean","drafts","forceNullable","parentName","paginatedType","whereInputType","mutationInputFields","auth","disableLocalStrategy","label","required","createMutationInputType","mutationInputType","updateMutationInputType","filter","Query","args","draft","localization","fallbackLocale","types","fallbackLocaleInputType","locale","localeInputType","resolve","where","limit","page","sort","totalDocs","entity","scope","typeSuffix","Mutation","data","autosave","disableDuplicate","versionIDType","versionCollectionFields","versionType","authFields","loginWithUsername","allowEmailLogin","requireEmail","JWT","saveToJWT","exp","strategy","token","user","refreshedToken","authArgs","canLoginWithEmail","canLoginWithUsername","maxLoginAttempts","password","disableEmail","expiration"],"mappings":"AAQA,SACEA,cAAc,EACdC,UAAU,EACVC,cAAc,EACdC,iBAAiB,EACjBC,aAAa,QACR,UAAS;AAChB,SAASC,4BAA4B,EAAEC,qBAAqB,EAAEC,WAAW,EAAEC,OAAO,QAAQ,UAAS;AACnG,SAASC,gBAAgB,EAAEC,eAAe,QAAQ,iBAAgB;AAIlE,SAASC,cAAc,QAAQ,sCAAqC;AACpE,SAASC,IAAI,QAAQ,4BAA2B;AAChD,SAASC,KAAK,QAAQ,6BAA4B;AAClD,SAASC,MAAM,QAAQ,8BAA6B;AACpD,SAASC,EAAE,QAAQ,0BAAyB;AAC5C,SAASC,OAAO,QAAQ,+BAA8B;AACtD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,MAAM,QAAQ,8BAA6B;AACpD,SAASC,WAAW,QAAQ,mCAAkC;AAC9D,SAASC,aAAa,QAAQ,oCAAmC;AACjE,SAASC,cAAc,QAA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B,MAAM;wBACJ,GAAGmC,QAAQ;wBACXI,UAAU;4BAAE1D,MAAM9D;wBAAc;oBAClC;oBACAyF,SAAShF,MAAMiC;gBACjB;gBAEAN,cAAc8D,QAAQ,CAACtD,MAAM,CAAC,CAAC,cAAc,EAAEG,aAAa,CAAC,CAAC,GAAG;oBAC/De,MAAM,IAAIhE,eAAeF;oBACzBqF,MAAM;wBACJwC,cAAc;4BAAE3D,MAAMlE;wBAAe;wBACrC8H,YAAY;4BAAE5D,MAAMjE;wBAAW;wBAC/B,GAAGuH,QAAQ;oBACb;oBACA3B,SAASlF,eAAemC;gBAC1B;gBAEAN,cAAc8D,QAAQ,CAACtD,MAAM,CAAC,CAAC,aAAa,EAAEG,aAAa,CAAC,CAAC,GAAG;oBAC9De,MAAM,IAAI/D,kBAAkB;wBAC1BwD,MAAM5B,WAAW,CAAC,EAAEc,KAAK,aAAa,CAAC;wBACvCG,QAAQ;4BACNqE,OAAO;gCAAEnD,MAAM9D;4BAAc;4BAC7BkH,MAAM;gCAAEpD,MAAMpB,WAAWG,OAAO,CAACiB,IAAI;4BAAC;wBACxC;oBACF;oBACAmB,MAAM;wBACJuC,UAAU;4BAAE1D,MAAM9D;wBAAc;wBAChCiH,OAAO;4BAAEnD,MAAM9D;wBAAc;oBAC/B;oBACAyF,SAAS5E,cAAc6B;gBACzB;gBAEAN,cAAc8D,QAAQ,CAACtD,MAAM,CAAC,CAAC,WAAW,EAAEG,aAAa,CAAC,CAAC,GAAG;oBAC5De,MAAMlE;oBACNqF,MAAM;wBACJgC,OAAO;4BAAEnD,MAAM9D;wBAAc;oBAC/B;oBACAyF,SAAS1E,YAAY2B;gBACvB;YACF;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/schema/initCollections.ts"],"sourcesContent":["import type {\n Collection,\n Field,\n GraphQLInfo,\n SanitizedCollectionConfig,\n SanitizedConfig,\n} from 'payload'\n\nimport {\n GraphQLBoolean,\n GraphQLInt,\n GraphQLNonNull,\n GraphQLObjectType,\n GraphQLString,\n} from 'graphql'\nimport { buildVersionCollectionFields, flattenTopLevelFields, formatNames, toWords } from 'payload'\nimport { fieldAffectsData, getLoginOptions } from 'payload/shared'\n\nimport type { ObjectTypeConfig } from './buildObjectType.js'\n\nimport { forgotPassword } from '../resolvers/auth/forgotPassword.js'\nimport { init } from '../resolvers/auth/init.js'\nimport { login } from '../resolvers/auth/login.js'\nimport { logout } from '../resolvers/auth/logout.js'\nimport { me } from '../resolvers/auth/me.js'\nimport { refresh } from '../resolvers/auth/refresh.js'\nimport { resetPassword } from '../resolvers/auth/resetPassword.js'\nimport { unlock } from '../resolvers/auth/unlock.js'\nimport { verifyEmail } from '../resolvers/auth/verifyEmail.js'\nimport { countResolver } from '../resolvers/collections/count.js'\nimport { createResolver } from '../resolvers/collections/create.js'\nimport { getDeleteResolver } from '../resolvers/collections/delete.js'\nimport { docAccessResolver } from '../resolvers/collections/docAccess.js'\nimport { duplicateResolver } from '../resolvers/collections/duplicate.js'\nimport { findResolver } from '../resolvers/collections/find.js'\nimport { findByIDResolver } from '../resolvers/collections/findByID.js'\nimport { findVersionByIDResolver } from '../resolvers/collections/findVersionByID.js'\nimport { findVersionsResolver } from '../resolvers/collections/findVersions.js'\nimport { restoreVersionResolver } from '../resolvers/collections/restoreVersion.js'\nimport { updateResolver } from '../resolvers/collections/update.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { buildMutationInputType, getCollectionIDType } from './buildMutationInputType.js'\nimport { buildObjectType } from './buildObjectType.js'\nimport { buildPaginatedListType } from './buildPaginatedListType.js'\nimport { buildPolicyType } from './buildPoliciesType.js'\nimport { buildWhereInputType } from './buildWhereInputType.js'\n\ntype InitCollectionsGraphQLArgs = {\n config: SanitizedConfig\n graphqlResult: GraphQLInfo\n}\nexport function initCollections({ config, graphqlResult }: InitCollectionsGraphQLArgs): void {\n Object.keys(graphqlResult.collections).forEach((slug) => {\n const collection: Collection = graphqlResult.collections[slug]\n const {\n config: collectionConfig,\n config: { fields, graphQL = {} as SanitizedCollectionConfig['graphQL'], versions },\n } = collection\n\n if (!graphQL) {\n return\n }\n\n let singularName\n let pluralName\n const fromSlug = formatNames(collection.config.slug)\n if (graphQL.singularName) {\n singularName = toWords(graphQL.singularName, true)\n } else {\n singularName = fromSlug.singular\n }\n if (graphQL.pluralName) {\n pluralName = toWords(graphQL.pluralName, true)\n } else {\n pluralName = fromSlug.plural\n }\n\n // For collections named 'Media' or similar,\n // there is a possibility that the singular name\n // will equal the plural name. Append `all` to the beginning\n // of potential conflicts\n if (singularName === pluralName) {\n pluralName = `all${singularName}`\n }\n\n collection.graphQL = {} as Collection['graphQL']\n\n const hasIDField =\n flattenTopLevelFields(fields).findIndex(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) > -1\n\n const idType = getCollectionIDType(config.db.defaultIDType, collectionConfig)\n\n const baseFields: ObjectTypeConfig = {}\n\n const whereInputFields = [...fields]\n\n if (!hasIDField) {\n baseFields.id = { type: new GraphQLNonNull(idType) }\n whereInputFields.push({\n name: 'id',\n type: config.db.defaultIDType as 'text',\n })\n }\n\n const forceNullableObjectType = Boolean(versions?.drafts)\n\n collection.graphQL.type = buildObjectType({\n name: singularName,\n baseFields,\n config,\n fields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: singularName,\n })\n\n collection.graphQL.paginatedType = buildPaginatedListType(pluralName, collection.graphQL.type)\n\n collection.graphQL.whereInputType = buildWhereInputType({\n name: singularName,\n fields: whereInputFields,\n parentName: singularName,\n })\n\n const mutationInputFields = [...fields]\n\n if (\n collectionConfig.auth &&\n (!collectionConfig.auth.disableLocalStrategy ||\n (typeof collectionConfig.auth.disableLocalStrategy === 'object' &&\n collectionConfig.auth.disableLocalStrategy.optionalPassword))\n ) {\n mutationInputFields.push({\n name: 'password',\n type: 'text',\n label: 'Password',\n required: !(\n typeof collectionConfig.auth.disableLocalStrategy === 'object' &&\n collectionConfig.auth.disableLocalStrategy.optionalPassword\n ),\n })\n }\n\n const createMutationInputType = buildMutationInputType({\n name: singularName,\n config,\n fields: mutationInputFields,\n graphqlResult,\n parentName: singularName,\n })\n if (createMutationInputType) {\n collection.graphQL.mutationInputType = new GraphQLNonNull(createMutationInputType)\n }\n\n const updateMutationInputType = buildMutationInputType({\n name: `${singularName}Update`,\n config,\n fields: mutationInputFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n ),\n forceNullable: true,\n graphqlResult,\n parentName: `${singularName}Update`,\n })\n if (updateMutationInputType) {\n collection.graphQL.updateMutationInputType = new GraphQLNonNull(updateMutationInputType)\n }\n\n graphqlResult.Query.fields[singularName] = {\n type: collection.graphQL.type,\n args: {\n id: { type: new GraphQLNonNull(idType) },\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findByIDResolver(collection),\n }\n\n graphqlResult.Query.fields[pluralName] = {\n type: buildPaginatedListType(pluralName, collection.graphQL.type),\n args: {\n draft: { type: GraphQLBoolean },\n where: { type: collection.graphQL.whereInputType },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n limit: { type: GraphQLInt },\n page: { type: GraphQLInt },\n sort: { type: GraphQLString },\n },\n resolve: findResolver(collection),\n }\n\n graphqlResult.Query.fields[`count${pluralName}`] = {\n type: new GraphQLObjectType({\n name: `count${pluralName}`,\n fields: {\n totalDocs: { type: GraphQLInt },\n },\n }),\n args: {\n draft: { type: GraphQLBoolean },\n where: { type: collection.graphQL.whereInputType },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: countResolver(collection),\n }\n\n graphqlResult.Query.fields[`docAccess${singularName}`] = {\n type: buildPolicyType({\n type: 'collection',\n entity: collectionConfig,\n scope: 'docAccess',\n typeSuffix: 'DocAccess',\n }),\n args: {\n id: { type: new GraphQLNonNull(idType) },\n },\n resolve: docAccessResolver(collection),\n }\n\n graphqlResult.Mutation.fields[`create${singularName}`] = {\n type: collection.graphQL.type,\n args: {\n ...(createMutationInputType\n ? { data: { type: collection.graphQL.mutationInputType } }\n : {}),\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: createResolver(collection),\n }\n\n graphqlResult.Mutation.fields[`update${singularName}`] = {\n type: collection.graphQL.type,\n args: {\n id: { type: new GraphQLNonNull(idType) },\n autosave: { type: GraphQLBoolean },\n ...(updateMutationInputType\n ? { data: { type: collection.graphQL.updateMutationInputType } }\n : {}),\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: updateResolver(collection),\n }\n\n graphqlResult.Mutation.fields[`delete${singularName}`] = {\n type: collection.graphQL.type,\n args: {\n id: { type: new GraphQLNonNull(idType) },\n },\n resolve: getDeleteResolver(collection),\n }\n\n if (collectionConfig.disableDuplicate !== true) {\n graphqlResult.Mutation.fields[`duplicate${singularName}`] = {\n type: collection.graphQL.type,\n args: {\n id: { type: new GraphQLNonNull(idType) },\n },\n resolve: duplicateResolver(collection),\n }\n }\n\n if (collectionConfig.versions) {\n const versionIDType = config.db.defaultIDType === 'text' ? GraphQLString : GraphQLInt\n const versionCollectionFields: Field[] = [\n ...buildVersionCollectionFields(config, collectionConfig),\n {\n name: 'id',\n type: config.db.defaultIDType as 'text',\n },\n {\n name: 'createdAt',\n type: 'date',\n label: 'Created At',\n },\n {\n name: 'updatedAt',\n type: 'date',\n label: 'Updated At',\n },\n ]\n\n collection.graphQL.versionType = buildObjectType({\n name: `${singularName}Version`,\n config,\n fields: versionCollectionFields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: `${singularName}Version`,\n })\n\n graphqlResult.Query.fields[`version${formatName(singularName)}`] = {\n type: collection.graphQL.versionType,\n args: {\n id: { type: versionIDType },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findVersionByIDResolver(collection),\n }\n graphqlResult.Query.fields[`versions${pluralName}`] = {\n type: buildPaginatedListType(\n `versions${formatName(pluralName)}`,\n collection.graphQL.versionType,\n ),\n args: {\n where: {\n type: buildWhereInputType({\n name: `versions${singularName}`,\n fields: versionCollectionFields,\n parentName: `versions${singularName}`,\n }),\n },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n limit: { type: GraphQLInt },\n page: { type: GraphQLInt },\n sort: { type: GraphQLString },\n },\n resolve: findVersionsResolver(collection),\n }\n graphqlResult.Mutation.fields[`restoreVersion${formatName(singularName)}`] = {\n type: collection.graphQL.type,\n args: {\n id: { type: versionIDType },\n draft: { type: GraphQLBoolean },\n },\n resolve: restoreVersionResolver(collection),\n }\n }\n\n if (collectionConfig.auth) {\n const authFields: Field[] =\n collectionConfig.auth.disableLocalStrategy ||\n (collectionConfig.auth.loginWithUsername &&\n !collectionConfig.auth.loginWithUsername.allowEmailLogin &&\n !collectionConfig.auth.loginWithUsername.requireEmail)\n ? []\n : [\n {\n name: 'email',\n type: 'email',\n required: true,\n },\n ]\n collection.graphQL.JWT = buildObjectType({\n name: formatName(`${slug}JWT`),\n config,\n fields: [\n ...collectionConfig.fields.filter((field) => fieldAffectsData(field) && field.saveToJWT),\n ...authFields,\n {\n name: 'collection',\n type: 'text',\n required: true,\n },\n ],\n graphqlResult,\n parentName: formatName(`${slug}JWT`),\n })\n\n graphqlResult.Query.fields[`me${singularName}`] = {\n type: new GraphQLObjectType({\n name: formatName(`${slug}Me`),\n fields: {\n collection: {\n type: GraphQLString,\n },\n exp: {\n type: GraphQLInt,\n },\n strategy: {\n type: GraphQLString,\n },\n token: {\n type: GraphQLString,\n },\n user: {\n type: collection.graphQL.type,\n },\n },\n }),\n resolve: me(collection),\n }\n\n graphqlResult.Query.fields[`initialized${singularName}`] = {\n type: GraphQLBoolean,\n resolve: init(collection.config.slug),\n }\n\n graphqlResult.Mutation.fields[`refreshToken${singularName}`] = {\n type: new GraphQLObjectType({\n name: formatName(`${slug}Refreshed${singularName}`),\n fields: {\n exp: {\n type: GraphQLInt,\n },\n refreshedToken: {\n type: GraphQLString,\n },\n strategy: {\n type: GraphQLString,\n },\n user: {\n type: collection.graphQL.JWT,\n },\n },\n }),\n resolve: refresh(collection),\n }\n\n graphqlResult.Mutation.fields[`logout${singularName}`] = {\n type: GraphQLString,\n resolve: logout(collection),\n }\n\n if (!collectionConfig.auth.disableLocalStrategy) {\n const authArgs = {}\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(\n collectionConfig.auth.loginWithUsername,\n )\n\n if (canLoginWithEmail) {\n authArgs['email'] = { type: new GraphQLNonNull(GraphQLString) }\n }\n if (canLoginWithUsername) {\n authArgs['username'] = { type: new GraphQLNonNull(GraphQLString) }\n }\n\n if (collectionConfig.auth.maxLoginAttempts > 0) {\n graphqlResult.Mutation.fields[`unlock${singularName}`] = {\n type: new GraphQLNonNull(GraphQLBoolean),\n args: authArgs,\n resolve: unlock(collection),\n }\n }\n\n graphqlResult.Mutation.fields[`login${singularName}`] = {\n type: new GraphQLObjectType({\n name: formatName(`${slug}LoginResult`),\n fields: {\n exp: {\n type: GraphQLInt,\n },\n token: {\n type: GraphQLString,\n },\n user: {\n type: collection.graphQL.type,\n },\n },\n }),\n args: {\n ...authArgs,\n password: { type: GraphQLString },\n },\n resolve: login(collection),\n }\n\n graphqlResult.Mutation.fields[`forgotPassword${singularName}`] = {\n type: new GraphQLNonNull(GraphQLBoolean),\n args: {\n disableEmail: { type: GraphQLBoolean },\n expiration: { type: GraphQLInt },\n ...authArgs,\n },\n resolve: forgotPassword(collection),\n }\n\n graphqlResult.Mutation.fields[`resetPassword${singularName}`] = {\n type: new GraphQLObjectType({\n name: formatName(`${slug}ResetPassword`),\n fields: {\n token: { type: GraphQLString },\n user: { type: collection.graphQL.type },\n },\n }),\n args: {\n password: { type: GraphQLString },\n token: { type: GraphQLString },\n },\n resolve: resetPassword(collection),\n }\n\n graphqlResult.Mutation.fields[`verifyEmail${singularName}`] = {\n type: GraphQLBoolean,\n args: {\n token: { type: GraphQLString },\n },\n resolve: verifyEmail(collection),\n }\n }\n }\n })\n}\n"],"names":["GraphQLBoolean","GraphQLInt","GraphQLNonNull","GraphQLObjectType","GraphQLString","buildVersionCollectionFields","flattenTopLevelFields","formatNames","toWords","fieldAffectsData","getLoginOptions","forgotPassword","init","login","logout","me","refresh","resetPassword","unlock","verifyEmail","countResolver","createResolver","getDeleteResolver","docAccessResolver","duplicateResolver","findResolver","findByIDResolver","findVersionByIDResolver","findVersionsResolver","restoreVersionResolver","updateResolver","formatName","buildMutationInputType","getCollectionIDType","buildObjectType","buildPaginatedListType","buildPolicyType","buildWhereInputType","initCollections","config","graphqlResult","Object","keys","collections","forEach","slug","collection","collectionConfig","fields","graphQL","versions","singularName","pluralName","fromSlug","singular","plural","hasIDField","findIndex","field","name","idType","db","defaultIDType","baseFields","whereInputFields","id","type","push","forceNullableObjectType","Boolean","drafts","forceNullable","parentName","paginatedType","whereInputType","mutationInputFields","auth","disableLocalStrategy","optionalPassword","label","required","createMutationInputType","mutationInputType","updateMutationInputType","filter","Query","args","draft","localization","fallbackLocale","types","fallbackLocaleInputType","locale","localeInputType","resolve","where","limit","page","sort","totalDocs","entity","scope","typeSuffix","Mutation","data","autosave","disableDuplicate","versionIDType","versionCollectionFields","versionType","authFields","loginWithUsername","allowEmailLogin","requireEmail","JWT","saveToJWT","exp","strategy","token","user","refreshedToken","authArgs","canLoginWithEmail","canLoginWithUsername","maxLoginAttempts","password","disableEmail","expiration"],"mappings":"AAQA,SACEA,cAAc,EACdC,UAAU,EACVC,cAAc,EACdC,iBAAiB,EACjBC,aAAa,QACR,UAAS;AAChB,SAASC,4BA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D,MAAM9D;wBAAc;wBAChCkH,OAAO;4BAAEpD,MAAM9D;wBAAc;oBAC/B;oBACA0F,SAAS7E,cAAc6B;gBACzB;gBAEAN,cAAc+D,QAAQ,CAACvD,MAAM,CAAC,CAAC,WAAW,EAAEG,cAAc,CAAC,GAAG;oBAC5De,MAAMlE;oBACNsF,MAAM;wBACJgC,OAAO;4BAAEpD,MAAM9D;wBAAc;oBAC/B;oBACA0F,SAAS3E,YAAY2B;gBACvB;YACF;QACF;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/initGlobals.ts"],"sourcesContent":["import { GraphQLBoolean, GraphQLInt, GraphQLNonNull, GraphQLString } from 'graphql'\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { Field, GraphQLInfo, SanitizedConfig, SanitizedGlobalConfig } from 'payload'\n\nimport { buildVersionGlobalFields, toWords } from 'payload'\n\nimport { docAccessResolver } from '../resolvers/globals/docAccess.js'\nimport { findOne } from '../resolvers/globals/findOne.js'\nimport { findVersionByID } from '../resolvers/globals/findVersionByID.js'\nimport { findVersions } from '../resolvers/globals/findVersions.js'\nimport { restoreVersion } from '../resolvers/globals/restoreVersion.js'\nimport { update } from '../resolvers/globals/update.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { buildMutationInputType } from './buildMutationInputType.js'\nimport { buildObjectType } from './buildObjectType.js'\nimport { buildPaginatedListType } from './buildPaginatedListType.js'\nimport { buildPolicyType } from './buildPoliciesType.js'\nimport { buildWhereInputType } from './buildWhereInputType.js'\n\ntype InitGlobalsGraphQLArgs = {\n config: SanitizedConfig\n graphqlResult: GraphQLInfo\n}\nexport function initGlobals({ config, graphqlResult }: InitGlobalsGraphQLArgs): void {\n Object.keys(graphqlResult.globals.config).forEach((slug) => {\n const global: SanitizedGlobalConfig = graphqlResult.globals.config[slug]\n const { fields, graphQL, versions } = global\n\n if (graphQL === false) {\n return\n }\n\n const formattedName = graphQL?.name ? graphQL.name : singular(toWords(global.slug, true))\n\n const forceNullableObjectType = Boolean(versions?.drafts)\n\n if (!graphqlResult.globals.graphQL) {\n graphqlResult.globals.graphQL = {}\n }\n\n const updateMutationInputType = buildMutationInputType({\n name: formattedName,\n config,\n fields,\n graphqlResult,\n parentName: formattedName,\n })\n graphqlResult.globals.graphQL[slug] = {\n type: buildObjectType({\n name: formattedName,\n config,\n fields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: formattedName,\n }),\n mutationInputType: updateMutationInputType\n ? new GraphQLNonNull(updateMutationInputType)\n : null,\n }\n\n graphqlResult.Query.fields[formattedName] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findOne(global),\n }\n\n graphqlResult.Mutation.fields[`update${formattedName}`] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n ...(updateMutationInputType\n ? { data: { type: graphqlResult.globals.graphQL[slug].mutationInputType } }\n : {}),\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: update(global),\n }\n\n graphqlResult.Query.fields[`docAccess${formattedName}`] = {\n type: buildPolicyType({\n type: 'global',\n entity: global,\n scope: 'docAccess',\n typeSuffix: 'DocAccess',\n }),\n resolve: docAccessResolver(global),\n }\n\n if (global.versions) {\n const idType = config.db.defaultIDType === 'number' ? GraphQLInt : GraphQLString\n\n const versionGlobalFields: Field[] = [\n ...buildVersionGlobalFields(config, global),\n {\n name: 'id',\n type: config.db.defaultIDType as 'text',\n },\n {\n name: 'createdAt',\n type: 'date',\n label: 'Created At',\n },\n {\n name: 'updatedAt',\n type: 'date',\n label: 'Updated At',\n },\n ]\n\n graphqlResult.globals.graphQL[slug].versionType = buildObjectType({\n name: `${formattedName}Version`,\n config,\n fields: versionGlobalFields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: `${formattedName}Version`,\n })\n\n graphqlResult.Query.fields[`version${formatName(formattedName)}`] = {\n type: graphqlResult.globals.graphQL[slug].versionType,\n args: {\n id: { type: idType },\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findVersionByID(global),\n }\n graphqlResult.Query.fields[`versions${formattedName}`] = {\n type: buildPaginatedListType(\n `versions${formatName(formattedName)}`,\n graphqlResult.globals.graphQL[slug].versionType,\n ),\n args: {\n where: {\n type: buildWhereInputType({\n name: `versions${formattedName}`,\n fields: versionGlobalFields,\n parentName: `versions${formattedName}`,\n }),\n },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n limit: { type: GraphQLInt },\n page: { type: GraphQLInt },\n sort: { type: GraphQLString },\n },\n resolve: findVersions(global),\n }\n graphqlResult.Mutation.fields[`restoreVersion${formatName(formattedName)}`] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n id: { type: idType },\n draft: { type: GraphQLBoolean },\n },\n resolve: restoreVersion(global),\n }\n }\n })\n}\n"],"names":["GraphQLBoolean","GraphQLInt","GraphQLNonNull","GraphQLString","pluralize","singular","buildVersionGlobalFields","toWords","docAccessResolver","findOne","findVersionByID","findVersions","restoreVersion","update","formatName","buildMutationInputType","buildObjectType","buildPaginatedListType","buildPolicyType","buildWhereInputType","initGlobals","config","graphqlResult","Object","keys","globals","forEach","slug","global","fields","graphQL","versions","formattedName","name","forceNullableObjectType","Boolean","drafts","updateMutationInputType","parentName","type","forceNullable","mutationInputType","Query","args","draft","localization","fallbackLocale","types","fallbackLocaleInputType","locale","localeInputType","resolve","Mutation","data","entity","scope","typeSuffix","idType","db","defaultIDType","versionGlobalFields","label","versionType","id","where","limit","page","sort"],"mapp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,WAAWkB,eAAe,CAAC,EACtCV,cAAcG,OAAO,CAACK,OAAO,CAACH,KAAK,CAACmC,WAAW;gBAEjDnB,MAAM;oBACJqB,OAAO;wBACLzB,MAAMpB,oBAAoB;4BACxBc,MAAM,CAAC,QAAQ,EAAED,cAAc,CAAC;4BAChCH,QAAQ+B;4BACRtB,YAAY,CAAC,QAAQ,EAAEN,cAAc,CAAC;wBACxC;oBACF;oBACA,GAAIX,OAAOwB,YAAY,GACnB;wBACEC,gBAAgB;4BAAEP,MAAMjB,cAAcyB,KAAK,CAACC,uBAAuB;wBAAC;wBACpEC,QAAQ;4BAAEV,MAAMjB,cAAcyB,KAAK,CAACG,eAAe;wBAAC;oBACtD,IACA,CAAC,CAAC;oBACNe,OAAO;wBAAE1B,MAAMtC;oBAAW;oBAC1BiE,MAAM;wBAAE3B,MAAMtC;oBAAW;oBACzBkE,MAAM;wBAAE5B,MAAMpC;oBAAc;gBAC9B;gBACAgD,SAASxC,aAAaiB;YACxB;YACAN,cAAc8B,QAAQ,CAACvB,MAAM,CAAC,CAAC,cAAc,EAAEf,WAAWkB,eAAe,CAAC,CAAC,GAAG;gBAC5EO,MAAMjB,cAAcG,OAAO,CAACK,OAAO,CAACH,KAAK,CAACY,IAAI;gBAC9CI,MAAM;oBACJoB,IAAI;wBAAExB,MAAMkB;oBAAO;oBACnBb,OAAO;wBAAEL,MAAMvC;oBAAe;gBAChC;gBACAmD,SAASvC,eAAegB;YAC1B;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/schema/initGlobals.ts"],"sourcesContent":["import { GraphQLBoolean, GraphQLInt, GraphQLNonNull, GraphQLString } from 'graphql'\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { Field, GraphQLInfo, SanitizedConfig, SanitizedGlobalConfig } from 'payload'\n\nimport { buildVersionGlobalFields, toWords } from 'payload'\n\nimport { docAccessResolver } from '../resolvers/globals/docAccess.js'\nimport { findOne } from '../resolvers/globals/findOne.js'\nimport { findVersionByID } from '../resolvers/globals/findVersionByID.js'\nimport { findVersions } from '../resolvers/globals/findVersions.js'\nimport { restoreVersion } from '../resolvers/globals/restoreVersion.js'\nimport { update } from '../resolvers/globals/update.js'\nimport { formatName } from '../utilities/formatName.js'\nimport { buildMutationInputType } from './buildMutationInputType.js'\nimport { buildObjectType } from './buildObjectType.js'\nimport { buildPaginatedListType } from './buildPaginatedListType.js'\nimport { buildPolicyType } from './buildPoliciesType.js'\nimport { buildWhereInputType } from './buildWhereInputType.js'\n\ntype InitGlobalsGraphQLArgs = {\n config: SanitizedConfig\n graphqlResult: GraphQLInfo\n}\nexport function initGlobals({ config, graphqlResult }: InitGlobalsGraphQLArgs): void {\n Object.keys(graphqlResult.globals.config).forEach((slug) => {\n const global: SanitizedGlobalConfig = graphqlResult.globals.config[slug]\n const { fields, graphQL, versions } = global\n\n if (graphQL === false) {\n return\n }\n\n const formattedName = graphQL?.name ? graphQL.name : singular(toWords(global.slug, true))\n\n const forceNullableObjectType = Boolean(versions?.drafts)\n\n if (!graphqlResult.globals.graphQL) {\n graphqlResult.globals.graphQL = {}\n }\n\n const updateMutationInputType = buildMutationInputType({\n name: formattedName,\n config,\n fields,\n graphqlResult,\n parentName: formattedName,\n })\n graphqlResult.globals.graphQL[slug] = {\n type: buildObjectType({\n name: formattedName,\n config,\n fields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: formattedName,\n }),\n mutationInputType: updateMutationInputType\n ? new GraphQLNonNull(updateMutationInputType)\n : null,\n }\n\n graphqlResult.Query.fields[formattedName] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findOne(global),\n }\n\n graphqlResult.Mutation.fields[`update${formattedName}`] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n ...(updateMutationInputType\n ? { data: { type: graphqlResult.globals.graphQL[slug].mutationInputType } }\n : {}),\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: update(global),\n }\n\n graphqlResult.Query.fields[`docAccess${formattedName}`] = {\n type: buildPolicyType({\n type: 'global',\n entity: global,\n scope: 'docAccess',\n typeSuffix: 'DocAccess',\n }),\n resolve: docAccessResolver(global),\n }\n\n if (global.versions) {\n const idType = config.db.defaultIDType === 'number' ? GraphQLInt : GraphQLString\n\n const versionGlobalFields: Field[] = [\n ...buildVersionGlobalFields(config, global),\n {\n name: 'id',\n type: config.db.defaultIDType as 'text',\n },\n {\n name: 'createdAt',\n type: 'date',\n label: 'Created At',\n },\n {\n name: 'updatedAt',\n type: 'date',\n label: 'Updated At',\n },\n ]\n\n graphqlResult.globals.graphQL[slug].versionType = buildObjectType({\n name: `${formattedName}Version`,\n config,\n fields: versionGlobalFields,\n forceNullable: forceNullableObjectType,\n graphqlResult,\n parentName: `${formattedName}Version`,\n })\n\n graphqlResult.Query.fields[`version${formatName(formattedName)}`] = {\n type: graphqlResult.globals.graphQL[slug].versionType,\n args: {\n id: { type: idType },\n draft: { type: GraphQLBoolean },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n },\n resolve: findVersionByID(global),\n }\n graphqlResult.Query.fields[`versions${formattedName}`] = {\n type: buildPaginatedListType(\n `versions${formatName(formattedName)}`,\n graphqlResult.globals.graphQL[slug].versionType,\n ),\n args: {\n where: {\n type: buildWhereInputType({\n name: `versions${formattedName}`,\n fields: versionGlobalFields,\n parentName: `versions${formattedName}`,\n }),\n },\n ...(config.localization\n ? {\n fallbackLocale: { type: graphqlResult.types.fallbackLocaleInputType },\n locale: { type: graphqlResult.types.localeInputType },\n }\n : {}),\n limit: { type: GraphQLInt },\n page: { type: GraphQLInt },\n sort: { type: GraphQLString },\n },\n resolve: findVersions(global),\n }\n graphqlResult.Mutation.fields[`restoreVersion${formatName(formattedName)}`] = {\n type: graphqlResult.globals.graphQL[slug].type,\n args: {\n id: { type: idType },\n draft: { type: GraphQLBoolean },\n },\n resolve: restoreVersion(global),\n }\n }\n })\n}\n"],"names":["GraphQLBoolean","GraphQLInt","GraphQLNonNull","GraphQLString","pluralize","singular","buildVersionGlobalFields","toWords","docAccessResolver","findOne","findVersionByID","findVersions","restoreVersion","update","formatName","buildMutationInputType","buildObjectType","buildPaginatedListType","buildPolicyType","buildWhereInputType","initGlobals","config","graphqlResult","Object","keys","globals","forEach","slug","global","fields","graphQL","versions","formattedName","name","forceNullableObjectType","Boolean","drafts","updateMutationInputType","parentName","type","forceNullable","mutationInputType","Query","args","draft","localization","fallbackLocale","types","fallbackLocaleInputType","locale","localeInputType","resolve","Mutation","data","entity","scope","typeSuffix","idType","db","defaultIDType","versionGlobalFields","label","versionType","id","where","limit","page","sort"],"mappings":"AAAA,SAASA,cAAc,EAAEC,UAAU,EAAEC,cAAc,EAAEC,aAAa,QAAQ,UAAS;AACnF,OAAOC,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAIrB,SAASE,wBAAwB,EAAEC,OAAO,QAAQ,UAAS;AAE3D,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,OAAO,QAAQ,kCAAiC;AACzD,SAASC,eAAe,QAAQ,0CAAyC;AACzE,SAASC,YAAY,QAAQ,uCAAsC;AACnE,SAASC,cAAc,QAAQ,yCAAwC;AACvE,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,eAAe,QAAQ,yBAAwB;AACxD,SAASC,mBAAmB,QAAQ,2BAA0B;AAM9D,OAAO,SAASC,YAAY,EAAEC,MAAM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,CAAC,GAAG;gBAC5EO,MAAMjB,cAAcG,OAAO,CAACK,OAAO,CAACH,KAAK,CAACY,IAAI;gBAC9CI,MAAM;oBACJoB,IAAI;wBAAExB,MAAMkB;oBAAO;oBACnBb,OAAO;wBAAEL,MAAMvC;oBAAe;gBAChC;gBACAmD,SAASvC,eAAegB;YAC1B;QACF;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/recursivelyBuildNestedPaths.ts"],"sourcesContent":["import type { FieldWithSubFields, TabsField } from 'payload'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared'\n\nimport { fieldToSchemaMap } from './fieldToWhereInputSchemaMap.js'\n\ntype Args = {\n field: FieldWithSubFields | TabsField\n nestedFieldName2: string\n parentName: string\n}\n\nexport const recursivelyBuildNestedPaths = ({ field, nestedFieldName2, parentName }: Args) => {\n const fieldName = fieldAffectsData(field) ? field.name : undefined\n const nestedFieldName = fieldName || nestedFieldName2\n\n if (field.type === 'tabs') {\n // if the tab has a name, treat it as a group\n // otherwise, treat it as a row\n return field.tabs.reduce((tabSchema, tab: any) => {\n tabSchema.push(\n ...recursivelyBuildNestedPaths({\n field: {\n ...tab,\n type: 'name' in tab ? 'group' : 'row',\n },\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n )\n return tabSchema\n }, [])\n }\n\n const nestedPaths = field.fields.reduce((nestedFields, nestedField) => {\n if (!fieldIsPresentationalOnly(nestedField)) {\n if (!fieldAffectsData(nestedField)) {\n return [\n ...nestedFields,\n ...recursivelyBuildNestedPaths({\n field: nestedField,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n ]\n }\n\n const nestedPathName = fieldAffectsData(nestedField)\n ? `${nestedFieldName ? `${nestedFieldName}__` : ''}${nestedField.name}`\n : undefined\n const getFieldSchema = fieldToSchemaMap({\n nestedFieldName,\n parentName,\n })[nestedField.type]\n\n if (getFieldSchema) {\n const fieldSchema = getFieldSchema({\n ...nestedField,\n name: nestedPathName,\n })\n\n if (Array.isArray(fieldSchema)) {\n return [...nestedFields, ...fieldSchema]\n }\n\n return [\n ...nestedFields,\n {\n type: fieldSchema,\n key: nestedPathName,\n },\n ]\n }\n }\n\n return nestedFields\n }, [])\n\n return nestedPaths\n}\n"],"names":["fieldAffectsData","fieldIsPresentationalOnly","fieldToSchemaMap","recursivelyBuildNestedPaths","field","nestedFieldName2","parentName","fieldName","name","undefined","nestedFieldName","type","tabs","reduce","tabSchema","tab","push","nestedPaths","fields","nestedFields","nestedField","nestedPathName","getFieldSchema","fieldSchema","Array","isArray","key"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAE5E,SAASC,gBAAgB,QAAQ,kCAAiC;AAQlE,OAAO,MAAMC,8BAA8B,CAAC,EAAEC,KAAK,EAAEC,gBAAgB,EAAEC,UAAU,EAAQ;IACvF,MAAMC,YAAYP,iBAAiBI,SAASA,MAAMI,IAAI,GAAGC;IACzD,MAAMC,kBAAkBH,aAAaF;IAErC,IAAID,MAAMO,IAAI,KAAK,QAAQ;QACzB,6CAA6C;QAC7C,+BAA+B;QAC/B,OAAOP,MAAMQ,IAAI,CAACC,MAAM,CAAC,CAACC,WAAWC;YACnCD,UAAUE,IAAI,IACTb,4BAA4B;gBAC7BC,OAAO;oBACL,GAAGW,GAAG;oBACNJ,MAAM,UAAUI,MAAM,UAAU;gBAClC;gBACAV,kBAAkBK;gBAClBJ;YACF;YAEF,OAAOQ;QACT,GAAG,EAAE;IACP;IAEA,MAAMG,cAAcb,MAAMc,MAAM,CAACL,MAAM,CAAC,CAACM,cAAcC;QACrD,IAAI,CAACnB,0BAA0BmB,cAAc;YAC3C,IAAI,CAACpB,iBAAiBoB,cAAc;gBAClC,OAAO;uBACFD;uBACAhB,4BAA4B;wBAC7BC,OAAOgB;wBACPf,kBAAkBK;wBAClBJ;oBACF;iBACD;YACH;YAEA,MAAMe,iBAAiBrB,iBAAiBoB,eACpC,CAAC,EAAEV,kBAAkB,CAAC,EAAEA,gBAAgB,EAAE,CAAC,GAAG,GAAG,EAAEU,YAAYZ,IAAI,CAAC,CAAC,GACrEC;YACJ,MAAMa,iBAAiBpB,iBAAiB;gBACtCQ;gBACAJ;YACF,EAAE,CAACc,YAAYT,IAAI,CAAC;YAEpB,IAAIW,gBAAgB;gBAClB,MAAMC,cAAcD,eAAe;oBACjC,GAAGF,WAAW;oBACdZ,MAAMa;gBACR;gBAEA,IAAIG,MAAMC,OAAO,CAACF,cAAc;oBAC9B,OAAO;2BAAIJ;2BAAiBI;qBAAY;gBAC1C;gBAEA,OAAO;uBACFJ;oBACH;wBACER,MAAMY;wBACNG,KAAKL;oBACP;iBACD;YACH;QACF;QAEA,OAAOF;IACT,GAAG,EAAE;IAEL,OAAOF;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/schema/recursivelyBuildNestedPaths.ts"],"sourcesContent":["import type { FieldWithSubFields, TabsField } from 'payload'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared'\n\nimport { fieldToSchemaMap } from './fieldToWhereInputSchemaMap.js'\n\ntype Args = {\n field: FieldWithSubFields | TabsField\n nestedFieldName2: string\n parentName: string\n}\n\nexport const recursivelyBuildNestedPaths = ({ field, nestedFieldName2, parentName }: Args) => {\n const fieldName = fieldAffectsData(field) ? field.name : undefined\n const nestedFieldName = fieldName || nestedFieldName2\n\n if (field.type === 'tabs') {\n // if the tab has a name, treat it as a group\n // otherwise, treat it as a row\n return field.tabs.reduce((tabSchema, tab: any) => {\n tabSchema.push(\n ...recursivelyBuildNestedPaths({\n field: {\n ...tab,\n type: 'name' in tab ? 'group' : 'row',\n },\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n )\n return tabSchema\n }, [])\n }\n\n const nestedPaths = field.fields.reduce((nestedFields, nestedField) => {\n if (!fieldIsPresentationalOnly(nestedField)) {\n if (!fieldAffectsData(nestedField)) {\n return [\n ...nestedFields,\n ...recursivelyBuildNestedPaths({\n field: nestedField,\n nestedFieldName2: nestedFieldName,\n parentName,\n }),\n ]\n }\n\n const nestedPathName = fieldAffectsData(nestedField)\n ? `${nestedFieldName ? `${nestedFieldName}__` : ''}${nestedField.name}`\n : undefined\n const getFieldSchema = fieldToSchemaMap({\n nestedFieldName,\n parentName,\n })[nestedField.type]\n\n if (getFieldSchema) {\n const fieldSchema = getFieldSchema({\n ...nestedField,\n name: nestedPathName,\n })\n\n if (Array.isArray(fieldSchema)) {\n return [...nestedFields, ...fieldSchema]\n }\n\n return [\n ...nestedFields,\n {\n type: fieldSchema,\n key: nestedPathName,\n },\n ]\n }\n }\n\n return nestedFields\n }, [])\n\n return nestedPaths\n}\n"],"names":["fieldAffectsData","fieldIsPresentationalOnly","fieldToSchemaMap","recursivelyBuildNestedPaths","field","nestedFieldName2","parentName","fieldName","name","undefined","nestedFieldName","type","tabs","reduce","tabSchema","tab","push","nestedPaths","fields","nestedFields","nestedField","nestedPathName","getFieldSchema","fieldSchema","Array","isArray","key"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAE5E,SAASC,gBAAgB,QAAQ,kCAAiC;AAQlE,OAAO,MAAMC,8BAA8B,CAAC,EAAEC,KAAK,EAAEC,gBAAgB,EAAEC,UAAU,EAAQ;IACvF,MAAMC,YAAYP,iBAAiBI,SAASA,MAAMI,IAAI,GAAGC;IACzD,MAAMC,kBAAkBH,aAAaF;IAErC,IAAID,MAAMO,IAAI,KAAK,QAAQ;QACzB,6CAA6C;QAC7C,+BAA+B;QAC/B,OAAOP,MAAMQ,IAAI,CAACC,MAAM,CAAC,CAACC,WAAWC;YACnCD,UAAUE,IAAI,IACTb,4BAA4B;gBAC7BC,OAAO;oBACL,GAAGW,GAAG;oBACNJ,MAAM,UAAUI,MAAM,UAAU;gBAClC;gBACAV,kBAAkBK;gBAClBJ;YACF;YAEF,OAAOQ;QACT,GAAG,EAAE;IACP;IAEA,MAAMG,cAAcb,MAAMc,MAAM,CAACL,MAAM,CAAC,CAACM,cAAcC;QACrD,IAAI,CAACnB,0BAA0BmB,cAAc;YAC3C,IAAI,CAACpB,iBAAiBoB,cAAc;gBAClC,OAAO;uBACFD;uBACAhB,4BAA4B;wBAC7BC,OAAOgB;wBACPf,kBAAkBK;wBAClBJ;oBACF;iBACD;YACH;YAEA,MAAMe,iBAAiBrB,iBAAiBoB,eACpC,GAAGV,kBAAkB,GAAGA,gBAAgB,EAAE,CAAC,GAAG,KAAKU,YAAYZ,IAAI,EAAE,GACrEC;YACJ,MAAMa,iBAAiBpB,iBAAiB;gBACtCQ;gBACAJ;YACF,EAAE,CAACc,YAAYT,IAAI,CAAC;YAEpB,IAAIW,gBAAgB;gBAClB,MAAMC,cAAcD,eAAe;oBACjC,GAAGF,WAAW;oBACdZ,MAAMa;gBACR;gBAEA,IAAIG,MAAMC,OAAO,CAACF,cAAc;oBAC9B,OAAO;2BAAIJ;2BAAiBI;qBAAY;gBAC1C;gBAEA,OAAO;uBACFJ;oBACH;wBACER,MAAMY;wBACNG,KAAKL;oBACP;iBACD;YACH;QACF;QAEA,OAAOF;IACT,GAAG,EAAE;IAEL,OAAOF;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/withOperators.ts"],"sourcesContent":["import type { GraphQLType } from 'graphql'\nimport type { FieldAffectingData, NumberField, RadioField, SelectField } from 'payload'\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/shared'\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 dynamicTypes]: {\n operators: {\n name: string\n type: (field: FieldAffectingData, parentName: string) => GraphQLType\n }[]\n }\n} & {\n [key in staticTypes]: {\n operators: {\n name: string\n type: ((field: FieldAffectingData, parentName: string) => GraphQLType) | 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, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\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]) {\n throw new Error(`Error: ${field.type} has no defaults configured.`)\n }\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"],"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,iBAAgB;AAE/C,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,SAAS,QAAQ,iBAAgB;AAkB1C,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,QAAQ,CAACC,GAAG,CAAC,CAACC,WAAc,CAAA;oBACvCR,MAAMQ;oBACNN,MAAMjB;gBACR,CAAA;SACD;IACH;IACAwB,MAAM;QACJX,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUY,OAAO;aAAC,CAACH,GAAG,CAAC,CAACC,WAAc,CAAA;oBAClER,MAAMQ;oBACNN,MAAMX;gBACR,CAAA;SACD;IACH;IACAoB,MAAM;QACJb,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUc,UAAU;gBAAE;aAAO,CAACL,GAAG,CAAC,CAACC,WAAc,CAAA;oBAC7ER,MAAMQ;oBACNN,MAAMV;gBACR,CAAA;SACD;IACH;IACAqB,OAAO;QACLf,WAAW;eACN;mBAAIA,UAAUQ,QAAQ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ACpC,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'\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/shared'\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 dynamicTypes]: {\n operators: {\n name: string\n type: (field: FieldAffectingData, parentName: string) => GraphQLType\n }[]\n }\n} & {\n [key in staticTypes]: {\n operators: {\n name: string\n type: ((field: FieldAffectingData, parentName: string) => GraphQLType) | 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, ...operators.contains].map((operator) => ({\n name: operator,\n type: GraphQLJSON,\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]) {\n throw new Error(`Error: ${field.type} has no defaults configured.`)\n }\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"],"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,iBAAgB;AAE/C,SAASC,WAAW,QAAQ,yCAAwC;AACpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,SAAS,QAAQ,iBAAgB;AAkB1C,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,QAAQ,CAACC,GAAG,CAAC,CAACC,WAAc,CAAA;oBACvCR,MAAMQ;oBACNN,MAAMjB;gBACR,CAAA;SACD;IACH;IACAwB,MAAM;QACJX,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUY,OAAO;aAAC,CAACH,GAAG,CAAC,CAACC,WAAc,CAAA;oBAClER,MAAMQ;oBACNN,MAAMX;gBACR,CAAA;SACD;IACH;IACAoB,MAAM;QACJb,WAAW;eACN;mBAAIA,UAAUQ,QAAQ;mBAAKR,UAAUc,UAAU;gBAAE;aAAO,CAACL,GAAG,CAAC,CAACC,WAAc,CAAA;oBAC7ER,MAAMQ;oBACNN,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E,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 +1 @@
1
- {"version":3,"sources":["../../src/utilities/combineParentName.ts"],"sourcesContent":["import { formatName } from './formatName.js'\n\nexport const combineParentName = (parent: string, name: string): string =>\n formatName(`${parent ? `${parent}_` : ''}${name}`)\n"],"names":["formatName","combineParentName","parent","name"],"mappings":"AAAA,SAASA,UAAU,QAAQ,kBAAiB;AAE5C,OAAO,MAAMC,oBAAoB,CAACC,QAAgBC,OAChDH,WAAW,CAAC,EAAEE,SAAS,CAAC,EAAEA,OAAO,CAAC,CAAC,GAAG,GAAG,EAAEC,KAAK,CAAC,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/combineParentName.ts"],"sourcesContent":["import { formatName } from './formatName.js'\n\nexport const combineParentName = (parent: string, name: string): string =>\n formatName(`${parent ? `${parent}_` : ''}${name}`)\n"],"names":["formatName","combineParentName","parent","name"],"mappings":"AAAA,SAASA,UAAU,QAAQ,kBAAiB;AAE5C,OAAO,MAAMC,oBAAoB,CAACC,QAAgBC,OAChDH,WAAW,GAAGE,SAAS,GAAGA,OAAO,CAAC,CAAC,GAAG,KAAKC,MAAM,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/formatName.ts"],"sourcesContent":["const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n\nexport const formatName = (string: string): string => {\n let sanitizedString = String(string)\n\n const firstLetter = sanitizedString.substring(0, 1)\n\n if (numbers.indexOf(firstLetter) > -1) {\n sanitizedString = `_${sanitizedString}`\n }\n\n const formatted = sanitizedString\n // Convert accented characters\n .normalize('NFKD')\n .replace(/[\\u0300-\\u036f]/g, '')\n\n .replace(/\\./g, '_')\n .replace(/-|\\//g, '_')\n .replace(/\\+/g, '_')\n .replace(/,/g, '_')\n .replace(/\\(/g, '_')\n .replace(/\\)/g, '_')\n .replace(/'/g, '_')\n .replace(/ /g, '')\n\n return formatted || '_'\n}\n"],"names":["numbers","formatName","string","sanitizedString","String","firstLetter","substring","indexOf","formatted","normalize","replace"],"mappings":"AAAA,MAAMA,UAAU;IAAC;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;CAAI;AAElE,OAAO,MAAMC,aAAa,CAACC;IACzB,IAAIC,kBAAkBC,OAAOF;IAE7B,MAAMG,cAAcF,gBAAgBG,SAAS,CAAC,GAAG;IAEjD,IAAIN,QAAQO,OAAO,CAACF,eAAe,CAAC,GAAG;QACrCF,kBAAkB,CAAC,CAAC,EAAEA,gBAAgB,CAAC;IACzC;IAEA,MAAMK,YAAYL,eAChB,8BAA8B;KAC7BM,SAAS,CAAC,QACVC,OAAO,CAAC,oBAAoB,IAE5BA,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,SAAS,KACjBA,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,MAAM,KACdA,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,MAAM,KACdA,OAAO,CAAC,MAAM;IAEjB,OAAOF,aAAa;AACtB,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/formatName.ts"],"sourcesContent":["const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n\nexport const formatName = (string: string): string => {\n let sanitizedString = String(string)\n\n const firstLetter = sanitizedString.substring(0, 1)\n\n if (numbers.indexOf(firstLetter) > -1) {\n sanitizedString = `_${sanitizedString}`\n }\n\n const formatted = sanitizedString\n // Convert accented characters\n .normalize('NFKD')\n .replace(/[\\u0300-\\u036f]/g, '')\n\n .replace(/\\./g, '_')\n .replace(/-|\\//g, '_')\n .replace(/\\+/g, '_')\n .replace(/,/g, '_')\n .replace(/\\(/g, '_')\n .replace(/\\)/g, '_')\n .replace(/'/g, '_')\n .replace(/ /g, '')\n\n return formatted || '_'\n}\n"],"names":["numbers","formatName","string","sanitizedString","String","firstLetter","substring","indexOf","formatted","normalize","replace"],"mappings":"AAAA,MAAMA,UAAU;IAAC;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;CAAI;AAElE,OAAO,MAAMC,aAAa,CAACC;IACzB,IAAIC,kBAAkBC,OAAOF;IAE7B,MAAMG,cAAcF,gBAAgBG,SAAS,CAAC,GAAG;IAEjD,IAAIN,QAAQO,OAAO,CAACF,eAAe,CAAC,GAAG;QACrCF,kBAAkB,CAAC,CAAC,EAAEA,iBAAiB;IACzC;IAEA,MAAMK,YAAYL,eAChB,8BAA8B;KAC7BM,SAAS,CAAC,QACVC,OAAO,CAAC,oBAAoB,IAE5BA,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,SAAS,KACjBA,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,MAAM,KACdA,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,OAAO,KACfA,OAAO,CAAC,MAAM,KACdA,OAAO,CAAC,MAAM;IAEjB,OAAOF,aAAa;AACtB,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/graphql",
3
- "version": "3.2.3-canary.673b4b5",
3
+ "version": "3.3.0",
4
4
  "homepage": "https://payloadcms.com",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,12 +51,12 @@
51
51
  "devDependencies": {
52
52
  "@types/pluralize": "^0.0.33",
53
53
  "graphql-http": "^1.22.0",
54
- "@payloadcms/eslint-config": "3.0.0",
55
- "payload": "3.2.3-canary.673b4b5"
54
+ "payload": "3.3.0",
55
+ "@payloadcms/eslint-config": "3.0.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "graphql": "^16.8.1",
59
- "payload": "3.2.3-canary.673b4b5"
59
+ "payload": "3.3.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "pnpm build:types && pnpm build:swc",