From a5c8ea4e2e3e02dbbdb3429d9130eb109cec3258 Mon Sep 17 00:00:00 2001 From: Dan Ribbens Date: Fri, 11 Feb 2022 15:50:42 -0500 Subject: [PATCH] fix: version where input type --- src/collections/graphql/init.ts | 44 ++++++++++++----------- src/graphql/schema/buildWhereInputType.ts | 22 ++++++++++-- src/graphql/schema/withWhereAndOr.ts | 29 --------------- 3 files changed, 42 insertions(+), 53 deletions(-) delete mode 100644 src/graphql/schema/withWhereAndOr.ts diff --git a/src/collections/graphql/init.ts b/src/collections/graphql/init.ts index 6d07d816a6..2ae83d9393 100644 --- a/src/collections/graphql/init.ts +++ b/src/collections/graphql/init.ts @@ -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 }, diff --git a/src/graphql/schema/buildWhereInputType.ts b/src/graphql/schema/buildWhereInputType.ts index ace27b8e02..aecfc6571e 100644 --- a/src/graphql/schema/buildWhereInputType.ts +++ b/src/graphql/schema/buildWhereInputType.ts @@ -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; diff --git a/src/graphql/schema/withWhereAndOr.ts b/src/graphql/schema/withWhereAndOr.ts deleted file mode 100644 index b5925123b1..0000000000 --- a/src/graphql/schema/withWhereAndOr.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { - GraphQLInputFieldConfigMap, - GraphQLInputObjectType, - GraphQLList, - Thunk, -} from 'graphql'; - -const withWhereAndOr = (name: string, fieldTypes: Thunk): 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;