@payloadcms/graphql 3.23.0 → 3.24.0-canary.05013b2

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.
@@ -15,8 +15,9 @@ type BuildMutationInputTypeArgs = {
15
15
  forceNullable?: boolean;
16
16
  graphqlResult: GraphQLInfo;
17
17
  name: string;
18
+ parentIsLocalized: boolean;
18
19
  parentName: string;
19
20
  };
20
- export declare function buildMutationInputType({ name, config, fields, forceNullable, graphqlResult, parentName, }: BuildMutationInputTypeArgs): GraphQLInputObjectType | null;
21
+ export declare function buildMutationInputType({ name, config, fields, forceNullable, graphqlResult, parentIsLocalized, parentName, }: BuildMutationInputTypeArgs): GraphQLInputObjectType | null;
21
22
  export {};
22
23
  //# sourceMappingURL=buildMutationInputType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildMutationInputType.d.ts","sourceRoot":"","sources":["../../src/schema/buildMutationInputType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAe,MAAM,SAAS,CAAA;AACtF,OAAO,KAAK,EAQV,KAAK,EACL,WAAW,EASX,yBAAyB,EACzB,eAAe,EAMhB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAIL,sBAAsB,EAKvB,MAAM,SAAS,CAAA;AAUhB,QAAA,MAAM,YAAY;;;CAGjB,CAAA;AAED,eAAO,MAAM,mBAAmB,SACxB,MAAM,OAAO,YAAY,cACnB,yBAAyB,KACpC,iBAUF,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,CAAA;CACxC,CAAA;AAED,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,sBAAsB,CAAC,EACrC,IAAI,EACJ,MAAM,EACN,MAAM,EACN,aAAqB,EACrB,aAAa,EACb,UAAU,GACX,EAAE,0BAA0B,GAAG,sBAAsB,GAAG,IAAI,CAyT5D"}
1
+ {"version":3,"file":"buildMutationInputType.d.ts","sourceRoot":"","sources":["../../src/schema/buildMutationInputType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAe,MAAM,SAAS,CAAA;AACtF,OAAO,KAAK,EAQV,KAAK,EACL,WAAW,EASX,yBAAyB,EACzB,eAAe,EAMhB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAIL,sBAAsB,EAKvB,MAAM,SAAS,CAAA;AAUhB,QAAA,MAAM,YAAY;;;CAGjB,CAAA;AAED,eAAO,MAAM,mBAAmB,SACxB,MAAM,OAAO,YAAY,cACnB,yBAAyB,KACpC,iBAUF,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,CAAA;CACxC,CAAA;AAED,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,iBAAiB,EAAE,OAAO,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,sBAAsB,CAAC,EACrC,IAAI,EACJ,MAAM,EACN,MAAM,EACN,aAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,UAAU,GACX,EAAE,0BAA0B,GAAG,sBAAsB,GAAG,IAAI,CAmV5D"}
@@ -17,7 +17,7 @@ export const getCollectionIDType = (type, collection)=>{
17
17
  }
18
18
  return idFieldTypes[idField.type];
19
19
  };
