fix: format graphql localization input type (#932)

* fix: format locales for graphql

* fix: locale missing from graphql mutation args
This commit is contained in:
Dan Ribbens
2022-08-15 11:42:29 -04:00
committed by GitHub
parent 78630cafa2
commit 1c7445dc7f
5 changed files with 73 additions and 11 deletions

View File

@@ -177,6 +177,9 @@ function initCollectionsGraphQL(payload: Payload): void {
args: {
data: { type: collection.graphQL.mutationInputType },
draft: { type: GraphQLBoolean },
...(payload.config.localization ? {
locale: { type: payload.types.localeInputType },
} : {}),
},
resolve: createResolver(collection),
};
@@ -188,6 +191,9 @@ function initCollectionsGraphQL(payload: Payload): void {
data: { type: collection.graphQL.updateMutationInputType },
draft: { type: GraphQLBoolean },
autosave: { type: GraphQLBoolean },
...(payload.config.localization ? {
locale: { type: payload.types.localeInputType },
} : {}),
},
resolve: updateResolver(collection),
};

View File

@@ -62,6 +62,9 @@ function initGlobalsGraphQL(payload: Payload): void {
args: {
data: { type: global.graphQL.mutationInputType },
draft: { type: GraphQLBoolean },
...(payload.config.localization ? {
locale: { type: payload.types.localeInputType },
} : {}),
},
resolve: updateResolver(global),
};

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;