fix: version where input type

This commit is contained in:
Dan Ribbens
2022-02-11 15:50:42 -05:00
parent fa8a6b769b
commit a5c8ea4e2e
3 changed files with 42 additions and 53 deletions

View File

@@ -197,27 +197,29 @@ function registerCollections(): void {
this.Query.fields[`versions${pluralLabel}`] = {
type: buildPaginatedListType(`versions${formatName(pluralLabel)}`, collection.graphQL.versionType),
args: {
where: this.buildWhereInputType(
`versions${singularLabel}`,
[
...buildVersionCollectionFields(collection),
{
name: 'id',
type: 'text',
},
{
name: 'createdAt',
label: 'Created At',
type: 'date',
},
{
name: 'updatedAt',
label: 'Updated At',
type: 'date',
},
],
`versions${singularLabel}`,
),
where: {
type: this.buildWhereInputType(
`versions${singularLabel}`,
[
...buildVersionCollectionFields(collection.config),
{
name: 'id',
type: 'text',
},
{
name: 'createdAt',
label: 'Created At',
type: 'date',
},
{
name: 'updatedAt',
label: 'Updated At',
type: 'date',
},
],
`versions${singularLabel}`,
),
},
...(this.config.localization ? {
locale: { type: this.types.localeInputType },
fallbackLocale: { type: this.types.fallbackLocaleInputType },

View File

@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable no-use-before-define */
import {
GraphQLInputObjectType,
GraphQLInputObjectType, GraphQLList,
} from 'graphql';
import { GraphQLJSON } from 'graphql-type-json';
@@ -15,7 +15,6 @@ import {
import formatName from '../utilities/formatName';
import withOperators from './withOperators';
import operators from './operators';
import withWhereAndOr from './withWhereAndOr';
import fieldToSchemaMap from './fieldToSchemaMap';
// buildWhereInputType is similar to buildObjectType and operates
@@ -67,7 +66,24 @@ const buildWhereInputType = (name: string, fields: Field[], parentName: string):
const fieldName = formatName(name);
return withWhereAndOr(fieldName, fieldTypes);
return new GraphQLInputObjectType({
name: `${fieldName}_where`,
fields: {
...fieldTypes,
OR: {
type: new GraphQLList(new GraphQLInputObjectType({
name: `${fieldName}_where_or`,
fields: fieldTypes,
})),
},
AND: {
type: new GraphQLList(new GraphQLInputObjectType({
name: `${fieldName}_where_and`,
fields: fieldTypes,
})),
},
},
});
};
export default buildWhereInputType;

View File

@@ -1,29 +0,0 @@
import {
GraphQLInputFieldConfigMap,
GraphQLInputObjectType,
GraphQLList,
Thunk,
} from 'graphql';
const withWhereAndOr = (name: string, fieldTypes: Thunk<GraphQLInputFieldConfigMap>): GraphQLInputObjectType => {
return new GraphQLInputObjectType({
name: `${name}_where`,
fields: {
...fieldTypes,
OR: {
type: new GraphQLList(new GraphQLInputObjectType({
name: `${name}_where_or`,
fields: fieldTypes,
})),
},
AND: {
type: new GraphQLList(new GraphQLInputObjectType({
name: `${name}_where_and`,
fields: fieldTypes,
})),
},
},
});
};
export default withWhereAndOr;