@@ -74,36 +74,51 @@ CodeMirror.registerHelper(
74
74
( kind === 'Field' && step === 0 && typeInfo . fieldDef ) ||
75
75
( kind === 'AliasedField' && step === 2 && typeInfo . fieldDef )
76
76
) {
77
+ const header = document . createElement ( 'div' ) ;
78
+ header . className = 'CodeMirror-info-header' ;
79
+ renderField ( header , typeInfo , options ) ;
77
80
const into = document . createElement ( 'div' ) ;
78
- renderField ( into , typeInfo , options ) ;
81
+ into . appendChild ( header ) ;
79
82
renderDescription ( into , options , typeInfo . fieldDef as any ) ;
80
83
return into ;
81
84
} else if ( kind === 'Directive' && step === 1 && typeInfo . directiveDef ) {
85
+ const header = document . createElement ( 'div' ) ;
86
+ header . className = 'CodeMirror-info-header' ;
87
+ renderDirective ( header , typeInfo , options ) ;
82
88
const into = document . createElement ( 'div' ) ;
83
- renderDirective ( into , typeInfo , options ) ;
89
+ into . appendChild ( header ) ;
84
90
renderDescription ( into , options , typeInfo . directiveDef ) ;
85
91
return into ;
86
92
} else if ( kind === 'Argument' && step === 0 && typeInfo . argDef ) {
93
+ const header = document . createElement ( 'div' ) ;
94
+ header . className = 'CodeMirror-info-header' ;
95
+ renderArg ( header , typeInfo , options ) ;
87
96
const into = document . createElement ( 'div' ) ;
88
- renderArg ( into , typeInfo , options ) ;
97
+ into . appendChild ( header ) ;
89
98
renderDescription ( into , options , typeInfo . argDef ) ;
90
99
return into ;
91
100
} else if (
92
101
kind === 'EnumValue' &&
93
102
typeInfo . enumValue &&
94
103
typeInfo . enumValue . description
95
104
) {
105
+ const header = document . createElement ( 'div' ) ;
106
+ header . className = 'CodeMirror-info-header' ;
107
+ renderEnumValue ( header , typeInfo , options ) ;
96
108
const into = document . createElement ( 'div' ) ;
97
- renderEnumValue ( into , typeInfo , options ) ;
109
+ into . appendChild ( header ) ;
98
110
renderDescription ( into , options , typeInfo . enumValue ) ;
99
111
return into ;
100
112
} else if (
101
113
kind === 'NamedType' &&
102
114
typeInfo . type &&
103
115
( typeInfo . type as GraphQLObjectType ) . description
104
116
) {
117
+ const header = document . createElement ( 'div' ) ;
118
+ header . className = 'CodeMirror-info-header' ;
119
+ renderType ( header , typeInfo , options , typeInfo . type ) ;
105
120
const into = document . createElement ( 'div' ) ;
106
- renderType ( into , typeInfo , options , typeInfo . type ) ;
121
+ into . appendChild ( header ) ;
107
122
renderDescription ( into , options , typeInfo . type ) ;
108
123
return into ;
109
124
}
@@ -125,10 +140,6 @@ function renderQualifiedField(
125
140
options : GraphQLInfoOptions ,
126
141
) {
127
142
const fieldName = typeInfo . fieldDef ?. name || '' ;
128
- if ( fieldName . slice ( 0 , 2 ) !== '__' ) {
129
- renderType ( into , typeInfo , options , typeInfo . parentType ) ;
130
- text ( into , '.' ) ;
131
- }
132
143
text ( into , fieldName , 'field-name' , options , getFieldReference ( typeInfo ) ) ;
133
144
}
134
145
@@ -146,38 +157,47 @@ function renderArg(
146
157
typeInfo : TypeInfo ,
147
158
options : GraphQLInfoOptions ,
148
159
) {
149
- if ( typeInfo . directiveDef ) {
150
- renderDirective ( into , typeInfo , options ) ;
151
- } else if ( typeInfo . fieldDef ) {
152
- renderQualifiedField ( into , typeInfo , options ) ;
153
- }
154
-
155
160
const name = typeInfo . argDef ?. name || '' ;
156
- text ( into , '(' ) ;
157
161
text ( into , name , 'arg-name' , options , getArgumentReference ( typeInfo ) ) ;
158
162
renderTypeAnnotation ( into , typeInfo , options , typeInfo . inputType ) ;
159
- text ( into , ')' ) ;
160
163
}
161
164
162
- function renderTypeAnnotation (
165
+ function renderEnumValue (
163
166
into : HTMLElement ,
164
167
typeInfo : TypeInfo ,
165
168
options : GraphQLInfoOptions ,
166
- t : Maybe < GraphQLType > ,
167
169
) {
168
- text ( into , ': ' ) ;
169
- renderType ( into , typeInfo , options , t ) ;
170
+ const name = typeInfo . enumValue ?. name || '' ;
171
+ renderType ( into , typeInfo , options , typeInfo . inputType ) ;
172
+ text ( into , '.' ) ;
173
+ text ( into , name , 'enum-value' , options , getEnumValueReference ( typeInfo ) ) ;
170
174
}
171
175
172
- function renderEnumValue (
176
+ function renderTypeAnnotation (
173
177
into : HTMLElement ,
174
178
typeInfo : TypeInfo ,
175
179
options : GraphQLInfoOptions ,
180
+ t : Maybe < GraphQLType > ,
176
181
) {
177
- const name = typeInfo . enumValue ?. name || '' ;
178
- renderType ( into , typeInfo , options , typeInfo . inputType ) ;
179
- text ( into , '.' ) ;
180
- text ( into , name , 'enum-value' , options , getEnumValueReference ( typeInfo ) ) ;
182
+ const typeSpan = document . createElement ( 'span' ) ;
183
+ typeSpan . className = 'type-name-pill' ;
184
+ if ( t instanceof GraphQLNonNull ) {
185
+ renderType ( typeSpan , typeInfo , options , t . ofType ) ;
186
+ text ( typeSpan , '!' ) ;
187
+ } else if ( t instanceof GraphQLList ) {
188
+ text ( typeSpan , '[' ) ;
189
+ renderType ( typeSpan , typeInfo , options , t . ofType ) ;
190
+ text ( typeSpan , ']' ) ;
191
+ } else {
192
+ text (
193
+ typeSpan ,
194
+ t ?. name || '' ,
195
+ 'type-name' ,
196
+ options ,
197
+ getTypeReference ( typeInfo , t ) ,
198
+ ) ;
199
+ }
200
+ into . appendChild ( typeSpan ) ;
181
201
}
182
202
183
203
function renderType (
@@ -243,16 +263,21 @@ function renderDeprecation(
243
263
if ( reason ) {
244
264
const deprecationDiv = document . createElement ( 'div' ) ;
245
265
deprecationDiv . className = 'info-deprecation' ;
266
+ into . appendChild ( deprecationDiv ) ;
267
+
268
+ const label = document . createElement ( 'span' ) ;
269
+ label . className = 'info-deprecation-label' ;
270
+ label . appendChild ( document . createTextNode ( 'Deprecated' ) ) ;
271
+ deprecationDiv . appendChild ( label ) ;
272
+
273
+ const reasonDiv = document . createElement ( 'div' ) ;
274
+ reasonDiv . className = 'info-deprecation-reason' ;
246
275
if ( options . renderDescription ) {
247
- deprecationDiv . innerHTML = options . renderDescription ( reason ) ;
276
+ reasonDiv . innerHTML = options . renderDescription ( reason ) ;
248
277
} else {
249
- deprecationDiv . appendChild ( document . createTextNode ( reason ) ) ;
278
+ reasonDiv . appendChild ( document . createTextNode ( reason ) ) ;
250
279
}
251
- const label = document . createElement ( 'span' ) ;
252
- label . className = 'info-deprecation-label' ;
253
- label . appendChild ( document . createTextNode ( 'Deprecated: ' ) ) ;
254
- deprecationDiv . insertBefore ( label , deprecationDiv . firstChild ) ;
255
- into . appendChild ( deprecationDiv ) ;
280
+ deprecationDiv . appendChild ( reasonDiv ) ;
256
281
}
257
282
}
258
283
0 commit comments