20
- export function buildMutationInputType({ name, config, fields, forceNullable = false, graphqlResult, parentName }) {
20
+ export function buildMutationInputType({ name, config, fields, forceNullable = false, graphqlResult, parentIsLocalized, parentName }) {
21
21
  const fieldToSchemaMap = {
22
22
  array: (inputObjectTypeConfig, field)=>{
23
23
  const fullName = combineParentName(parentName, toWords(field.name, true));
@@ -26,12 +26,18 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
26
26
  config,
27
27
  fields: field.fields,
28
28
  graphqlResult,
29
+ parentIsLocalized: parentIsLocalized || field.localized,
29
30
  parentName: fullName
30
31
  });
31
32
  if (!type) {
32
33
  return inputObjectTypeConfig;
33
34
  }
34
- type = new GraphQLList(withNullableType(field, type, forceNullable));
35
+ type = new GraphQLList(withNullableType({
36
+ type,
37
+ field,
38
+ forceNullable,
39
+ parentIsLocalized
40
+ }));
35
41
  return {
36
42
  ...inputObjectTypeConfig,
37
43
  [field.name]: {
@@ -54,7 +60,12 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
54
60
  code: (inputObjectTypeConfig, field)=>({
55
61
  ...inputObjectTypeConfig,
56
62
  [field.name]: {
57
- type: withNullableType(field, GraphQLString, forceNullable)
63
+ type: withNullableType({
64
+ type: GraphQLString,
65
+ field,
66
+ forceNullable,
67
+ parentIsLocalized
68
+ })
58
69
  }
59
70
  }),
60
71
  collapsible: (inputObjectTypeConfig, field)=>field.fields.reduce((acc, subField)=>{
@@ -67,13 +78,23 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
67
78
  date: (inputObjectTypeConfig, field)=>({
68
79
  ...inputObjectTypeConfig,
69
80
  [field.name]: {
70
- type: withNullableType(field, GraphQLString, forceNullable)
81
+ type: withNullableType({
82
+ type: GraphQLString,
83
+ field,
84
+ forceNullable,
85
+ parentIsLocalized
86
+ })
71
87
  }
72
88
  }),
73
89
  email: (inputObjectTypeConfig, field)=>({
74
90
  ...inputObjectTypeConfig,
75
91
  [field.name]: {
76
- type: withNullableType(field, GraphQLString, forceNullable)
92
+ type: withNullableType({
93
+ type: GraphQLString,
94
+ field,
95
+ forceNullable,
96
+ parentIsLocalized
97
+ })
77
98
  }
78
99
  }),
79
100
  group: (inputObjectTypeConfig, field)=>{
@@ -84,6 +105,7 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
84
105
  config,
85
106
  fields: field.fields,
86
107
  graphqlResult,
108
+ parentIsLocalized: parentIsLocalized || field.localized,
87
109
  parentName: fullName
88
110
  });
89
111
  if (!type) {
@@ -102,7 +124,12 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
102
124
  json: (inputObjectTypeConfig, field)=>({
103
125
  ...inputObjectTypeConfig,
104
126
  [field.name]: {
105
- type: withNullableType(field, GraphQLJSON, forceNullable)
127
+ type: withNullableType({
128
+ type: GraphQLJSON,
129
+ field,
130
+ forceNullable,
131
+ parentIsLocalized
132
+ })
106
133
  }
107
134
  }),
108
135
  number: (inputObjectTypeConfig, field)=>{
@@ -110,20 +137,35 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
110
137
  return {
111
138
  ...inputObjectTypeConfig,
112
139
  [field.name]: {
113
- type: withNullableType(field, field.hasMany === true ? new GraphQLList(type) : type, forceNullable)
140
+ type: withNullableType({
141
+ type: field.hasMany === true ? new GraphQLList(type) : type,
142
+ field,
143
+ forceNullable,
144
+ parentIsLocalized
145
+ })
114
146
  }
115
147
  };
116
148
  },
117
149
  point: (inputObjectTypeConfig, field)=>({
118
150
  ...inputObjectTypeConfig,
119
151
  [field.name]: {
120
- type: withNullableType(field, new GraphQLList(GraphQLFloat), forceNullable)
152
+ type: withNullableType({
153
+ type: new GraphQLList(GraphQLFloat),
154
+ field,
155
+ forceNullable,
156
+ parentIsLocalized
157
+ })
121
158
  }
122
159
  }),
123
160
  radio: (inputObjectTypeConfig, field)=>({
124
161
  ...inputObjectTypeConfig,
125
162
  [field.name]: {
126
- type: withNullableType(field, GraphQLString, forceNullable)
163
+ type: withNullableType({
164
+ type: GraphQLString,
165
+ field,
166
+ forceNullable,
167
+ parentIsLocalized
168
+ })
127
169
  }
128
170
  }),
129
171
  relationship: (inputObjectTypeConfig, field)=>{
@@ -163,7 +205,12 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
163
205
  richText: (inputObjectTypeConfig, field)=>({
164
206
  ...inputObjectTypeConfig,
165
207
  [field.name]: {
166
- type: withNullableType(field, GraphQLJSON, forceNullable)
208
+ type: withNullableType({
209
+ type: GraphQLJSON,
210
+ field,
211
+ forceNullable,
212
+ parentIsLocalized
213
+ })
167
214
  }
168
215
  }),
169
216
  row: (inputObjectTypeConfig, field)=>field.fields.reduce((acc, subField)=>{
@@ -195,7 +242,12 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
195
242
  }, {})
196
243
  });
197
244
  type = field.hasMany ? new GraphQLList(type) : type;
198
- type = withNullableType(field, type, forceNullable);
245
+ type = withNullableType({
246
+ type,
247
+ field,
248
+ forceNullable,
249
+ parentIsLocalized
250
+ });
199
251
  return {
200
252
  ...inputObjectTypeConfig,
201
253
  [field.name]: {
@@ -213,6 +265,7 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
213
265
  config,
214
266
  fields: tab.fields,
215
267
  graphqlResult,
268
+ parentIsLocalized: parentIsLocalized || tab.localized,
216
269
  parentName: fullName
217
270
  });
218
271
  if (!type) {
@@ -243,13 +296,23 @@ export function buildMutationInputType({ name, config, fields, forceNullable = f
243
296
  text: (inputObjectTypeConfig, field)=>({
244
297
  ...inputObjectTypeConfig,
245
298
  [field.name]: {
246
- type: withNullableType(field, field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString, forceNullable)
299
+ type: withNullableType({
300
+ type: field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,
301
+ field,
302
+ forceNullable,
303
+ parentIsLocalized
304
+ })
247
305
  }
248
306
  }),
249
307
  textarea: (inputObjectTypeConfig, field)=>({
250
308
  ...inputObjectTypeConfig,
251
309
  [field.name]: {
252
- type: withNullableType(field, GraphQLString, forceNullable)
310
+ type: withNullableType({
311
+ type: GraphQLString,
312
+ field,
313
+ forceNullable,
314
+ parentIsLocalized
315
+ })
253
316
  }
254
317
  }),
255
318
  upload: (inputObjectTypeConfig, field)=>{
@@ -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,K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MAAM,CAAC,QAAQ,EAAE8C,UAAU,KAAK,CAAC;QACjCjD,QAAQkD;IACV;AACF"}
1
+ {"version":3,"sources":["../../src/schema/buildMutationInputType.ts"],"sourcesContent":["import type { GraphQLInputFieldConfig, GraphQLScalarType, GraphQLType } from 'graphql'\nimport type {\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 parentIsLocalized: boolean\n parentName: string\n}\n\nexport function buildMutationInputType({\n name,\n config,\n fields,\n forceNullable = false,\n graphqlResult,\n parentIsLocalized,\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 parentIsLocalized: parentIsLocalized || field.localized,\n parentName: fullName,\n })\n\n if (!type) {\n return inputObjectTypeConfig\n }\n\n type = new GraphQLList(withNullableType({ type, field, forceNullable, parentIsLocalized }))\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]: {\n type: withNullableType({ type: GraphQLString, field, forceNullable, parentIsLocalized }),\n },\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]: {\n type: withNullableType({ type: GraphQLString, field, forceNullable, parentIsLocalized }),\n },\n }),\n email: (inputObjectTypeConfig: InputObjectTypeConfig, field: EmailField) => ({\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType({ type: GraphQLString, field, forceNullable, parentIsLocalized }),\n },\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 parentIsLocalized: parentIsLocalized || field.localized,\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]: {\n type: withNullableType({ type: GraphQLJSON, field, forceNullable, parentIsLocalized }),\n },\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 type: field.hasMany === true ? new GraphQLList(type) : type,\n field,\n forceNullable,\n parentIsLocalized,\n }),\n },\n }\n },\n point: (inputObjectTypeConfig: InputObjectTypeConfig, field: PointField) => ({\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType({\n type: new GraphQLList(GraphQLFloat),\n field,\n forceNullable,\n parentIsLocalized,\n }),\n },\n }),\n radio: (inputObjectTypeConfig: InputObjectTypeConfig, field: RadioField) => ({\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType({ type: GraphQLString, field, forceNullable, parentIsLocalized }),\n },\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]: {\n type: withNullableType({ type: GraphQLJSON, field, forceNullable, parentIsLocalized }),\n },\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({ type, field, forceNullable, parentIsLocalized })\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 parentIsLocalized: parentIsLocalized || tab.localized,\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 type: field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,\n field,\n forceNullable,\n parentIsLocalized,\n }),\n },\n }),\n textarea: (inputObjectTypeConfig: InputObjectTypeConfig, field: TextareaField) => ({\n ...inputObjectTypeConfig,\n [field.name]: {\n type: withNullableType({ type: GraphQLString, field, forceNullable, parentIsLocalized }),\n },\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","parentIsLocalized","parentName","fieldToSchemaMap","array","inputObjectTypeConfig","fullName","localized","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,6BAA6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;gBACF;YACF,OAAO;gBACLS,OAAOD,oBACLS,OAAOiC,EAAE,CAACC,aAAa,EACvBhC,cAAciC,WAAW,CAACR,WAAW,CAAC3B,MAAM;YAEhD;YAEA,OAAO;gBACL,GAAGO,qBAAqB;gBACxB,CAACV,MAAMC,IAAI,CAAC,EAAE;oBAAEN,MAAMK,MAAM0B,OAAO,GAAG,IAAIhD,YAAYiB,QAAQA;gBAAK;YACrE;QACF;IACF;IAEA,MAAMsD,YAAY7D,WAAWa;IAE7B,MAAMiD,eAAepD,OAAOmB,MAAM,CAAC,CAACP,uBAAuBV;QACzD,MAAMmD,cAAc3C,gBAAgB,CAACR,MAAML,IAAI,CAAC;QAEhD,IAAI,OAAOwD,gBAAgB,YAAY;YACrC,OAAOzC;QACT;QAEA,MAAM0C,SAASD,YAAYzC,uBAAuBV;QAClD,IAAIqD,OAAOC,IAAI,CAACF,QAAQG,MAAM,KAAK,GAAG;YACpC,OAAO7C;QACT;QAEA,OAAO;YACL,GAAGA,qBAAqB;YACxB,GAAGyC,YAAYzC,uBAAuBV,MAAM;QAC9C;IACF,GAAG,CAAC;IAEJ,IAAIqD,OAAOC,IAAI,CAACJ,cAAcK,MAAM,KAAK,GAAG;QAC1C,OAAO;IACT;IAEA,OAAO,IAAI/E,uBAAuB;QAChCyB,MAAM,CAAC,QAAQ,EAAEgD,UAAU,KAAK,CAAC;QACjCnD,QAAQoD;IACV;AACF"}
@@ -11,8 +11,9 @@ type Args = {
11
11
  forceNullable?: boolean;
12
12
  graphqlResult: GraphQLInfo;
13
13
  name: string;
14
+ parentIsLocalized?: boolean;
14
15
  parentName: string;
15
16
  };
16
- export declare function buildObjectType({ name, baseFields, config, fields, forceNullable, graphqlResult, parentName, }: Args): GraphQLObjectType;
17
+ export declare function buildObjectType({ name, baseFields, config, fields, forceNullable, graphqlResult, parentIsLocalized, parentName, }: Args): GraphQLObjectType;
17
18
  export {};
18
19
  //# sourceMappingURL=buildObjectType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildObjectType.d.ts","sourceRoot":"","sources":["../../src/schema/buildObjectType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,SAAS,CAAA;AAC9D,OAAO,KAAK,EAQV,KAAK,EACL,WAAW,EAWX,eAAe,EAMhB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAOL,iBAAiB,EAGlB,MAAM,SAAS,CAAA;AAchB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CAC7C,CAAA;AAED,KAAK,IAAI,GAAG;IACV,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,IAAI,EACJ,UAAe,EACf,MAAM,EACN,MAAM,EACN,aAAa,EACb,aAAa,EACb,UAAU,GACX,EAAE,IAAI,GAAG,iBAAiB,CAm0B1B"}
1
+ {"version":3,"file":"buildObjectType.d.ts","sourceRoot":"","sources":["../../src/schema/buildObjectType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,SAAS,CAAA;AAC9D,OAAO,KAAK,EAQV,KAAK,EACL,WAAW,EAWX,eAAe,EAMhB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAOL,iBAAiB,EAGlB,MAAM,SAAS,CAAA;AAchB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CAC7C,CAAA;AAED,KAAK,IAAI,GAAG;IACV,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,WAAW,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,IAAI,EACJ,UAAe,EACf,MAAM,EACN,MAAM,EACN,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,UAAU,GACX,EAAE,IAAI,GAAG,iBAAiB,CAs2B1B"}
@@ -8,7 +8,7 @@ import { formatName } from '../utilities/formatName.js';
8
8
  import { formatOptions } from '../utilities/formatOptions.js';
9
9
  import { isFieldNullable } from './isFieldNullable.js';
10
10
  import { withNullableType } from './withNullableType.js';
11
- export function buildObjectType({ name, baseFields = {}, config, fields, forceNullable, graphqlResult, parentName }) {
11
+ export function buildObjectType({ name, baseFields = {}, config, fields, forceNullable, graphqlResult, parentIsLocalized, parentName }) {
12
12
  const fieldToSchemaMap = {
13
13
  array: (objectTypeConfig, field)=>{
14
14
  const interfaceName = field?.interfaceName || combineParentName(parentName, toWords(field.name, true));
@@ -17,8 +17,13 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
17
17
  name: interfaceName,
18
18
  config,
19
19
  fields: field.fields,
20
- forceNullable: isFieldNullable(field, forceNullable),
20
+ forceNullable: isFieldNullable({
21
+ field,
22
+ forceNullable,
23
+ parentIsLocalized
24
+ }),
21
25
  graphqlResult,
26
+ parentIsLocalized: field.localized || parentIsLocalized,
22
27
  parentName: interfaceName
23
28
  });
24
29
  if (Object.keys(objectType.getFields()).length) {
@@ -32,13 +37,20 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
32
37
  return {
33
38
  ...objectTypeConfig,
34
39
  [field.name]: {
35
- type: withNullableType(field, arrayType)
40
+ type: withNullableType({
41
+ type: arrayType,
42
+ field,
43
+ parentIsLocalized
44
+ })
36
45
  }
37
46
  };
38
47
  },
39
48
  blocks: (objectTypeConfig, field)=>{
40
- const blockTypes = field.blocks.reduce((acc, block)=>{
41
- if (!graphqlResult.types.blockTypes[block.slug]) {
49
+ const blockTypes = (field.blockReferences ?? field.blocks).reduce((acc, _block)=>{
50
+ const blockSlug = typeof _block === 'string' ? _block : _block.slug;
51
+ if (!graphqlResult.types.blockTypes[blockSlug]) {
52
+ // TODO: iterate over blocks mapped to block slug in v4, or pass through payload.blocks
53
+ const block = typeof _block === 'string' ? config.blocks.find((b)=>b.slug === _block) : _block;
42
54
  const interfaceName = block?.interfaceName || block?.graphQL?.singularName || toWords(block.slug, true);
43
55
  const objectType = buildObjectType({
44
56
  name: interfaceName,
@@ -52,14 +64,15 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
52
64
  ],
53
65
  forceNullable,
54
66
  graphqlResult,
67
+ parentIsLocalized,
55
68
  parentName: interfaceName
56
69
  });
57
70
  if (Object.keys(objectType.getFields()).length) {
58
71
  graphqlResult.types.blockTypes[block.slug] = objectType;
59
72
  }
60
73
  }
61
- if (graphqlResult.types.blockTypes[block.slug]) {
62
- acc.push(graphqlResult.types.blockTypes[block.slug]);
74
+ if (graphqlResult.types.blockTypes[blockSlug]) {
75
+ acc.push(graphqlResult.types.blockTypes[blockSlug]);
63
76
  }
64
77
  return acc;
65
78
  }, []);
@@ -75,20 +88,34 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
75
88
  return {
76
89
  ...objectTypeConfig,
77
90
  [field.name]: {
78
- type: withNullableType(field, type)
91
+ type: withNullableType({
92
+ type,
93
+ field,
94
+ parentIsLocalized
95
+ })
79
96
  }
80
97
  };
81
98
  },
82
99
  checkbox: (objectTypeConfig, field)=>({
83
100
  ...objectTypeConfig,
84
101
  [field.name]: {
85
- type: withNullableType(field, GraphQLBoolean, forceNullable)
102
+ type: withNullableType({
103
+ type: GraphQLBoolean,
104
+ field,
105
+ forceNullable,
106
+ parentIsLocalized
107
+ })
86
108
  }
87
109
  }),
88
110
  code: (objectTypeConfig, field)=>({
89
111
  ...objectTypeConfig,
90
112
  [field.name]: {
91
- type: withNullableType(field, GraphQLString, forceNullable)
113
+ type: withNullableType({
114
+ type: GraphQLString,
115
+ field,
116
+ forceNullable,
117
+ parentIsLocalized
118
+ })
92
119
  }
93
120
  }),
94
121
  collapsible: (objectTypeConfig, field)=>field.fields.reduce((objectTypeConfigWithCollapsibleFields, subField)=>{
@@ -101,13 +128,23 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
101
128
  date: (objectTypeConfig, field)=>({
102
129
  ...objectTypeConfig,
103
130
  [field.name]: {
104
- type: withNullableType(field, DateTimeResolver, forceNullable)
131
+ type: withNullableType({
132
+ type: DateTimeResolver,
133
+ field,
134
+ forceNullable,
135
+ parentIsLocalized
136
+ })
105
137
  }
106
138
  }),
107
139
  email: (objectTypeConfig, field)=>({
108
140
  ...objectTypeConfig,
109
141
  [field.name]: {
110
- type: withNullableType(field, EmailAddressResolver, forceNullable)
142
+ type: withNullableType({
143
+ type: EmailAddressResolver,
144
+ field,
145
+ forceNullable,
146
+ parentIsLocalized
147
+ })
111
148
  }
112
149
  }),
113
150
  group: (objectTypeConfig, field)=>{
@@ -117,8 +154,13 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
117
154
  name: interfaceName,
118
155
  config,
119
156
  fields: field.fields,
120
- forceNullable: isFieldNullable(field, forceNullable),
157
+ forceNullable: isFieldNullable({
158
+ field,
159
+ forceNullable,
160
+ parentIsLocalized
161
+ }),
121
162
  graphqlResult,
163
+ parentIsLocalized: field.localized || parentIsLocalized,
122
164
  parentName: interfaceName
123
165
  });
124
166
  if (Object.keys(objectType.getFields()).length) {
@@ -199,7 +241,12 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
199
241
  json: (objectTypeConfig, field)=>({
200
242
  ...objectTypeConfig,
201
243
  [field.name]: {
202
- type: withNullableType(field, GraphQLJSON, forceNullable)
244
+ type: withNullableType({
245
+ type: GraphQLJSON,
246
+ field,
247
+ forceNullable,
248
+ parentIsLocalized
249
+ })
203
250
  }
204
251
  }),
205
252
  number: (objectTypeConfig, field)=>{
@@ -207,23 +254,38 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
207
254
  return {
208
255
  ...objectTypeConfig,
209
256
  [field.name]: {
210
- type: withNullableType(field, field?.hasMany === true ? new GraphQLList(type) : type, forceNullable)
257
+ type: withNullableType({
258
+ type: field?.hasMany === true ? new GraphQLList(type) : type,
259
+ field,
260
+ forceNullable,
261
+ parentIsLocalized
262
+ })
211
263
  }
212
264
  };
213
265
  },
214
266
  point: (objectTypeConfig, field)=>({
215
267
  ...objectTypeConfig,
216
268
  [field.name]: {
217
- type: withNullableType(field, new GraphQLList(new GraphQLNonNull(GraphQLFloat)), forceNullable)
269
+ type: withNullableType({
270
+ type: new GraphQLList(new GraphQLNonNull(GraphQLFloat)),
271
+ field,
272
+ forceNullable,
273
+ parentIsLocalized
274
+ })
218
275
  }
219
276
  }),
220
277
  radio: (objectTypeConfig, field)=>({
221
278
  ...objectTypeConfig,
222
279
  [field.name]: {
223
- type: withNullableType(field, new GraphQLEnumType({
224
- name: combineParentName(parentName, field.name),
225
- values: formatOptions(field)
226
- }), forceNullable)
280
+ type: withNullableType({
281
+ type: new GraphQLEnumType({
282
+ name: combineParentName(parentName, field.name),
283
+ values: formatOptions(field)
284
+ }),
285
+ field,
286
+ forceNullable,
287
+ parentIsLocalized
288
+ })
227
289
  }
228
290
  }),
229
291
  relationship: (objectTypeConfig, field)=>{
@@ -290,7 +352,12 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
290
352
  };
291
353
  }
292
354
  const relationship = {
293
- type: withNullableType(field, hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type, forceNullable),
355
+ type: withNullableType({
356
+ type: hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type,
357
+ field,
358
+ forceNullable,
359
+ parentIsLocalized
360
+ }),
294
361
  args: relationshipArgs,
295
362
  extensions: {
296
363
  complexity: typeof field?.graphQL?.complexity === 'number' ? field.graphQL.complexity : 10
@@ -393,7 +460,12 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
393
460
  richText: (objectTypeConfig, field)=>({
394
461
  ...objectTypeConfig,
395
462
  [field.name]: {
396
- type: withNullableType(field, GraphQLJSON, forceNullable),
463
+ type: withNullableType({
464
+ type: GraphQLJSON,
465
+ field,
466
+ forceNullable,
467
+ parentIsLocalized
468
+ }),
397
469
  args: {
398
470
  depth: {
399
471
  type: GraphQLInt
@@ -430,6 +502,7 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
430
502
  findMany: false,
431
503
  flattenLocales: false,
432
504
  overrideAccess: false,
505
+ parentIsLocalized,
433
506
  populationPromises,
434
507
  req: context.req,
435
508
  showHiddenFields: false,
@@ -456,7 +529,12 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
456
529
  values: formatOptions(field)
457
530
  });
458
531
  type = field.hasMany ? new GraphQLList(new GraphQLNonNull(type)) : type;
459
- type = withNullableType(field, type, forceNullable);
532
+ type = withNullableType({
533
+ type,
534
+ field,
535
+ forceNullable,
536
+ parentIsLocalized
537
+ });
460
538
  return {
461
539
  ...objectTypeConfig,
462
540
  [field.name]: {
@@ -474,6 +552,7 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
474
552
  fields: tab.fields,
475
553
  forceNullable,
476
554
  graphqlResult,
555
+ parentIsLocalized: tab.localized || parentIsLocalized,
477
556
  parentName: interfaceName
478
557
  });
479
558
  if (Object.keys(objectType.getFields()).length) {
@@ -510,13 +589,23 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
510
589
  text: (objectTypeConfig, field)=>({
511
590
  ...objectTypeConfig,
512
591
  [field.name]: {
513
- type: withNullableType(field, field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString, forceNullable)
592
+ type: withNullableType({
593
+ type: field.hasMany === true ? new GraphQLList(GraphQLString) : GraphQLString,
594
+ field,
595
+ forceNullable,
596
+ parentIsLocalized
597
+ })
514
598
  }
515
599
  }),
516
600
  textarea: (objectTypeConfig, field)=>({
517
601
  ...objectTypeConfig,
518
602
  [field.name]: {
519
- type: withNullableType(field, GraphQLString, forceNullable)
603
+ type: withNullableType({
604
+ type: GraphQLString,
605
+ field,
606
+ forceNullable,
607
+ parentIsLocalized
608
+ })
520
609
  }
521
610
  }),
522
611
  upload: (objectTypeConfig, field)=>{
@@ -581,7 +670,12 @@ export function buildObjectType({ name, baseFields = {}, config, fields, forceNu
581
670
  };
582
671
  }
583
672
  const relationship = {
584
- type: withNullableType(field, hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type, forceNullable),
673
+ type: withNullableType({
674
+ type: hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type,
675
+ field,
676
+ forceNullable,
677
+ parentIsLocalized
678
+ }),
585
679
  args: relationshipArgs,
586
680
  extensions: {
587
681
  complexity: typeof field?.graphQL?.complexity === 'number' ? field.graphQL.complexity : 10