File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,13 @@ import { expect } from 'chai';
44import { UserModel } from '../__mocks__/userModel.js' ;
55import { composeWithMongoose } from '../composeWithMongoose' ;
66import { TypeComposer , InputTypeComposer } from 'graphql-compose' ;
7+ import typeStorage from '../typeStorage' ;
78
9+ describe ( 'composeWithMongoose ->' , ( ) => {
10+ beforeEach ( ( ) => {
11+ typeStorage . clear ( ) ;
12+ } ) ;
813
9- describe ( 'modelConverter' , ( ) => {
1014 describe ( 'mongooseModelToTypeComposer()' , ( ) => {
1115 describe ( 'basics' , ( ) => {
1216 it ( 'should return TypeComposer' , ( ) => {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {
2020 GraphQLObjectType ,
2121} from 'graphql' ;
2222import GraphQLMongoID from './types/mongoid' ;
23+ import typeStorage from './typeStorage' ;
2324
2425import type {
2526 MongooseModelT ,
@@ -131,12 +132,15 @@ export function convertModelToGraphQL(
131132 }
132133
133134 const typeComposer = new TypeComposer (
134- new GraphQLObjectType ( {
135- name : typeName ,
136- interfaces : [ ] ,
137- description : undefined ,
138- fields : { } ,
139- } )
135+ typeStorage . getOrSet (
136+ typeName ,
137+ new GraphQLObjectType ( {
138+ name : typeName ,
139+ interfaces : [ ] ,
140+ description : undefined ,
141+ fields : { } ,
142+ } )
143+ )
140144 ) ;
141145
142146 const mongooseFields = getFieldsFromModel ( model , typeName ) ;
@@ -296,11 +300,15 @@ export function enumToGraphQL(
296300 return result ;
297301 } , { } ) ;
298302
299- return new GraphQLEnumType ( {
300- name : `Enum${ prefix } ${ capitalize ( _getFieldName ( field ) ) } ` ,
301- description : _getFieldDescription ( field ) ,
302- values : graphQLEnumValues ,
303- } ) ;
303+ const typeName = `Enum${ prefix } ${ capitalize ( _getFieldName ( field ) ) } ` ;
304+ return typeStorage . getOrSet (
305+ typeName ,
306+ new GraphQLEnumType ( {
307+ name : typeName ,
308+ description : _getFieldDescription ( field ) ,
309+ values : graphQLEnumValues ,
310+ } )
311+ ) ;
304312}
305313
306314
You can’t perform that action at this time.
0 commit comments