chore: merge master

This commit is contained in:
James
2022-09-11 18:07:05 -07:00
245 changed files with 4708 additions and 2347 deletions

View File

@@ -1,11 +1,12 @@
import { GraphQLEnumType } from 'graphql';
import { LocalizationConfig } from '../../config/types';
import formatName from '../utilities/formatName';
const buildFallbackLocaleInputType = (localization: LocalizationConfig): GraphQLEnumType => new GraphQLEnumType({
name: 'FallbackLocaleInputType',
values: [...localization.locales, 'none'].reduce((values, locale) => ({
...values,
[locale]: {
[formatName(locale)]: {
value: locale,
},
}), {}),

View File

@@ -1,14 +1,17 @@
import { GraphQLEnumType } from 'graphql';
import { GraphQLEnumType, GraphQLScalarType } from 'graphql';
import { LocalizationConfig } from '../../config/types';
import formatName from '../utilities/formatName';
const buildLocaleInputType = (localization: LocalizationConfig): GraphQLEnumType => new GraphQLEnumType({
name: 'LocaleInputType',
values: localization.locales.reduce((values, locale) => ({
...values,
[locale]: {
value: locale,
},
}), {}),
});
const buildLocaleInputType = (localization: LocalizationConfig): GraphQLEnumType | GraphQLScalarType => {
return new GraphQLEnumType({
name: 'LocaleInputType',
values: localization.locales.reduce((values, locale) => ({
...values,
[formatName(locale)]: {
value: locale,
},
}), {}),
});
};
export default buildLocaleInputType;

View File

@@ -9,6 +9,7 @@ import {
GraphQLFloat,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLString,
GraphQLType,
@@ -42,11 +43,12 @@ import formatName from '../utilities/formatName';
import combineParentName from '../utilities/combineParentName';
import withNullableType from './withNullableType';
import { toWords } from '../../utilities/formatLabels';
import createRichTextRelationshipPromise from '../../fields/richText/relationshipPromise';
import createRichTextRelationshipPromise from '../../fields/richText/richTextRelationshipPromise';
import formatOptions from '../utilities/formatOptions';
import { Payload } from '../..';
import buildWhereInputType from './buildWhereInputType';
import buildBlockType from './buildBlockType';
import isFieldNullable from './isFieldNullable';
type LocaleInputType = {
locale: {
@@ -108,7 +110,7 @@ function buildObjectType({
}),
point: (objectTypeConfig: ObjectTypeConfig, field: PointField) => ({
...objectTypeConfig,
[field.name]: { type: withNullableType(field, new GraphQLList(GraphQLFloat), forceNullable) },
[field.name]: { type: withNullableType(field, new GraphQLList(new GraphQLNonNull(GraphQLFloat)), forceNullable) },
}),
richText: (objectTypeConfig: ObjectTypeConfig, field: RichTextField) => ({
...objectTypeConfig,
@@ -229,7 +231,7 @@ function buildObjectType({
values: formatOptions(field),
});
type = field.hasMany ? new GraphQLList(type) : type;
type = field.hasMany ? new GraphQLList(new GraphQLNonNull(type)) : type;
type = withNullableType(field, type, forceNullable);
return {
@@ -307,7 +309,7 @@ function buildObjectType({
const relationship = {
args: relationshipArgs,
type: hasManyValues ? new GraphQLList(type) : type,
type: hasManyValues ? new GraphQLList(new GraphQLNonNull(type)) : type,
extensions: { complexity: 10 },
async resolve(parent, args, context) {
const value = parent[field.name];
@@ -412,18 +414,20 @@ function buildObjectType({
},
array: (objectTypeConfig: ObjectTypeConfig, field: ArrayField) => {
const fullName = combineParentName(parentName, field.label === false ? toWords(field.name, true) : field.label);
const type = buildObjectType({
payload,
name: fullName,
fields: field.fields,
parentName: fullName,
forceNullable,
forceNullable: isFieldNullable(field, forceNullable),
});
const arrayType = new GraphQLList(withNullableType(field, type, forceNullable));
const arrayType = new GraphQLList(new GraphQLNonNull(type));
return {
...objectTypeConfig,
[field.name]: { type: arrayType },
[field.name]: { type: withNullableType(field, arrayType) },
};
},
group: (objectTypeConfig: ObjectTypeConfig, field: GroupField) => {
@@ -433,7 +437,7 @@ function buildObjectType({
name: fullName,
parentName: fullName,
fields: field.fields,
forceNullable,
forceNullable: isFieldNullable(field, forceNullable),
});
return {
@@ -446,22 +450,22 @@ function buildObjectType({
buildBlockType({
payload,
block,
forceNullable,
forceNullable: isFieldNullable(field, forceNullable),
});
return payload.types.blockTypes[block.slug];
});
const fullName = combineParentName(parentName, field.label === false ? toWords(field.name, true) : field.label);
const type = new GraphQLList(new GraphQLUnionType({
const type = new GraphQLList(new GraphQLNonNull(new GraphQLUnionType({
name: fullName,
types: blockTypes,
resolveType: (data) => payload.types.blockTypes[data.blockType].name,
}));
})));
return {
...objectTypeConfig,
[field.name]: { type },
[field.name]: { type: withNullableType(field, type) },
};
},
row: (objectTypeConfig: ObjectTypeConfig, field: RowField) => field.fields.reduce((objectTypeConfigWithRowFields, subField) => {

View File

@@ -0,0 +1,9 @@
import { FieldAffectingData, fieldAffectsData } from '../../fields/config/types';
const isFieldNullable = (field: FieldAffectingData, force: boolean): boolean => {
const hasReadAccessControl = field.access && field.access.read;
const condition = field.admin && field.admin.condition;
return !(force && fieldAffectsData(field) && field.required && !field.localized && !condition && !hasReadAccessControl);
};
export default isFieldNullable;

View File

@@ -0,0 +1,18 @@
/* eslint-disable indent */
/* eslint-disable jest/prefer-strict-equal */
import formatName from './formatName';
describe('formatName', () => {
it.each`
char | expected
${'á'} | ${'a'}
${'è'} | ${'e'}
${'í'} | ${'i'}
${'ó'} | ${'o'}
${'ú'} | ${'u'}
${'ñ'} | ${'n'}
${'ü'} | ${'u'}
`('should convert accented character: $char', ({ char, expected }) => {
expect(formatName(char)).toEqual(expected);
});
});

View File

@@ -10,6 +10,10 @@ const formatName = (string: string): string => {
}
const formatted = sanitizedString
// Convert accented characters
.normalize('NFKD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/\./g, '_')
.replace(/-|\//g, '_')
.replace(/\+/g, '_')