Clarify object type documentation

Craig pointed out this is a bit confusing when you don't have all the
fields.  Now we say so, but still include the type's description in case
it's useful.

Fixes #37.
This commit is contained in:
Ben Kraft
2021-04-23 18:13:32 -07:00
parent f1914cd9ef
commit d449acdda3
22 changed files with 129 additions and 1 deletions
+6
View File
@@ -15,6 +15,9 @@ type getUserResponse struct {
User getUserUser `json:"user"`
}
// getUserUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A user is an individual's account on GitHub that owns repositories and can make new content.
type getUserUser struct {
// The user's public profile name.
@@ -29,6 +32,9 @@ type getViewerResponse struct {
Viewer getViewerViewerUser `json:"viewer"`
}
// getViewerViewerUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A user is an individual's account on GitHub that owns repositories and can make new content.
type getViewerViewerUser struct {
// The user's public profile name.
+3
View File
@@ -13,6 +13,9 @@ type InputEnumQueryResponse struct {
UsersWithRole []InputEnumQueryUsersWithRoleUser `json:"usersWithRole"`
}
// InputEnumQueryUsersWithRoleUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type InputEnumQueryUsersWithRoleUser struct {
// id is the user's ID.
+3
View File
@@ -16,6 +16,9 @@ type InputObjectQueryResponse struct {
User InputObjectQueryUser `json:"user"`
}
// InputObjectQueryUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type InputObjectQueryUser struct {
// id is the user's ID.
+28
View File
@@ -14,6 +14,7 @@ type InterfaceNestingResponse struct {
Root InterfaceNestingRootTopic `json:"root"`
}
// InterfaceNestingRootTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNestingRootTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"`
@@ -67,6 +68,7 @@ func (v *InterfaceNestingRootTopic) UnmarshalJSON(b []byte) error {
return nil
}
// InterfaceNestingRootTopicChildrenArticle includes the requested fields of the GraphQL type Article.
type InterfaceNestingRootTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -76,6 +78,7 @@ type InterfaceNestingRootTopicChildrenArticle struct {
func (v InterfaceNestingRootTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenArticleParentTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNestingRootTopicChildrenArticleParentTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"`
@@ -129,6 +132,7 @@ func (v *InterfaceNestingRootTopicChildrenArticleParentTopic) UnmarshalJSON(b []
return nil
}
// InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle includes the requested fields of the GraphQL type Article.
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -137,11 +141,15 @@ type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle struct {
func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent includes the requested fields of the GraphQL type Content.
// The GraphQL type's documentation follows.
//
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent()
}
// InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -150,6 +158,7 @@ type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic struct {
func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo includes the requested fields of the GraphQL type Video.
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -158,11 +167,15 @@ type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo struct {
func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenContent includes the requested fields of the GraphQL type Content.
// The GraphQL type's documentation follows.
//
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNestingRootTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent()
}
// InterfaceNestingRootTopicChildrenTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNestingRootTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -172,6 +185,7 @@ type InterfaceNestingRootTopicChildrenTopic struct {
func (v InterfaceNestingRootTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenTopicParentTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNestingRootTopicChildrenTopicParentTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"`
@@ -225,6 +239,7 @@ func (v *InterfaceNestingRootTopicChildrenTopicParentTopic) UnmarshalJSON(b []by
return nil
}
// InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle includes the requested fields of the GraphQL type Article.
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -233,11 +248,15 @@ type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle struct {
func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent includes the requested fields of the GraphQL type Content.
// The GraphQL type's documentation follows.
//
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent()
}
// InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -246,6 +265,7 @@ type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic struct {
func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo includes the requested fields of the GraphQL type Video.
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -254,6 +274,7 @@ type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo struct {
func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenVideo includes the requested fields of the GraphQL type Video.
type InterfaceNestingRootTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -263,6 +284,7 @@ type InterfaceNestingRootTopicChildrenVideo struct {
func (v InterfaceNestingRootTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenVideoParentTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNestingRootTopicChildrenVideoParentTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"`
@@ -316,6 +338,7 @@ func (v *InterfaceNestingRootTopicChildrenVideoParentTopic) UnmarshalJSON(b []by
return nil
}
// InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle includes the requested fields of the GraphQL type Article.
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -324,11 +347,15 @@ type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle struct {
func (v InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent includes the requested fields of the GraphQL type Content.
// The GraphQL type's documentation follows.
//
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent()
}
// InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -337,6 +364,7 @@ type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic struct {
func (v InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent() {
}
// InterfaceNestingRootTopicChildrenVideoParentTopicChildrenVideo includes the requested fields of the GraphQL type Video.
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -14,6 +14,7 @@ type InterfaceNoFragmentsQueryResponse struct {
Root InterfaceNoFragmentsQueryRootTopic `json:"root"`
}
// InterfaceNoFragmentsQueryRootTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNoFragmentsQueryRootTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"`
@@ -68,6 +69,7 @@ func (v *InterfaceNoFragmentsQueryRootTopic) UnmarshalJSON(b []byte) error {
return nil
}
// InterfaceNoFragmentsQueryRootTopicChildrenArticle includes the requested fields of the GraphQL type Article.
type InterfaceNoFragmentsQueryRootTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -77,11 +79,15 @@ type InterfaceNoFragmentsQueryRootTopicChildrenArticle struct {
func (v InterfaceNoFragmentsQueryRootTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent() {
}
// InterfaceNoFragmentsQueryRootTopicChildrenContent includes the requested fields of the GraphQL type Content.
// The GraphQL type's documentation follows.
//
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNoFragmentsQueryRootTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent()
}
// InterfaceNoFragmentsQueryRootTopicChildrenTopic includes the requested fields of the GraphQL type Topic.
type InterfaceNoFragmentsQueryRootTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
@@ -91,6 +97,7 @@ type InterfaceNoFragmentsQueryRootTopicChildrenTopic struct {
func (v InterfaceNoFragmentsQueryRootTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent() {
}
// InterfaceNoFragmentsQueryRootTopicChildrenVideo includes the requested fields of the GraphQL type Video.
type InterfaceNoFragmentsQueryRootTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
+3
View File
@@ -16,6 +16,9 @@ type ListInputQueryResponse struct {
User ListInputQueryUser `json:"user"`
}
// ListInputQueryUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type ListInputQueryUser struct {
// id is the user's ID.
+3
View File
@@ -20,6 +20,9 @@ type OmitEmptyQueryResponse struct {
Convert2 time.Time `json:"convert2"`
}
// OmitEmptyQueryUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type OmitEmptyQueryUser struct {
// id is the user's ID.
+6
View File
@@ -9,6 +9,9 @@ import (
"github.com/me/mypkg"
)
// PointersQueryOtherUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type PointersQueryOtherUser struct {
// id is the user's ID.
@@ -32,6 +35,9 @@ type PointersQueryResponse struct {
MaybeConvert *time.Time `json:"maybeConvert"`
}
// PointersQueryUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type PointersQueryUser struct {
// id is the user's ID.
+6
View File
@@ -9,6 +9,9 @@ import (
"github.com/me/mypkg"
)
// PointersQueryOtherUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type PointersQueryOtherUser struct {
// id is the user's ID.
@@ -32,6 +35,9 @@ type PointersQueryResponse struct {
MaybeConvert time.Time `json:"maybeConvert"`
}
// PointersQueryUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type PointersQueryUser struct {
// id is the user's ID.
+3
View File
@@ -16,6 +16,9 @@ type QueryWithAliasResponse struct {
User QueryWithAliasUser `json:"User"`
}
// QueryWithAliasUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type QueryWithAliasUser struct {
// id is the user's ID.
@@ -16,6 +16,9 @@ type QueryWithDoubleAliasResponse struct {
User QueryWithDoubleAliasUser `json:"user"`
}
// QueryWithDoubleAliasUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type QueryWithDoubleAliasUser struct {
// id is the user's ID.
+6
View File
@@ -6,6 +6,9 @@ import (
"github.com/Khan/genqlient/graphql"
)
// QueryWithEnumsOtherUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type QueryWithEnumsOtherUser struct {
Roles []Role `json:"roles"`
@@ -25,6 +28,9 @@ type QueryWithEnumsResponse struct {
OtherUser QueryWithEnumsOtherUser `json:"otherUser"`
}
// QueryWithEnumsUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type QueryWithEnumsUser struct {
Roles []Role `json:"roles"`
+3
View File
@@ -15,6 +15,9 @@ type QueryWithSlicesResponse struct {
User QueryWithSlicesUser `json:"user"`
}
// QueryWithSlicesUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type QueryWithSlicesUser struct {
Emails []string `json:"emails"`
+4
View File
@@ -15,11 +15,15 @@ type QueryWithStructsResponse struct {
User QueryWithStructsUser `json:"user"`
}
// QueryWithStructsUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type QueryWithStructsUser struct {
AuthMethods []QueryWithStructsUserAuthMethodsAuthMethod `json:"authMethods"`
}
// QueryWithStructsUserAuthMethodsAuthMethod includes the requested fields of the GraphQL type AuthMethod.
type QueryWithStructsUserAuthMethodsAuthMethod struct {
Provider string `json:"provider"`
Email string `json:"email"`
+3
View File
@@ -16,6 +16,9 @@ type SimpleInputQueryResponse struct {
User SimpleInputQueryUser `json:"user"`
}
// SimpleInputQueryUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type SimpleInputQueryUser struct {
// id is the user's ID.
+3
View File
@@ -7,6 +7,9 @@ import (
"github.com/me/mypkg"
)
// SimpleMutationCreateUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type SimpleMutationCreateUser struct {
// id is the user's ID.
+3
View File
@@ -16,6 +16,9 @@ type SimpleQueryResponse struct {
User SimpleQueryUser `json:"user"`
}
// SimpleQueryUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type SimpleQueryUser struct {
// id is the user's ID.
+3
View File
@@ -16,6 +16,9 @@ type TypeNameQueryResponse struct {
User TypeNameQueryUser `json:"user"`
}
// TypeNameQueryUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type TypeNameQueryUser struct {
Typename string `json:"__typename"`
+5
View File
@@ -8,6 +8,7 @@ import (
"github.com/Khan/genqlient/graphql"
)
// UnionNoFragmentsQueryRandomLeafArticle includes the requested fields of the GraphQL type Article.
type UnionNoFragmentsQueryRandomLeafArticle struct {
Typename string `json:"__typename"`
}
@@ -15,11 +16,15 @@ type UnionNoFragmentsQueryRandomLeafArticle struct {
func (v UnionNoFragmentsQueryRandomLeafArticle) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() {
}
// UnionNoFragmentsQueryRandomLeafLeafContent includes the requested fields of the GraphQL type LeafContent.
// The GraphQL type's documentation follows.
//
// LeafContent represents content items that can't have child-nodes.
type UnionNoFragmentsQueryRandomLeafLeafContent interface {
implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent()
}
// UnionNoFragmentsQueryRandomLeafVideo includes the requested fields of the GraphQL type Video.
type UnionNoFragmentsQueryRandomLeafVideo struct {
Typename string `json:"__typename"`
}
+6
View File
@@ -20,11 +20,17 @@ const (
RoleTeacher Role = "TEACHER"
)
// UsesEnumTwiceQueryMeUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type UsesEnumTwiceQueryMeUser struct {
Roles []Role `json:"roles"`
}
// UsesEnumTwiceQueryOtherUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type UsesEnumTwiceQueryOtherUser struct {
Roles []Role `json:"roles"`
+3
View File
@@ -30,6 +30,9 @@ type unexportedResponse struct {
User unexportedUser `json:"user"`
}
// unexportedUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A User is a user!
type unexportedUser struct {
// id is the user's ID.
+19 -1
View File
@@ -317,7 +317,25 @@ func (builder *typeBuilder) writeTypedef(
}()
if description == "" {
description = typedef.Description
switch typedef.Kind {
case ast.Object, ast.Interface, ast.Union:
// For types where we only have some fields, note that, along with
// the GraphQL documentation (if any). We don't want to just use
// the GraphQL documentation, since it may refer to fields we
// haven't selected, say.
// TODO: When we implement interfaces and unions more completely,
// also mention the concrete types they might be.
description = fmt.Sprintf(
"%v includes the requested fields of the GraphQL type %v.",
typeName, typedef.Name)
if typedef.Description != "" {
description = fmt.Sprintf(
"%v\nThe GraphQL type's documentation follows.\n\n%v",
description, typedef.Description)
}
default:
description = typedef.Description
}
}
builder.writeDescription(description)