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:
Ben Kraft
2021-08-27 18:12:35 -07:00
committed by GitHub
parent e6b1984d44
commit 46898ca52c
8 changed files with 73 additions and 15 deletions
@@ -50,7 +50,8 @@ func (v *InterfaceListFieldRootTopic) UnmarshalJSON(b []byte) error {
err = __unmarshalInterfaceListFieldRootTopicChildrenContent(
target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceListFieldRootTopic.Children: %w", err)
}
}
}
@@ -147,6 +148,9 @@ func __unmarshalInterfaceListFieldRootTopicChildrenContent(v *InterfaceListField
case "Topic":
*v = new(InterfaceListFieldRootTopicChildrenTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceListFieldRootTopicChildrenContent: "%v"`, tn.TypeName)
@@ -203,7 +207,8 @@ func (v *InterfaceListFieldWithPointerTopic) UnmarshalJSON(b []byte) error {
err = __unmarshalInterfaceListFieldWithPointerTopicChildrenContent(
target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceListFieldWithPointerTopic.Children: %w", err)
}
}
}
@@ -300,6 +305,9 @@ func __unmarshalInterfaceListFieldWithPointerTopicChildrenContent(v *InterfaceLi
case "Topic":
*v = new(InterfaceListFieldWithPointerTopicChildrenTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceListFieldWithPointerTopicChildrenContent: "%v"`, tn.TypeName)
@@ -110,6 +110,9 @@ func __unmarshalInterfaceListOfListOfListsFieldListOfListsOfListsOfContent(v *In
case "Topic":
*v = new(InterfaceListOfListOfListsFieldListOfListsOfListsOfContentTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceListOfListOfListsFieldListOfListsOfListsOfContent: "%v"`, tn.TypeName)
@@ -183,7 +186,8 @@ func (v *InterfaceListOfListOfListsFieldResponse) UnmarshalJSON(b []byte) error
err = __unmarshalInterfaceListOfListOfListsFieldListOfListsOfListsOfContent(
target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceListOfListOfListsFieldResponse.ListOfListsOfListsOfContent: %w", err)
}
}
}
@@ -211,7 +215,8 @@ func (v *InterfaceListOfListOfListsFieldResponse) UnmarshalJSON(b []byte) error
err = __unmarshalInterfaceListOfListOfListsFieldWithPointerContent(
*target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceListOfListOfListsFieldResponse.WithPointer: %w", err)
}
}
}
@@ -310,6 +315,9 @@ func __unmarshalInterfaceListOfListOfListsFieldWithPointerContent(v *InterfaceLi
case "Topic":
*v = new(InterfaceListOfListOfListsFieldWithPointerTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceListOfListOfListsFieldWithPointerContent: "%v"`, tn.TypeName)
@@ -48,7 +48,8 @@ func (v *InterfaceNestingRootTopic) UnmarshalJSON(b []byte) error {
err = __unmarshalInterfaceNestingRootTopicChildrenContent(
target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceNestingRootTopic.Children: %w", err)
}
}
}
@@ -151,6 +152,9 @@ func __unmarshalInterfaceNestingRootTopicChildrenContent(v *InterfaceNestingRoot
case "Topic":
*v = new(InterfaceNestingRootTopicChildrenTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceNestingRootTopicChildrenContent: "%v"`, tn.TypeName)
@@ -190,7 +194,8 @@ func (v *InterfaceNestingRootTopicChildrenParentTopic) UnmarshalJSON(b []byte) e
err = __unmarshalInterfaceNestingRootTopicChildrenParentTopicChildrenContent(
target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceNestingRootTopicChildrenParentTopic.Children: %w", err)
}
}
}
@@ -283,6 +288,9 @@ func __unmarshalInterfaceNestingRootTopicChildrenParentTopicChildrenContent(v *I
case "Topic":
*v = new(InterfaceNestingRootTopicChildrenParentTopicChildrenTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceNestingRootTopicChildrenParentTopicChildrenContent: "%v"`, tn.TypeName)
@@ -100,6 +100,9 @@ func __unmarshalInterfaceNoFragmentsQueryRandomItemContent(v *InterfaceNoFragmen
case "Topic":
*v = new(InterfaceNoFragmentsQueryRandomItemTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceNoFragmentsQueryRandomItemContent: "%v"`, tn.TypeName)
@@ -218,6 +221,9 @@ func __unmarshalInterfaceNoFragmentsQueryRandomItemWithTypeNameContent(v *Interf
case "Topic":
*v = new(InterfaceNoFragmentsQueryRandomItemWithTypeNameTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceNoFragmentsQueryRandomItemWithTypeNameContent: "%v"`, tn.TypeName)
@@ -271,7 +277,8 @@ func (v *InterfaceNoFragmentsQueryResponse) UnmarshalJSON(b []byte) error {
err = __unmarshalInterfaceNoFragmentsQueryRandomItemContent(
target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceNoFragmentsQueryResponse.RandomItem: %w", err)
}
}
{
@@ -280,7 +287,8 @@ func (v *InterfaceNoFragmentsQueryResponse) UnmarshalJSON(b []byte) error {
err = __unmarshalInterfaceNoFragmentsQueryRandomItemWithTypeNameContent(
target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceNoFragmentsQueryResponse.RandomItemWithTypeName: %w", err)
}
}
{
@@ -290,7 +298,8 @@ func (v *InterfaceNoFragmentsQueryResponse) UnmarshalJSON(b []byte) error {
err = __unmarshalInterfaceNoFragmentsQueryWithPointerContent(
*target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal InterfaceNoFragmentsQueryResponse.WithPointer: %w", err)
}
}
return nil
@@ -393,6 +402,9 @@ func __unmarshalInterfaceNoFragmentsQueryWithPointerContent(v *InterfaceNoFragme
case "Topic":
*v = new(InterfaceNoFragmentsQueryWithPointerTopic)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing Content.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for InterfaceNoFragmentsQueryWithPointerContent: "%v"`, tn.TypeName)
@@ -61,6 +61,9 @@ func __unmarshalUnionNoFragmentsQueryRandomLeafLeafContent(v *UnionNoFragmentsQu
case "Video":
*v = new(UnionNoFragmentsQueryRandomLeafVideo)
return json.Unmarshal(m, *v)
case "":
return fmt.Errorf(
"Response was missing LeafContent.__typename")
default:
return fmt.Errorf(
`Unexpected concrete type for UnionNoFragmentsQueryRandomLeafLeafContent: "%v"`, tn.TypeName)
@@ -98,7 +101,8 @@ func (v *UnionNoFragmentsQueryResponse) UnmarshalJSON(b []byte) error {
err = __unmarshalUnionNoFragmentsQueryRandomLeafLeafContent(
target, raw)
if err != nil {
return err
return fmt.Errorf(
"Unable to unmarshal UnionNoFragmentsQueryResponse.RandomLeaf: %w", err)
}
}
return nil