11/* @flow */
22/* eslint-disable no-use-before-define */
33
4- import type { ObjectTypeComposer , ComposeFieldConfigArgumentMap } from 'graphql-compose' ;
4+ import {
5+ ObjectTypeComposer ,
6+ type ObjectTypeComposerArgumentConfigMapDefinition ,
7+ } from 'graphql-compose' ;
58import type { MongooseModel } from 'mongoose' ;
69import GraphQLMongoID from '../../types/mongoid' ;
710import { isObject , toMongoFilterDottedObject , getIndexedFieldNamesForGraphQL } from '../../utils' ;
@@ -35,8 +38,8 @@ export const filterHelperArgs = (
3538 typeComposer : ObjectTypeComposer < any , any > ,
3639 model : MongooseModel ,
3740 opts ? : FilterHelperArgsOpts
38- ) : ComposeFieldConfigArgumentMap < > => {
39- if ( ! typeComposer || typeComposer . constructor . name !== ' ObjectTypeComposer' ) {
41+ ) : ObjectTypeComposerArgumentConfigMapDefinition < > => {
42+ if ( ! ( typeComposer instanceof ObjectTypeComposer ) ) {
4043 throw new Error ( 'First arg for filterHelperArgs() should be instance of ObjectTypeComposer.' ) ;
4144 }
4245
@@ -69,7 +72,7 @@ export const filterHelperArgs = (
6972 const filterTypeName : string = opts . filterTypeName ;
7073 const itc = typeComposer . getInputTypeComposer ( ) . clone ( filterTypeName ) ;
7174
72- itc . makeOptional ( '_id' ) ;
75+ itc . makeFieldNullable ( '_id' ) ;
7376
7477 itc . addFields ( {
7578 _ids : [ GraphQLMongoID ] ,
@@ -78,7 +81,7 @@ export const filterHelperArgs = (
7881 itc . removeField ( removeFields ) ;
7982
8083 if ( opts . requiredFields ) {
81- itc . makeRequired ( opts . requiredFields ) ;
84+ itc . makeFieldNonNull ( opts . requiredFields ) ;
8285 }
8386
8487 if ( itc . getFieldNames ( ) . length === 0 ) {
@@ -89,7 +92,7 @@ export const filterHelperArgs = (
8992
9093 return {
9194 filter : {
92- type : opts . isRequired ? itc . getTypeNonNull ( ) : itc . getType ( ) ,
95+ type : opts . isRequired ? itc . getTypeNonNull ( ) : itc ,
9396 description : opts . onlyIndexed ? 'Filter only by indexed fields' : 'Filter by fields' ,
9497 } ,
9598 } ;
0 commit comments