Skip to content

Commit 623f886

Browse files
authored
Merge pull request #651 from dariuszkuc/fix_list_name
fix String/Name methods on the List type
2 parents d264c4c + c18e0b6 commit 623f886

File tree

1 file changed

+68
-72
lines changed

1 file changed

+68
-72
lines changed

definition.go

Lines changed: 68 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,12 @@ func GetNamed(ttype Type) Named {
193193
//
194194
// Example:
195195
//
196-
// var OddType = new Scalar({
197-
// name: 'Odd',
198-
// serialize(value) {
199-
// return value % 2 === 1 ? value : null;
200-
// }
201-
// });
202-
//
196+
// var OddType = new Scalar({
197+
// name: 'Odd',
198+
// serialize(value) {
199+
// return value % 2 === 1 ? value : null;
200+
// }
201+
// });
203202
type Scalar struct {
204203
PrivateName string `json:"name"`
205204
PrivateDescription string `json:"description"`
@@ -306,33 +305,33 @@ func (st *Scalar) Error() error {
306305
// have a name, but most importantly describe their fields.
307306
// Example:
308307
//
309-
// var AddressType = new Object({
310-
// name: 'Address',
311-
// fields: {
312-
// street: { type: String },
313-
// number: { type: Int },
314-
// formatted: {
315-
// type: String,
316-
// resolve(obj) {
317-
// return obj.number + ' ' + obj.street
318-
// }
319-
// }
320-
// }
321-
// });
308+
// var AddressType = new Object({
309+
// name: 'Address',
310+
// fields: {
311+
// street: { type: String },
312+
// number: { type: Int },
313+
// formatted: {
314+
// type: String,
315+
// resolve(obj) {
316+
// return obj.number + ' ' + obj.street
317+
// }
318+
// }
319+
// }
320+
// });
322321
//
323322
// When two types need to refer to each other, or a type needs to refer to
324323
// itself in a field, you can use a function expression (aka a closure or a
325324
// thunk) to supply the fields lazily.
326325
//
327326
// Example:
328327
//
329-
// var PersonType = new Object({
330-
// name: 'Person',
331-
// fields: () => ({
332-
// name: { type: String },
333-
// bestFriend: { type: PersonType },
334-
// })
335-
// });
328+
// var PersonType = new Object({
329+
// name: 'Person',
330+
// fields: () => ({
331+
// name: { type: String },
332+
// bestFriend: { type: PersonType },
333+
// })
334+
// });
336335
//
337336
// /
338337
type Object struct {
@@ -668,14 +667,12 @@ func (st *Argument) Error() error {
668667
//
669668
// Example:
670669
//
671-
// var EntityType = new Interface({
672-
// name: 'Entity',
673-
// fields: {
674-
// name: { type: String }
675-
// }
676-
// });
677-
//
678-
//
670+
// var EntityType = new Interface({
671+
// name: 'Entity',
672+
// fields: {
673+
// name: { type: String }
674+
// }
675+
// });
679676
type Interface struct {
680677
PrivateName string `json:"name"`
681678
PrivateDescription string `json:"description"`
@@ -779,18 +776,18 @@ func (it *Interface) Error() error {
779776
//
780777
// Example:
781778
//
782-
// var PetType = new Union({
783-
// name: 'Pet',
784-
// types: [ DogType, CatType ],
785-
// resolveType(value) {
786-
// if (value instanceof Dog) {
787-
// return DogType;
788-
// }
789-
// if (value instanceof Cat) {
790-
// return CatType;
791-
// }
792-
// }
793-
// });
779+
// var PetType = new Union({
780+
// name: 'Pet',
781+
// types: [ DogType, CatType ],
782+
// resolveType(value) {
783+
// if (value instanceof Dog) {
784+
// return DogType;
785+
// }
786+
// if (value instanceof Cat) {
787+
// return CatType;
788+
// }
789+
// }
790+
// });
794791
type Union struct {
795792
PrivateName string `json:"name"`
796793
PrivateDescription string `json:"description"`
@@ -1085,18 +1082,18 @@ func (gt *Enum) getNameLookup() map[string]*EnumValueDefinition {
10851082
// An input object defines a structured collection of fields which may be
10861083
// supplied to a field argument.
10871084
//
1088-
// Using `NonNull` will ensure that a value must be provided by the query
1085+
// # Using `NonNull` will ensure that a value must be provided by the query
10891086
//
10901087
// Example:
10911088
//
1092-
// var GeoPoint = new InputObject({
1093-
// name: 'GeoPoint',
1094-
// fields: {
1095-
// lat: { type: new NonNull(Float) },
1096-
// lon: { type: new NonNull(Float) },
1097-
// alt: { type: Float, defaultValue: 0 },
1098-
// }
1099-
// });
1089+
// var GeoPoint = new InputObject({
1090+
// name: 'GeoPoint',
1091+
// fields: {
1092+
// lat: { type: new NonNull(Float) },
1093+
// lon: { type: new NonNull(Float) },
1094+
// alt: { type: Float, defaultValue: 0 },
1095+
// }
1096+
// });
11001097
type InputObject struct {
11011098
PrivateName string `json:"name"`
11021099
PrivateDescription string `json:"description"`
@@ -1235,14 +1232,13 @@ func (gt *InputObject) Error() error {
12351232
//
12361233
// Example:
12371234
//
1238-
// var PersonType = new Object({
1239-
// name: 'Person',
1240-
// fields: () => ({
1241-
// parents: { type: new List(Person) },
1242-
// children: { type: new List(Person) },
1243-
// })
1244-
// })
1245-
//
1235+
// var PersonType = new Object({
1236+
// name: 'Person',
1237+
// fields: () => ({
1238+
// parents: { type: new List(Person) },
1239+
// children: { type: new List(Person) },
1240+
// })
1241+
// })
12461242
type List struct {
12471243
OfType Type `json:"ofType"`
12481244

@@ -1261,14 +1257,14 @@ func NewList(ofType Type) *List {
12611257
return gl
12621258
}
12631259
func (gl *List) Name() string {
1264-
return fmt.Sprintf("%v", gl.OfType)
1260+
return fmt.Sprintf("[%v]", gl.OfType)
12651261
}
12661262
func (gl *List) Description() string {
12671263
return ""
12681264
}
12691265
func (gl *List) String() string {
12701266
if gl.OfType != nil {
1271-
return fmt.Sprintf("[%v]", gl.OfType)
1267+
return gl.Name()
12721268
}
12731269
return ""
12741270
}
@@ -1286,12 +1282,12 @@ func (gl *List) Error() error {
12861282
//
12871283
// Example:
12881284
//
1289-
// var RowType = new Object({
1290-
// name: 'Row',
1291-
// fields: () => ({
1292-
// id: { type: new NonNull(String) },
1293-
// })
1294-
// })
1285+
// var RowType = new Object({
1286+
// name: 'Row',
1287+
// fields: () => ({
1288+
// id: { type: new NonNull(String) },
1289+
// })
1290+
// })
12951291
//
12961292
// Note: the enforcement of non-nullability occurs within the executor.
12971293
type NonNull struct {

0 commit comments

Comments
 (0)