Return clearer errors when __typename is missing (#68)
## Summary: In practice, at Khan at least, this is easy to mess up when writing mocks, because you write the mock by looking at the query, and the query doesn't say it's asking for `__typename` (because genqlient automatically adds that). A sufficiently-smart mocking library might be able to fix that, or detect it at least, but in any case, we can give a clearer error. I also removed an unrelated TODO that was done. Issue: https://khanacademy.slack.com/archives/C01120CNCS0/p1630019788014000 ## Test plan: make check Author: benjaminjkraft Reviewers: dnerdy, aberkan, csilvers, MiguelCastillo Required Reviewers: Approved by: dnerdy Checks: ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Test (1.13), ✅ Lint, ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Test (1.13), ✅ Lint Pull request URL: https://github.com/Khan/genqlient/pull/68
This commit is contained in:
@@ -327,6 +327,9 @@ func __unmarshalqueryWithInterfaceListFieldBeingsBeing(v *queryWithInterfaceList
|
||||
case "Animal":
|
||||
*v = new(queryWithInterfaceListFieldBeingsAnimal)
|
||||
return json.Unmarshal(m, *v)
|
||||
case "":
|
||||
return fmt.Errorf(
|
||||
"Response was missing Being.__typename")
|
||||
default:
|
||||
return fmt.Errorf(
|
||||
`Unexpected concrete type for queryWithInterfaceListFieldBeingsBeing: "%v"`, tn.TypeName)
|
||||
@@ -371,7 +374,8 @@ func (v *queryWithInterfaceListFieldResponse) UnmarshalJSON(b []byte) error {
|
||||
err = __unmarshalqueryWithInterfaceListFieldBeingsBeing(
|
||||
target, raw)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf(
|
||||
"Unable to unmarshal queryWithInterfaceListFieldResponse.Beings: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,6 +452,9 @@ func __unmarshalqueryWithInterfaceListPointerFieldBeingsBeing(v *queryWithInterf
|
||||
case "Animal":
|
||||
*v = new(queryWithInterfaceListPointerFieldBeingsAnimal)
|
||||
return json.Unmarshal(m, *v)
|
||||
case "":
|
||||
return fmt.Errorf(
|
||||
"Response was missing Being.__typename")
|
||||
default:
|
||||
return fmt.Errorf(
|
||||
`Unexpected concrete type for queryWithInterfaceListPointerFieldBeingsBeing: "%v"`, tn.TypeName)
|
||||
@@ -493,7 +500,8 @@ func (v *queryWithInterfaceListPointerFieldResponse) UnmarshalJSON(b []byte) err
|
||||
err = __unmarshalqueryWithInterfaceListPointerFieldBeingsBeing(
|
||||
*target, raw)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf(
|
||||
"Unable to unmarshal queryWithInterfaceListPointerFieldResponse.Beings: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -563,6 +571,9 @@ func __unmarshalqueryWithInterfaceNoFragmentsBeing(v *queryWithInterfaceNoFragme
|
||||
case "Animal":
|
||||
*v = new(queryWithInterfaceNoFragmentsBeingAnimal)
|
||||
return json.Unmarshal(m, *v)
|
||||
case "":
|
||||
return fmt.Errorf(
|
||||
"Response was missing Being.__typename")
|
||||
default:
|
||||
return fmt.Errorf(
|
||||
`Unexpected concrete type for queryWithInterfaceNoFragmentsBeing: "%v"`, tn.TypeName)
|
||||
@@ -616,7 +627,8 @@ func (v *queryWithInterfaceNoFragmentsResponse) UnmarshalJSON(b []byte) error {
|
||||
err = __unmarshalqueryWithInterfaceNoFragmentsBeing(
|
||||
target, raw)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf(
|
||||
"Unable to unmarshal queryWithInterfaceNoFragmentsResponse.Being: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user