Add documentation to types and fields

Fixes #3.
This commit is contained in:
Ben Kraft
2021-04-21 18:07:36 -07:00
parent 32fea7fae4
commit 748f2cf072
26 changed files with 387 additions and 28 deletions
+12 -2
View File
@@ -9,21 +9,31 @@ import (
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
) )
// getUserResponse is returned by getUser on success.
type getUserResponse struct { type getUserResponse struct {
// Lookup a user by login.
User getUserUser `json:"user"` User getUserUser `json:"user"`
} }
// A user is an individual's account on GitHub that owns repositories and can make new content.
type getUserUser struct { type getUserUser struct {
TheirName string `json:"theirName"` // The user's public profile name.
TheirName string `json:"theirName"`
// Identifies the date and time when the object was created.
CreatedAt time.Time `json:"createdAt"` CreatedAt time.Time `json:"createdAt"`
} }
// getViewerResponse is returned by getViewer on success.
type getViewerResponse struct { type getViewerResponse struct {
// The currently authenticated user.
Viewer getViewerViewerUser `json:"viewer"` Viewer getViewerViewerUser `json:"viewer"`
} }
// A user is an individual's account on GitHub that owns repositories and can make new content.
type getViewerViewerUser struct { type getViewerViewerUser struct {
MyName string `json:"MyName"` // The user's public profile name.
MyName string `json:"MyName"`
// Identifies the date and time when the object was created.
CreatedAt time.Time `json:"createdAt"` CreatedAt time.Time `json:"createdAt"`
} }
+1
View File
@@ -8,6 +8,7 @@ import (
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
) )
// convertTimezoneResponse is returned by convertTimezone on success.
type convertTimezoneResponse struct { type convertTimezoneResponse struct {
Convert time.Time `json:"convert"` Convert time.Time `json:"convert"`
} }
+1
View File
@@ -6,6 +6,7 @@ import (
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
) )
// EmptyInterfaceResponse is returned by EmptyInterface on success.
type EmptyInterfaceResponse struct { type EmptyInterfaceResponse struct {
GetJunk interface{} `json:"getJunk"` GetJunk interface{} `json:"getJunk"`
GetComplexJunk []map[string]*[]*map[string]interface{} `json:"getComplexJunk"` GetComplexJunk []map[string]*[]*map[string]interface{} `json:"getComplexJunk"`
+13
View File
@@ -7,18 +7,31 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// InputEnumQueryResponse is returned by InputEnumQuery on success.
type InputEnumQueryResponse struct { type InputEnumQueryResponse struct {
// usersWithRole looks a user up by role.
UsersWithRole []InputEnumQueryUsersWithRoleUser `json:"usersWithRole"` UsersWithRole []InputEnumQueryUsersWithRoleUser `json:"usersWithRole"`
} }
// A User is a user!
type InputEnumQueryUsersWithRoleUser struct { type InputEnumQueryUsersWithRoleUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
// Role is a type a user may have.
type Role string type Role string
const ( const (
// What is a student?
//
// A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
//
// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
RoleStudent Role = "STUDENT" RoleStudent Role = "STUDENT"
// Teacher is a teacher, who teaches the students.
RoleTeacher Role = "TEACHER" RoleTeacher Role = "TEACHER"
) )
+24 -2
View File
@@ -7,24 +7,46 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// InputObjectQueryResponse is returned by InputObjectQuery on success.
type InputObjectQueryResponse struct { type InputObjectQueryResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User InputObjectQueryUser `json:"user"` User InputObjectQueryUser `json:"user"`
} }
// A User is a user!
type InputObjectQueryUser struct { type InputObjectQueryUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
// Role is a type a user may have.
type Role string type Role string
const ( const (
// What is a student?
//
// A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
//
// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
RoleStudent Role = "STUDENT" RoleStudent Role = "STUDENT"
// Teacher is a teacher, who teaches the students.
RoleTeacher Role = "TEACHER" RoleTeacher Role = "TEACHER"
) )
// UserQueryInput is the argument to Query.users.
//
// Ideally this would support anything and everything!
// Or maybe ideally it wouldn't.
// Really I'm just talking to make this documentation longer.
type UserQueryInput struct { type UserQueryInput struct {
Email string `json:"email"` Email string `json:"email"`
Name string `json:"name"` Name string `json:"name"`
// id looks the user up by ID. It's a great way to look up users.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Role Role `json:"role"` Role Role `json:"role"`
Names []string `json:"names"` Names []string `json:"names"`
+21
View File
@@ -9,11 +9,13 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// InterfaceNestingResponse is returned by InterfaceNesting on success.
type InterfaceNestingResponse struct { type InterfaceNestingResponse struct {
Root InterfaceNestingRootTopic `json:"root"` Root InterfaceNestingRootTopic `json:"root"`
} }
type InterfaceNestingRootTopic struct { type InterfaceNestingRootTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Children []InterfaceNestingRootTopicChildrenContent `json:"-"` Children []InterfaceNestingRootTopicChildrenContent `json:"-"`
} }
@@ -66,6 +68,7 @@ func (v *InterfaceNestingRootTopic) UnmarshalJSON(b []byte) error {
} }
type InterfaceNestingRootTopicChildrenArticle struct { type InterfaceNestingRootTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Parent InterfaceNestingRootTopicChildrenArticleParentTopic `json:"parent"` Parent InterfaceNestingRootTopicChildrenArticleParentTopic `json:"parent"`
} }
@@ -74,6 +77,7 @@ func (v InterfaceNestingRootTopicChildrenArticle) implementsGraphQLInterfaceInte
} }
type InterfaceNestingRootTopicChildrenArticleParentTopic struct { type InterfaceNestingRootTopicChildrenArticleParentTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Children []InterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent `json:"-"` Children []InterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent `json:"-"`
} }
@@ -126,17 +130,20 @@ func (v *InterfaceNestingRootTopicChildrenArticleParentTopic) UnmarshalJSON(b []
} }
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle struct { type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() { func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() {
} }
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent interface { type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent()
} }
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic struct { type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
@@ -144,17 +151,20 @@ func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic) implem
} }
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo struct { type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() { func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() {
} }
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNestingRootTopicChildrenContent interface { type InterfaceNestingRootTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent() implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent()
} }
type InterfaceNestingRootTopicChildrenTopic struct { type InterfaceNestingRootTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Parent InterfaceNestingRootTopicChildrenTopicParentTopic `json:"parent"` Parent InterfaceNestingRootTopicChildrenTopicParentTopic `json:"parent"`
} }
@@ -163,6 +173,7 @@ func (v InterfaceNestingRootTopicChildrenTopic) implementsGraphQLInterfaceInterf
} }
type InterfaceNestingRootTopicChildrenTopicParentTopic struct { type InterfaceNestingRootTopicChildrenTopicParentTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Children []InterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent `json:"-"` Children []InterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent `json:"-"`
} }
@@ -215,17 +226,20 @@ func (v *InterfaceNestingRootTopicChildrenTopicParentTopic) UnmarshalJSON(b []by
} }
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle struct { type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() { func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() {
} }
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent interface { type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent()
} }
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic struct { type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
@@ -233,6 +247,7 @@ func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic) implemen
} }
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo struct { type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
@@ -240,6 +255,7 @@ func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo) implemen
} }
type InterfaceNestingRootTopicChildrenVideo struct { type InterfaceNestingRootTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Parent InterfaceNestingRootTopicChildrenVideoParentTopic `json:"parent"` Parent InterfaceNestingRootTopicChildrenVideoParentTopic `json:"parent"`
} }
@@ -248,6 +264,7 @@ func (v InterfaceNestingRootTopicChildrenVideo) implementsGraphQLInterfaceInterf
} }
type InterfaceNestingRootTopicChildrenVideoParentTopic struct { type InterfaceNestingRootTopicChildrenVideoParentTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Children []InterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent `json:"-"` Children []InterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent `json:"-"`
} }
@@ -300,17 +317,20 @@ func (v *InterfaceNestingRootTopicChildrenVideoParentTopic) UnmarshalJSON(b []by
} }
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle struct { type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
func (v InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent() { func (v InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent() {
} }
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent interface { type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent() implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent()
} }
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic struct { type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
@@ -318,6 +338,7 @@ func (v InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic) implemen
} }
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenVideo struct { type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
@@ -9,11 +9,13 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// InterfaceNoFragmentsQueryResponse is returned by InterfaceNoFragmentsQuery on success.
type InterfaceNoFragmentsQueryResponse struct { type InterfaceNoFragmentsQueryResponse struct {
Root InterfaceNoFragmentsQueryRootTopic `json:"root"` Root InterfaceNoFragmentsQueryRootTopic `json:"root"`
} }
type InterfaceNoFragmentsQueryRootTopic struct { type InterfaceNoFragmentsQueryRootTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Children []InterfaceNoFragmentsQueryRootTopicChildrenContent `json:"-"` Children []InterfaceNoFragmentsQueryRootTopicChildrenContent `json:"-"`
@@ -67,6 +69,7 @@ func (v *InterfaceNoFragmentsQueryRootTopic) UnmarshalJSON(b []byte) error {
} }
type InterfaceNoFragmentsQueryRootTopicChildrenArticle struct { type InterfaceNoFragmentsQueryRootTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} }
@@ -74,11 +77,13 @@ type InterfaceNoFragmentsQueryRootTopicChildrenArticle struct {
func (v InterfaceNoFragmentsQueryRootTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent() { func (v InterfaceNoFragmentsQueryRootTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent() {
} }
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNoFragmentsQueryRootTopicChildrenContent interface { type InterfaceNoFragmentsQueryRootTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent() implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent()
} }
type InterfaceNoFragmentsQueryRootTopicChildrenTopic struct { type InterfaceNoFragmentsQueryRootTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} }
@@ -87,6 +92,7 @@ func (v InterfaceNoFragmentsQueryRootTopicChildrenTopic) implementsGraphQLInterf
} }
type InterfaceNoFragmentsQueryRootTopicChildrenVideo struct { type InterfaceNoFragmentsQueryRootTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} }
+9
View File
@@ -7,11 +7,20 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// ListInputQueryResponse is returned by ListInputQuery on success.
type ListInputQueryResponse struct { type ListInputQueryResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User ListInputQueryUser `json:"user"` User ListInputQueryUser `json:"user"`
} }
// A User is a user!
type ListInputQueryUser struct { type ListInputQueryUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
@@ -6,6 +6,7 @@ import (
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
) )
// ListOfListsOfListsResponse is returned by ListOfListsOfLists on success.
type ListOfListsOfListsResponse struct { type ListOfListsOfListsResponse struct {
ListOfListsOfLists [][][]string `json:"listOfListsOfLists"` ListOfListsOfLists [][][]string `json:"listOfListsOfLists"`
} }
+24 -2
View File
@@ -9,26 +9,48 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// OmitEmptyQueryResponse is returned by OmitEmptyQuery on success.
type OmitEmptyQueryResponse struct { type OmitEmptyQueryResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User OmitEmptyQueryUser `json:"user"` User OmitEmptyQueryUser `json:"user"`
MaybeConvert time.Time `json:"maybeConvert"` MaybeConvert time.Time `json:"maybeConvert"`
Convert2 time.Time `json:"convert2"` Convert2 time.Time `json:"convert2"`
} }
// A User is a user!
type OmitEmptyQueryUser struct { type OmitEmptyQueryUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
// Role is a type a user may have.
type Role string type Role string
const ( const (
// What is a student?
//
// A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
//
// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
RoleStudent Role = "STUDENT" RoleStudent Role = "STUDENT"
// Teacher is a teacher, who teaches the students.
RoleTeacher Role = "TEACHER" RoleTeacher Role = "TEACHER"
) )
// UserQueryInput is the argument to Query.users.
//
// Ideally this would support anything and everything!
// Or maybe ideally it wouldn't.
// Really I'm just talking to make this documentation longer.
type UserQueryInput struct { type UserQueryInput struct {
Email string `json:"email"` Email string `json:"email"`
Name string `json:"name"` Name string `json:"name"`
// id looks the user up by ID. It's a great way to look up users.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Role Role `json:"role"` Role Role `json:"role"`
Names []string `json:"names"` Names []string `json:"names"`
+33 -3
View File
@@ -9,17 +9,34 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// A User is a user!
type PointersQueryOtherUser struct { type PointersQueryOtherUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id *mypkg.ID `json:"id"` Id *mypkg.ID `json:"id"`
} }
// PointersQueryResponse is returned by PointersQuery on success.
type PointersQueryResponse struct { type PointersQueryResponse struct {
User *PointersQueryUser `json:"user"` // user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User *PointersQueryUser `json:"user"`
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
OtherUser *PointersQueryOtherUser `json:"otherUser"` OtherUser *PointersQueryOtherUser `json:"otherUser"`
MaybeConvert *time.Time `json:"maybeConvert"` MaybeConvert *time.Time `json:"maybeConvert"`
} }
// A User is a user!
type PointersQueryUser struct { type PointersQueryUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id *mypkg.ID `json:"id"` Id *mypkg.ID `json:"id"`
Roles []*Role `json:"roles"` Roles []*Role `json:"roles"`
Name *string `json:"name"` Name *string `json:"name"`
@@ -27,16 +44,29 @@ type PointersQueryUser struct {
EmailsNoPtr []string `json:"emailsNoPtr"` EmailsNoPtr []string `json:"emailsNoPtr"`
} }
// Role is a type a user may have.
type Role string type Role string
const ( const (
// What is a student?
//
// A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
//
// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
RoleStudent Role = "STUDENT" RoleStudent Role = "STUDENT"
// Teacher is a teacher, who teaches the students.
RoleTeacher Role = "TEACHER" RoleTeacher Role = "TEACHER"
) )
// UserQueryInput is the argument to Query.users.
//
// Ideally this would support anything and everything!
// Or maybe ideally it wouldn't.
// Really I'm just talking to make this documentation longer.
type UserQueryInput struct { type UserQueryInput struct {
Email *string `json:"email"` Email *string `json:"email"`
Name *string `json:"name"` Name *string `json:"name"`
// id looks the user up by ID. It's a great way to look up users.
Id *mypkg.ID `json:"id"` Id *mypkg.ID `json:"id"`
Role *Role `json:"role"` Role *Role `json:"role"`
Names []*string `json:"names"` Names []*string `json:"names"`
+33 -3
View File
@@ -9,17 +9,34 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// A User is a user!
type PointersQueryOtherUser struct { type PointersQueryOtherUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
// PointersQueryResponse is returned by PointersQuery on success.
type PointersQueryResponse struct { type PointersQueryResponse struct {
User *PointersQueryUser `json:"user"` // user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User *PointersQueryUser `json:"user"`
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
OtherUser *PointersQueryOtherUser `json:"otherUser"` OtherUser *PointersQueryOtherUser `json:"otherUser"`
MaybeConvert time.Time `json:"maybeConvert"` MaybeConvert time.Time `json:"maybeConvert"`
} }
// A User is a user!
type PointersQueryUser struct { type PointersQueryUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Roles []Role `json:"roles"` Roles []Role `json:"roles"`
Name *string `json:"name"` Name *string `json:"name"`
@@ -27,16 +44,29 @@ type PointersQueryUser struct {
EmailsNoPtr []*string `json:"emailsNoPtr"` EmailsNoPtr []*string `json:"emailsNoPtr"`
} }
// Role is a type a user may have.
type Role string type Role string
const ( const (
// What is a student?
//
// A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
//
// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
RoleStudent Role = "STUDENT" RoleStudent Role = "STUDENT"
// Teacher is a teacher, who teaches the students.
RoleTeacher Role = "TEACHER" RoleTeacher Role = "TEACHER"
) )
// UserQueryInput is the argument to Query.users.
//
// Ideally this would support anything and everything!
// Or maybe ideally it wouldn't.
// Really I'm just talking to make this documentation longer.
type UserQueryInput struct { type UserQueryInput struct {
Email string `json:"email"` Email string `json:"email"`
Name string `json:"name"` Name string `json:"name"`
// id looks the user up by ID. It's a great way to look up users.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Role Role `json:"role"` Role Role `json:"role"`
Names []string `json:"names"` Names []string `json:"names"`
+13 -1
View File
@@ -7,12 +7,24 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// QueryWithAliasResponse is returned by QueryWithAlias on success.
type QueryWithAliasResponse struct { type QueryWithAliasResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User QueryWithAliasUser `json:"User"` User QueryWithAliasUser `json:"User"`
} }
// A User is a user!
type QueryWithAliasUser struct { type QueryWithAliasUser struct {
ID mypkg.ID `json:"ID"` // id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
ID mypkg.ID `json:"ID"`
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
OtherID mypkg.ID `json:"otherID"` OtherID mypkg.ID `json:"otherID"`
} }
+13 -1
View File
@@ -7,12 +7,24 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// QueryWithDoubleAliasResponse is returned by QueryWithDoubleAlias on success.
type QueryWithDoubleAliasResponse struct { type QueryWithDoubleAliasResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User QueryWithDoubleAliasUser `json:"user"` User QueryWithDoubleAliasUser `json:"user"`
} }
// A User is a user!
type QueryWithDoubleAliasUser struct { type QueryWithDoubleAliasUser struct {
ID mypkg.ID `json:"ID"` // id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
ID mypkg.ID `json:"ID"`
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
AlsoID mypkg.ID `json:"AlsoID"` AlsoID mypkg.ID `json:"AlsoID"`
} }
+19 -1
View File
@@ -6,23 +6,41 @@ import (
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
) )
// A User is a user!
type QueryWithEnumsOtherUser struct { type QueryWithEnumsOtherUser struct {
Roles []Role `json:"roles"` Roles []Role `json:"roles"`
} }
// QueryWithEnumsResponse is returned by QueryWithEnums on success.
type QueryWithEnumsResponse struct { type QueryWithEnumsResponse struct {
User QueryWithEnumsUser `json:"user"` // user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User QueryWithEnumsUser `json:"user"`
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
OtherUser QueryWithEnumsOtherUser `json:"otherUser"` OtherUser QueryWithEnumsOtherUser `json:"otherUser"`
} }
// A User is a user!
type QueryWithEnumsUser struct { type QueryWithEnumsUser struct {
Roles []Role `json:"roles"` Roles []Role `json:"roles"`
} }
// Role is a type a user may have.
type Role string type Role string
const ( const (
// What is a student?
//
// A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
//
// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
RoleStudent Role = "STUDENT" RoleStudent Role = "STUDENT"
// Teacher is a teacher, who teaches the students.
RoleTeacher Role = "TEACHER" RoleTeacher Role = "TEACHER"
) )
+6
View File
@@ -6,10 +6,16 @@ import (
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
) )
// QueryWithSlicesResponse is returned by QueryWithSlices on success.
type QueryWithSlicesResponse struct { type QueryWithSlicesResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User QueryWithSlicesUser `json:"user"` User QueryWithSlicesUser `json:"user"`
} }
// A User is a user!
type QueryWithSlicesUser struct { type QueryWithSlicesUser struct {
Emails []string `json:"emails"` Emails []string `json:"emails"`
EmailsOrNull []string `json:"emailsOrNull"` EmailsOrNull []string `json:"emailsOrNull"`
+6
View File
@@ -6,10 +6,16 @@ import (
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
) )
// QueryWithStructsResponse is returned by QueryWithStructs on success.
type QueryWithStructsResponse struct { type QueryWithStructsResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User QueryWithStructsUser `json:"user"` User QueryWithStructsUser `json:"user"`
} }
// A User is a user!
type QueryWithStructsUser struct { type QueryWithStructsUser struct {
AuthMethods []QueryWithStructsUserAuthMethodsAuthMethod `json:"authMethods"` AuthMethods []QueryWithStructsUserAuthMethodsAuthMethod `json:"authMethods"`
} }
+9
View File
@@ -7,11 +7,20 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// SimpleInputQueryResponse is returned by SimpleInputQuery on success.
type SimpleInputQueryResponse struct { type SimpleInputQueryResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User SimpleInputQueryUser `json:"user"` User SimpleInputQueryUser `json:"user"`
} }
// A User is a user!
type SimpleInputQueryUser struct { type SimpleInputQueryUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
+5
View File
@@ -7,11 +7,16 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// A User is a user!
type SimpleMutationCreateUser struct { type SimpleMutationCreateUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} }
// SimpleMutationResponse is returned by SimpleMutation on success.
type SimpleMutationResponse struct { type SimpleMutationResponse struct {
CreateUser SimpleMutationCreateUser `json:"createUser"` CreateUser SimpleMutationCreateUser `json:"createUser"`
} }
+9
View File
@@ -7,11 +7,20 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// SimpleQueryResponse is returned by SimpleQuery on success.
type SimpleQueryResponse struct { type SimpleQueryResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User SimpleQueryUser `json:"user"` User SimpleQueryUser `json:"user"`
} }
// A User is a user!
type SimpleQueryUser struct { type SimpleQueryUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
+11 -2
View File
@@ -7,13 +7,22 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// TypeNameQueryResponse is returned by TypeNameQuery on success.
type TypeNameQueryResponse struct { type TypeNameQueryResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User TypeNameQueryUser `json:"user"` User TypeNameQueryUser `json:"user"`
} }
// A User is a user!
type TypeNameQueryUser struct { type TypeNameQueryUser struct {
Typename string `json:"__typename"` Typename string `json:"__typename"`
Id mypkg.ID `json:"id"` // id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"`
} }
func TypeNameQuery( func TypeNameQuery(
+2
View File
@@ -15,6 +15,7 @@ type UnionNoFragmentsQueryRandomLeafArticle struct {
func (v UnionNoFragmentsQueryRandomLeafArticle) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() { func (v UnionNoFragmentsQueryRandomLeafArticle) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() {
} }
// LeafContent represents content items that can't have child-nodes.
type UnionNoFragmentsQueryRandomLeafLeafContent interface { type UnionNoFragmentsQueryRandomLeafLeafContent interface {
implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent()
} }
@@ -26,6 +27,7 @@ type UnionNoFragmentsQueryRandomLeafVideo struct {
func (v UnionNoFragmentsQueryRandomLeafVideo) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() { func (v UnionNoFragmentsQueryRandomLeafVideo) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() {
} }
// UnionNoFragmentsQueryResponse is returned by UnionNoFragmentsQuery on success.
type UnionNoFragmentsQueryResponse struct { type UnionNoFragmentsQueryResponse struct {
RandomLeaf UnionNoFragmentsQueryRandomLeafLeafContent `json:"-"` RandomLeaf UnionNoFragmentsQueryRandomLeafLeafContent `json:"-"`
} }
+19 -1
View File
@@ -6,23 +6,41 @@ import (
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
) )
// Role is a type a user may have.
type Role string type Role string
const ( const (
// What is a student?
//
// A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
//
// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
RoleStudent Role = "STUDENT" RoleStudent Role = "STUDENT"
// Teacher is a teacher, who teaches the students.
RoleTeacher Role = "TEACHER" RoleTeacher Role = "TEACHER"
) )
// A User is a user!
type UsesEnumTwiceQueryMeUser struct { type UsesEnumTwiceQueryMeUser struct {
Roles []Role `json:"roles"` Roles []Role `json:"roles"`
} }
// A User is a user!
type UsesEnumTwiceQueryOtherUser struct { type UsesEnumTwiceQueryOtherUser struct {
Roles []Role `json:"roles"` Roles []Role `json:"roles"`
} }
// UsesEnumTwiceQueryResponse is returned by UsesEnumTwiceQuery on success.
type UsesEnumTwiceQueryResponse struct { type UsesEnumTwiceQueryResponse struct {
Me UsesEnumTwiceQueryMeUser `json:"Me"` // user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
Me UsesEnumTwiceQueryMeUser `json:"Me"`
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
OtherUser UsesEnumTwiceQueryOtherUser `json:"OtherUser"` OtherUser UsesEnumTwiceQueryOtherUser `json:"OtherUser"`
} }
+38
View File
@@ -1,15 +1,35 @@
"""DateTime is a scalar.
We don't really have anything useful to do with this description though.
"""
scalar DateTime scalar DateTime
scalar Junk scalar Junk
scalar ComplexJunk scalar ComplexJunk
"""Role is a type a user may have."""
enum Role { enum Role {
"""What is a student?
A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
(from [Wikipedia](https://en.wikipedia.org/wiki/Student))
"""
STUDENT STUDENT
"""Teacher is a teacher, who teaches the students."""
TEACHER TEACHER
} }
"""UserQueryInput is the argument to Query.users.
Ideally this would support anything and everything!
Or maybe ideally it wouldn't.
Really I'm just talking to make this documentation longer.
"""
input UserQueryInput { input UserQueryInput {
email: String email: String
name: String name: String
"""id looks the user up by ID. It's a great way to look up users."""
id: ID id: ID
role: Role role: Role
names: [String] names: [String]
@@ -20,7 +40,11 @@ type AuthMethod {
email: String email: String
} }
"""A User is a user!"""
type User { type User {
"""id is the user's ID.
It is stable, unique, and opaque, like all good IDs."""
id: ID! id: ID!
roles: [Role!] roles: [Role!]
name: String name: String
@@ -31,15 +55,19 @@ type User {
authMethods: [AuthMethod!]! authMethods: [AuthMethod!]!
} }
"""Content is implemented by various types like Article, Video, and Topic."""
interface Content { interface Content {
"""ID is the identifier of the content."""
id: ID! id: ID!
name: String! name: String!
parent: Topic parent: Topic
} }
"""LeafContent represents content items that can't have child-nodes."""
union LeafContent = Article | Video union LeafContent = Article | Video
type Article implements Content { type Article implements Content {
"""ID is documented in the Content interface."""
id: ID! id: ID!
name: String! name: String!
parent: Topic! parent: Topic!
@@ -47,6 +75,7 @@ type Article implements Content {
} }
type Video implements Content { type Video implements Content {
"""ID is documented in the Content interface."""
id: ID! id: ID!
name: String! name: String!
parent: Topic! parent: Topic!
@@ -54,14 +83,23 @@ type Video implements Content {
} }
type Topic implements Content { type Topic implements Content {
"""ID is documented in the Content interface."""
id: ID! id: ID!
name: String! name: String!
parent: Topic parent: Topic
children: [Content!]! children: [Content!]!
} }
"""Query's description is probably ignored by almost all callers."""
type Query { type Query {
"""user looks up a user by some stuff.
See UserQueryInput for what stuff is supported.
If query is null, returns the current user.
"""
user(query: UserQueryInput): User user(query: UserQueryInput): User
"""usersWithRole looks a user up by role."""
usersWithRole(role: Role!): [User!]! usersWithRole(role: Role!): [User!]!
root: Topic! root: Topic!
randomLeaf: LeafContent! randomLeaf: LeafContent!
+24 -2
View File
@@ -7,24 +7,46 @@ import (
"github.com/me/mypkg" "github.com/me/mypkg"
) )
// Role is a type a user may have.
type Role string type Role string
const ( const (
// What is a student?
//
// A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive.
//
// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
RoleStudent Role = "STUDENT" RoleStudent Role = "STUDENT"
// Teacher is a teacher, who teaches the students.
RoleTeacher Role = "TEACHER" RoleTeacher Role = "TEACHER"
) )
// unexportedResponse is returned by unexported on success.
type unexportedResponse struct { type unexportedResponse struct {
// user looks up a user by some stuff.
//
// See UserQueryInput for what stuff is supported.
// If query is null, returns the current user.
User unexportedUser `json:"user"` User unexportedUser `json:"user"`
} }
// A User is a user!
type unexportedUser struct { type unexportedUser struct {
// id is the user's ID.
//
// It is stable, unique, and opaque, like all good IDs.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
} }
// UserQueryInput is the argument to Query.users.
//
// Ideally this would support anything and everything!
// Or maybe ideally it wouldn't.
// Really I'm just talking to make this documentation longer.
type userQueryInput struct { type userQueryInput struct {
Email string `json:"email"` Email string `json:"email"`
Name string `json:"name"` Name string `json:"name"`
// id looks the user up by ID. It's a great way to look up users.
Id mypkg.ID `json:"id"` Id mypkg.ID `json:"id"`
Role Role `json:"role"` Role Role `json:"role"`
Names []string `json:"names"` Names []string `json:"names"`
+35 -8
View File
@@ -54,9 +54,11 @@ func (g *generator) getTypeForOperation(operation *ast.OperationDefinition, quer
return "", errorf(operation.Position, "%v", err) return "", errorf(operation.Position, "%v", err)
} }
description := fmt.Sprintf("%v is returned by %v on success.", name, operation.Name)
builder := &typeBuilder{generator: g} builder := &typeBuilder{generator: g}
err = builder.writeTypedef( err = builder.writeTypedef(
name, operation.Name, baseType, operation.Position, fields, queryOptions) name, operation.Name, baseType, operation.Position, fields, queryOptions, description)
return name, err return name, err
} }
@@ -129,6 +131,7 @@ func (g *generator) getTypeForInputType(opName string, typ *ast.Type, options, q
type field interface { type field interface {
Alias() string Alias() string
Options() (*GenqlientDirective, error) Options() (*GenqlientDirective, error)
Description() string
Type() *ast.Type Type() *ast.Type
Pos() *ast.Position Pos() *ast.Position
SubFields() ([]field, error) SubFields() ([]field, error)
@@ -154,6 +157,13 @@ func (s outputField) Options() (*GenqlientDirective, error) {
return s.queryOptions.merge(directive), nil return s.queryOptions.merge(directive), nil
} }
func (s outputField) Description() string {
if s.field.Definition == nil {
return ""
}
return s.field.Definition.Description
}
func (s outputField) Type() *ast.Type { func (s outputField) Type() *ast.Type {
if s.field.Definition == nil { if s.field.Definition == nil {
return nil return nil
@@ -200,8 +210,9 @@ func (s inputField) Options() (*GenqlientDirective, error) {
} }
return s.queryOptions.merge(directive), nil return s.queryOptions.merge(directive), nil
} }
func (s inputField) Type() *ast.Type { return s.field.Type } func (s inputField) Description() string { return s.field.Description }
func (s inputField) Pos() *ast.Position { return s.field.Position } func (s inputField) Type() *ast.Type { return s.field.Type }
func (s inputField) Pos() *ast.Position { return s.field.Position }
func (s inputField) SubFields() ([]field, error) { func (s inputField) SubFields() ([]field, error) {
return selectionsForInputType(s.generator, s.field.Type, s.queryOptions), nil return selectionsForInputType(s.generator, s.field.Type, s.queryOptions), nil
@@ -221,9 +232,6 @@ func (builder *typeBuilder) writeField(typeNamePrefix string, field field) error
// We need an exportable name for JSON-marshaling. // We need an exportable name for JSON-marshaling.
goName := upperFirst(jsonName) goName := upperFirst(jsonName)
builder.WriteString(goName)
builder.WriteRune(' ')
typ := field.Type() typ := field.Type()
if typ == nil { if typ == nil {
// Unclear why gqlparser hasn't already rejected this, // Unclear why gqlparser hasn't already rejected this,
@@ -243,6 +251,10 @@ func (builder *typeBuilder) writeField(typeNamePrefix string, field field) error
typedef := builder.schema.Types[typ.Name()] typedef := builder.schema.Types[typ.Name()]
builder.writeDescription(field.Description())
builder.WriteString(goName)
builder.WriteRune(' ')
// Note we don't deduplicate suffixes here -- if our prefix is GetUser // Note we don't deduplicate suffixes here -- if our prefix is GetUser
// and the field name is User, we do GetUserUser. This is important // and the field name is User, we do GetUserUser. This is important
// because if you have a field called user on a type called User we // because if you have a field called user on a type called User we
@@ -301,7 +313,7 @@ func (builder *typeBuilder) writeType(name, namePrefix string, typ *ast.Type, fi
builder.WriteString(name) builder.WriteString(name)
childBuilder := &typeBuilder{generator: builder.generator} childBuilder := &typeBuilder{generator: builder.generator}
return childBuilder.writeTypedef(name, namePrefix, def, typ.Position, fields, options) return childBuilder.writeTypedef(name, namePrefix, def, typ.Position, fields, options, "")
} }
func (builder *typeBuilder) writeTypedef( func (builder *typeBuilder) writeTypedef(
@@ -310,6 +322,7 @@ func (builder *typeBuilder) writeTypedef(
pos *ast.Position, pos *ast.Position,
fields []field, fields []field,
options *GenqlientDirective, options *GenqlientDirective,
description string, // defaults to typedef.Description
) (err error) { ) (err error) {
defer func() { defer func() {
// Whenever we're done, add the type to the type-map. // Whenever we're done, add the type to the type-map.
@@ -321,6 +334,11 @@ func (builder *typeBuilder) writeTypedef(
} }
}() }()
if description == "" {
description = typedef.Description
}
builder.writeDescription(description)
fmt.Fprintf(builder, "type %s ", typeName) fmt.Fprintf(builder, "type %s ", typeName)
switch typedef.Kind { switch typedef.Kind {
case ast.Object, ast.InputObject: case ast.Object, ast.InputObject:
@@ -355,7 +373,7 @@ func (builder *typeBuilder) writeTypedef(
for _, impldef := range builder.schema.GetPossibleTypes(typedef) { for _, impldef := range builder.schema.GetPossibleTypes(typedef) {
name, namePrefix := builder.typeName(typeNamePrefix, impldef) name, namePrefix := builder.typeName(typeNamePrefix, impldef)
implBuilder := &typeBuilder{generator: builder.generator} implBuilder := &typeBuilder{generator: builder.generator}
err := implBuilder.writeTypedef(name, namePrefix, impldef, pos, fields, options) err := implBuilder.writeTypedef(name, namePrefix, impldef, pos, fields, options, "")
if err != nil { if err != nil {
return err return err
} }
@@ -371,6 +389,7 @@ func (builder *typeBuilder) writeTypedef(
builder.WriteString("string\n") builder.WriteString("string\n")
builder.WriteString("const (\n") builder.WriteString("const (\n")
for _, val := range typedef.EnumValues { for _, val := range typedef.EnumValues {
builder.writeDescription(val.Description)
fmt.Fprintf(builder, "%s %s = \"%s\"\n", fmt.Fprintf(builder, "%s %s = \"%s\"\n",
typeName+goConstName(val.Name), typeName+goConstName(val.Name),
typeName, val.Name) typeName, val.Name)
@@ -383,3 +402,11 @@ func (builder *typeBuilder) writeTypedef(
return errorf(pos, "unexpected kind: %v", typedef.Kind) return errorf(pos, "unexpected kind: %v", typedef.Kind)
} }
} }
func (builder *typeBuilder) writeDescription(desc string) {
if desc != "" {
for _, line := range strings.Split(desc, "\n") {
builder.WriteString("// " + strings.TrimLeft(line, " \t") + "\n")
}
}
}