total rewrite to interface handling; not complete but it compiles
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
query InterfaceNoFragmentsQuery {
|
||||
root {
|
||||
id
|
||||
name
|
||||
children {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type Article struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (v Article) implementsGraphQLInterfaceContent() {}
|
||||
|
||||
type Content interface {
|
||||
implementsGraphQLInterfaceContent()
|
||||
}
|
||||
|
||||
type InterfaceNoFragmentsQueryResponse struct {
|
||||
Root Topic `json:"root"`
|
||||
}
|
||||
|
||||
type Topic struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Children []Content `json:"-"`
|
||||
}
|
||||
|
||||
func (v *Topic) UnmarshalJSON(b []byte) error {
|
||||
var firstPass struct {
|
||||
*Topic
|
||||
Children json.RawMessage `json:"children"`
|
||||
}
|
||||
firstPass.Topic = v
|
||||
|
||||
err := json.Unmarshal(b, &typenames)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var tn struct {
|
||||
TypeName string `json:"__typename"`
|
||||
}
|
||||
err = json.Unmarshal(firstPass.Children, &tn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch tn.TypeName {
|
||||
|
||||
case "Article":
|
||||
v.Children = Article{}
|
||||
err = json.Unmarshal(
|
||||
firstPass.Children, &v.Children)
|
||||
|
||||
case "Video":
|
||||
v.Children = Video{}
|
||||
err = json.Unmarshal(
|
||||
firstPass.Children, &v.Children)
|
||||
|
||||
case "Topic":
|
||||
v.Children = Topic{}
|
||||
err = json.Unmarshal(
|
||||
firstPass.Children, &v.Children)
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Video struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (v Video) implementsGraphQLInterfaceContent() {}
|
||||
|
||||
func InterfaceNoFragmentsQuery(client *graphql.Client) (*InterfaceNoFragmentsQueryResponse, error) {
|
||||
var retval InterfaceNoFragmentsQueryResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query InterfaceNoFragmentsQuery {
|
||||
root {
|
||||
id
|
||||
name
|
||||
children {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{ User: user { ID: id } }
|
||||
query QueryWithAlias { User: user { ID: id } }
|
||||
|
||||
+27
-3
@@ -1,5 +1,29 @@
|
||||
type Response struct {
|
||||
User *struct {
|
||||
ID string
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type QueryWithAliasResponse struct {
|
||||
User *User
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
func QueryWithAlias(client *graphql.Client) (*QueryWithAliasResponse, error) {
|
||||
var retval QueryWithAliasResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query QueryWithAlias {
|
||||
User: user {
|
||||
ID: id
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
query QueryWithDoubleAlias {
|
||||
user {
|
||||
ID: id
|
||||
AlsoID: id
|
||||
|
||||
+31
-6
@@ -1,6 +1,31 @@
|
||||
type Response struct {
|
||||
User *struct {
|
||||
ID string
|
||||
AlsoID string
|
||||
} `json:"user"`
|
||||
}
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type QueryWithDoubleAliasResponse struct {
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID string
|
||||
AlsoID string
|
||||
}
|
||||
|
||||
func QueryWithDoubleAlias(client *graphql.Client) (*QueryWithDoubleAliasResponse, error) {
|
||||
var retval QueryWithDoubleAliasResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query QueryWithDoubleAlias {
|
||||
user {
|
||||
ID: id
|
||||
AlsoID: id
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
query QueryWithEnums {
|
||||
user {
|
||||
roles
|
||||
}
|
||||
|
||||
+32
-8
@@ -1,12 +1,36 @@
|
||||
type Response struct {
|
||||
User *struct {
|
||||
Roles []role `json:"roles"`
|
||||
} `json:"user"`
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type QueryWithEnumsResponse struct {
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type role string
|
||||
type Role string
|
||||
|
||||
const (
|
||||
studentRole role = "STUDENT"
|
||||
teacherRole role = "TEACHER"
|
||||
)
|
||||
StudentRole Role = "STUDENT"
|
||||
TeacherRole Role = "TEACHER"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Roles []Role `json:"roles"`
|
||||
}
|
||||
|
||||
func QueryWithEnums(client *graphql.Client) (*QueryWithEnumsResponse, error) {
|
||||
var retval QueryWithEnumsResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query QueryWithEnums {
|
||||
user {
|
||||
roles
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
query ($query: UserQueryInput) {
|
||||
query QueryWithInput($query: UserQueryInput) {
|
||||
user(query: $query) {
|
||||
id
|
||||
}
|
||||
|
||||
+40
-12
@@ -1,19 +1,47 @@
|
||||
type Response struct {
|
||||
User *struct {
|
||||
Id string `json:"id"`
|
||||
} `json:"user"`
|
||||
}
|
||||
package test
|
||||
|
||||
type role string
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
const (
|
||||
studentRole role = "STUDENT"
|
||||
teacherRole role = "TEACHER"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type userQueryInput struct {
|
||||
type QueryWithInputResponse struct {
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type Role string
|
||||
|
||||
const (
|
||||
StudentRole Role = "STUDENT"
|
||||
TeacherRole Role = "TEACHER"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type UserQueryInput struct {
|
||||
Email *string `json:"email"`
|
||||
Name *string `json:"name"`
|
||||
Id *string `json:"id"`
|
||||
Role *role `json:"role"`
|
||||
}
|
||||
Role *Role `json:"role"`
|
||||
}
|
||||
|
||||
func QueryWithInput(client *graphql.Client, query *UserQueryInput) (*QueryWithInputResponse, error) {
|
||||
variables := map[string]interface{}{
|
||||
"query": query,
|
||||
}
|
||||
|
||||
var retval QueryWithInputResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query QueryWithInput ($query: UserQueryInput) {
|
||||
user(query: $query) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`, &retval, variables)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
query QueryWithSlices {
|
||||
user {
|
||||
emails
|
||||
emailsOrNull
|
||||
|
||||
+35
-8
@@ -1,8 +1,35 @@
|
||||
type Response struct {
|
||||
User *struct {
|
||||
Emails []string `json:"emails"`
|
||||
EmailsOrNull []string `json:"emailsOrNull"`
|
||||
EmailsWithNulls []*string `json:"emailsWithNulls"`
|
||||
EmailsWithNullsOrNull []*string `json:"emailsWithNullsOrNull"`
|
||||
} `json:"user"`
|
||||
}
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type QueryWithSlicesResponse struct {
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Emails []string `json:"emails"`
|
||||
EmailsOrNull []string `json:"emailsOrNull"`
|
||||
EmailsWithNulls []*string `json:"emailsWithNulls"`
|
||||
EmailsWithNullsOrNull []*string `json:"emailsWithNullsOrNull"`
|
||||
}
|
||||
|
||||
func QueryWithSlices(client *graphql.Client) (*QueryWithSlicesResponse, error) {
|
||||
var retval QueryWithSlicesResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query QueryWithSlices {
|
||||
user {
|
||||
emails
|
||||
emailsOrNull
|
||||
emailsWithNulls
|
||||
emailsWithNullsOrNull
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
query QueryWithStructs {
|
||||
user {
|
||||
authMethods {
|
||||
provider
|
||||
|
||||
+37
-8
@@ -1,8 +1,37 @@
|
||||
type Response struct {
|
||||
User *struct {
|
||||
AuthMethods []struct {
|
||||
Provider *string `json:"provider"`
|
||||
Email *string `json:"email"`
|
||||
} `json:"authMethods"`
|
||||
} `json:"user"`
|
||||
}
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type AuthMethod struct {
|
||||
Provider *string `json:"provider"`
|
||||
Email *string `json:"email"`
|
||||
}
|
||||
|
||||
type QueryWithStructsResponse struct {
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
AuthMethods []AuthMethod `json:"authMethods"`
|
||||
}
|
||||
|
||||
func QueryWithStructs(client *graphql.Client) (*QueryWithStructsResponse, error) {
|
||||
var retval QueryWithStructsResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query QueryWithStructs {
|
||||
user {
|
||||
authMethods {
|
||||
provider
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{ user { id } }
|
||||
query SimpleQuery { user { id } }
|
||||
|
||||
+28
-4
@@ -1,5 +1,29 @@
|
||||
type Response struct {
|
||||
User *struct {
|
||||
Id string `json:"id"`
|
||||
} `json:"user"`
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type SimpleQueryResponse struct {
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
func SimpleQuery(client *graphql.Client) (*SimpleQueryResponse, error) {
|
||||
var retval SimpleQueryResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query SimpleQuery {
|
||||
user {
|
||||
id
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
query TypeNameQuery {
|
||||
user {
|
||||
__typename
|
||||
id
|
||||
|
||||
+31
-6
@@ -1,6 +1,31 @@
|
||||
type Response struct {
|
||||
User *struct {
|
||||
Typename *string `json:"__typename"`
|
||||
Id string `json:"id"`
|
||||
} `json:"user"`
|
||||
}
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type TypeNameQueryResponse struct {
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Typename *string `json:"__typename"`
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
func TypeNameQuery(client *graphql.Client) (*TypeNameQueryResponse, error) {
|
||||
var retval TypeNameQueryResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query TypeNameQuery {
|
||||
user {
|
||||
__typename
|
||||
id
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
query UnionNoFragmentsQuery {
|
||||
randomLeaf {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package test
|
||||
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type Article struct {
|
||||
Typename *string `json:"__typename"`
|
||||
}
|
||||
|
||||
func (v Article) implementsGraphQLInterfaceLeafContent() {}
|
||||
|
||||
type LeafContent interface {
|
||||
implementsGraphQLInterfaceLeafContent()
|
||||
}
|
||||
|
||||
type UnionNoFragmentsQueryResponse struct {
|
||||
RandomLeaf LeafContent `json:"-"`
|
||||
}
|
||||
|
||||
func (v *UnionNoFragmentsQueryResponse) UnmarshalJSON(b []byte) error {
|
||||
var firstPass struct {
|
||||
*UnionNoFragmentsQueryResponse
|
||||
RandomLeaf json.RawMessage `json:"randomLeaf"`
|
||||
}
|
||||
firstPass.UnionNoFragmentsQueryResponse = v
|
||||
|
||||
err := json.Unmarshal(b, &typenames)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var tn struct {
|
||||
TypeName string `json:"__typename"`
|
||||
}
|
||||
err = json.Unmarshal(firstPass.RandomLeaf, &tn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch tn.TypeName {
|
||||
|
||||
case "Article":
|
||||
v.RandomLeaf = Article{}
|
||||
err = json.Unmarshal(
|
||||
firstPass.RandomLeaf, &v.RandomLeaf)
|
||||
|
||||
case "Video":
|
||||
v.RandomLeaf = Video{}
|
||||
err = json.Unmarshal(
|
||||
firstPass.RandomLeaf, &v.RandomLeaf)
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Video struct {
|
||||
Typename *string `json:"__typename"`
|
||||
}
|
||||
|
||||
func (v Video) implementsGraphQLInterfaceLeafContent() {}
|
||||
|
||||
func UnionNoFragmentsQuery(client *graphql.Client) (*UnionNoFragmentsQueryResponse, error) {
|
||||
var retval UnionNoFragmentsQueryResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query UnionNoFragmentsQuery {
|
||||
randomLeaf {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
query UsesEnumTwiceQuery {
|
||||
Me: user { roles }
|
||||
OtherUser: user { roles }
|
||||
}
|
||||
|
||||
+48
-12
@@ -1,15 +1,51 @@
|
||||
type Response struct {
|
||||
Me *struct {
|
||||
Roles []role `json:"roles"`
|
||||
}
|
||||
OtherUser *struct {
|
||||
Roles []role `json:"roles"`
|
||||
}
|
||||
}
|
||||
package test
|
||||
|
||||
type role string
|
||||
// Code generated by github.com/Khan/genql, DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Khan/genql/graphql"
|
||||
)
|
||||
|
||||
type Role string
|
||||
|
||||
const (
|
||||
studentRole role = "STUDENT"
|
||||
teacherRole role = "TEACHER"
|
||||
)
|
||||
StudentRole Role = "STUDENT"
|
||||
TeacherRole Role = "TEACHER"
|
||||
)
|
||||
|
||||
type Role1 string
|
||||
|
||||
const (
|
||||
StudentRole1 Role1 = "STUDENT"
|
||||
TeacherRole1 Role1 = "TEACHER"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Roles []Role `json:"roles"`
|
||||
}
|
||||
|
||||
type User1 struct {
|
||||
Roles []Role1 `json:"roles"`
|
||||
}
|
||||
|
||||
type UsesEnumTwiceQueryResponse struct {
|
||||
Me *User
|
||||
OtherUser *User1
|
||||
}
|
||||
|
||||
func UsesEnumTwiceQuery(client *graphql.Client) (*UsesEnumTwiceQueryResponse, error) {
|
||||
var retval UsesEnumTwiceQueryResponse
|
||||
err := client.MakeRequest(context.Background(), `
|
||||
query UsesEnumTwiceQuery {
|
||||
Me: user {
|
||||
roles
|
||||
}
|
||||
OtherUser: user {
|
||||
roles
|
||||
}
|
||||
}
|
||||
`, &retval, nil)
|
||||
return &retval, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user