1
1
import chalk from 'chalk'
2
2
import * as os from 'os'
3
3
import { graphQLToTypecriptType , GraphQLTypeObject } from './source-helper'
4
- import { ValidatedDefinition } from './validation'
4
+ import { maybeReplaceDefaultName , ValidatedDefinition } from './validation'
5
5
6
6
export function outputDefinitionFilesNotFound (
7
7
validatedDefinitions : ValidatedDefinition [ ] ,
@@ -89,14 +89,14 @@ ${chalk.bold(
89
89
${ chalk . bold ( 'Step 2' ) } : Re-run ${ chalk . bold ( '`graphqlgen`' ) } `)
90
90
}
91
91
92
- export function outputMissingModels ( missingModels : GraphQLTypeObject [ ] ) {
92
+ export function outputMissingModels ( missingModels : GraphQLTypeObject [ ] , defaultName : string | null ) {
93
93
console . log ( `❌ Some types from your application schema have model definitions that are not defined yet
94
94
95
95
${ chalk . bold (
96
96
'Step 1' ,
97
97
) } : Copy/paste the model definitions below to your application
98
98
99
- ${ missingModels . map ( renderModelFromType ) . join ( os . EOL ) }
99
+ ${ missingModels . map ( m => renderModelFromType ( m , defaultName ) ) . join ( os . EOL ) }
100
100
101
101
102
102
${ chalk . bold ( 'Step 2' ) } : Reference the model definitions in your ${ chalk . bold (
@@ -110,9 +110,10 @@ models:
110
110
${ chalk . bold ( 'Step 3' ) } : Re-run ${ chalk . bold ( '`graphqlgen`' ) } `)
111
111
}
112
112
113
- function renderModelFromType ( type : GraphQLTypeObject ) : string {
113
+ function renderModelFromType ( type : GraphQLTypeObject , defaultName : string | null ) : string {
114
+ const name = maybeReplaceDefaultName ( type . name , defaultName )
114
115
return `\
115
- export interface ${ chalk . bold ( type . name ) } {
116
+ export interface ${ chalk . bold ( name ) } {
116
117
${ type . fields
117
118
. map ( field => ` ${ field . name } : ${ graphQLToTypecriptType ( field . type ) } ` )
118
119
. join ( os . EOL ) }
0 commit comments