Skip to content

Commit 500a3ff

Browse files
authored
Merge pull request #123 from sogko/sogko/0.5.0
Port changes from `graphql-js` v0.5.0 (April 2016 spec)
2 parents a5cf5f2 + 34413d2 commit 500a3ff

39 files changed

+2698
-1343
lines changed

abstract_test.go

Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ func TestIsTypeOfUsedToResolveRuntimeTypeForInterface(t *testing.T) {
3636
})
3737

3838
// ie declare that Dog belongs to Pet interface
39-
_ = graphql.NewObject(graphql.ObjectConfig{
39+
dogType := graphql.NewObject(graphql.ObjectConfig{
4040
Name: "Dog",
4141
Interfaces: []*graphql.Interface{
4242
petType,
4343
},
44-
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
45-
_, ok := value.(*testDog)
44+
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
45+
_, ok := p.Value.(*testDog)
4646
return ok
4747
},
4848
Fields: graphql.Fields{
@@ -67,13 +67,13 @@ func TestIsTypeOfUsedToResolveRuntimeTypeForInterface(t *testing.T) {
6767
},
6868
})
6969
// ie declare that Cat belongs to Pet interface
70-
_ = graphql.NewObject(graphql.ObjectConfig{
70+
catType := graphql.NewObject(graphql.ObjectConfig{
7171
Name: "Cat",
7272
Interfaces: []*graphql.Interface{
7373
petType,
7474
},
75-
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
76-
_, ok := value.(*testCat)
75+
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
76+
_, ok := p.Value.(*testCat)
7777
return ok
7878
},
7979
Fields: graphql.Fields{
@@ -112,6 +112,7 @@ func TestIsTypeOfUsedToResolveRuntimeTypeForInterface(t *testing.T) {
112112
},
113113
},
114114
}),
115+
Types: []graphql.Type{catType, dogType},
115116
})
116117
if err != nil {
117118
t.Fatalf("Error in schema %v", err.Error())
@@ -161,8 +162,8 @@ func TestIsTypeOfUsedToResolveRuntimeTypeForUnion(t *testing.T) {
161162

162163
dogType := graphql.NewObject(graphql.ObjectConfig{
163164
Name: "Dog",
164-
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
165-
_, ok := value.(*testDog)
165+
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
166+
_, ok := p.Value.(*testDog)
166167
return ok
167168
},
168169
Fields: graphql.Fields{
@@ -176,8 +177,8 @@ func TestIsTypeOfUsedToResolveRuntimeTypeForUnion(t *testing.T) {
176177
})
177178
catType := graphql.NewObject(graphql.ObjectConfig{
178179
Name: "Cat",
179-
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
180-
_, ok := value.(*testCat)
180+
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
181+
_, ok := p.Value.(*testCat)
181182
return ok
182183
},
183184
Fields: graphql.Fields{
@@ -269,14 +270,14 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
269270
Type: graphql.String,
270271
},
271272
},
272-
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
273-
if _, ok := value.(*testCat); ok {
273+
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
274+
if _, ok := p.Value.(*testCat); ok {
274275
return catType
275276
}
276-
if _, ok := value.(*testDog); ok {
277+
if _, ok := p.Value.(*testDog); ok {
277278
return dogType
278279
}
279-
if _, ok := value.(*testHuman); ok {
280+
if _, ok := p.Value.(*testHuman); ok {
280281
return humanType
281282
}
282283
return nil
@@ -288,12 +289,6 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
288289
Fields: graphql.Fields{
289290
"name": &graphql.Field{
290291
Type: graphql.String,
291-
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
292-
if human, ok := p.Source.(*testHuman); ok {
293-
return human.Name, nil
294-
}
295-
return nil, nil
296-
},
297292
},
298293
},
299294
})
@@ -302,28 +297,12 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
302297
Interfaces: []*graphql.Interface{
303298
petType,
304299
},
305-
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
306-
_, ok := value.(*testDog)
307-
return ok
308-
},
309300
Fields: graphql.Fields{
310301
"name": &graphql.Field{
311302
Type: graphql.String,
312-
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
313-
if dog, ok := p.Source.(*testDog); ok {
314-
return dog.Name, nil
315-
}
316-
return nil, nil
317-
},
318303
},
319304
"woofs": &graphql.Field{
320305
Type: graphql.Boolean,
321-
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
322-
if dog, ok := p.Source.(*testDog); ok {
323-
return dog.Woofs, nil
324-
}
325-
return nil, nil
326-
},
327306
},
328307
},
329308
})
@@ -332,28 +311,12 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
332311
Interfaces: []*graphql.Interface{
333312
petType,
334313
},
335-
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
336-
_, ok := value.(*testCat)
337-
return ok
338-
},
339314
Fields: graphql.Fields{
340315
"name": &graphql.Field{
341316
Type: graphql.String,
342-
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
343-
if cat, ok := p.Source.(*testCat); ok {
344-
return cat.Name, nil
345-
}
346-
return nil, nil
347-
},
348317
},
349318
"meows": &graphql.Field{
350319
Type: graphql.Boolean,
351-
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
352-
if cat, ok := p.Source.(*testCat); ok {
353-
return cat.Meows, nil
354-
}
355-
return nil, nil
356-
},
357320
},
358321
},
359322
})
@@ -373,6 +336,7 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
373336
},
374337
},
375338
}),
339+
Types: []graphql.Type{catType, dogType},
376340
})
377341
if err != nil {
378342
t.Fatalf("Error in schema %v", err.Error())
@@ -405,7 +369,7 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
405369
},
406370
},
407371
Errors: []gqlerrors.FormattedError{
408-
gqlerrors.FormattedError{
372+
{
409373
Message: `Runtime Object type "Human" is not a possible type for "Pet".`,
410374
Locations: []location.SourceLocation{},
411375
},
@@ -461,14 +425,14 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
461425
Types: []*graphql.Object{
462426
dogType, catType,
463427
},
464-
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
465-
if _, ok := value.(*testCat); ok {
428+
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
429+
if _, ok := p.Value.(*testCat); ok {
466430
return catType
467431
}
468-
if _, ok := value.(*testDog); ok {
432+
if _, ok := p.Value.(*testDog); ok {
469433
return dogType
470434
}
471-
if _, ok := value.(*testHuman); ok {
435+
if _, ok := p.Value.(*testHuman); ok {
472436
return humanType
473437
}
474438
return nil
@@ -523,7 +487,7 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
523487
},
524488
},
525489
Errors: []gqlerrors.FormattedError{
526-
gqlerrors.FormattedError{
490+
{
527491
Message: `Runtime Object type "Human" is not a possible type for "Pet".`,
528492
Locations: []location.SourceLocation{},
529493
},

0 commit comments

Comments
 (0)