github.com/codykaup/genqlient@v0.6.2/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go (about) 1 // Code generated by github.com/codykaup/genqlient, DO NOT EDIT. 2 3 package test 4 5 import ( 6 "encoding/json" 7 "fmt" 8 9 "github.com/codykaup/genqlient/graphql" 10 ) 11 12 // UnionNoFragmentsQueryRandomLeafArticle includes the requested fields of the GraphQL type Article. 13 type UnionNoFragmentsQueryRandomLeafArticle struct { 14 Typename string `json:"__typename"` 15 } 16 17 // GetTypename returns UnionNoFragmentsQueryRandomLeafArticle.Typename, and is useful for accessing the field via an interface. 18 func (v *UnionNoFragmentsQueryRandomLeafArticle) GetTypename() string { return v.Typename } 19 20 // UnionNoFragmentsQueryRandomLeafLeafContent includes the requested fields of the GraphQL interface LeafContent. 21 // 22 // UnionNoFragmentsQueryRandomLeafLeafContent is implemented by the following types: 23 // UnionNoFragmentsQueryRandomLeafArticle 24 // UnionNoFragmentsQueryRandomLeafVideo 25 // The GraphQL type's documentation follows. 26 // 27 // LeafContent represents content items that can't have child-nodes. 28 type UnionNoFragmentsQueryRandomLeafLeafContent interface { 29 implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() 30 // GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values). 31 GetTypename() string 32 } 33 34 func (v *UnionNoFragmentsQueryRandomLeafArticle) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() { 35 } 36 func (v *UnionNoFragmentsQueryRandomLeafVideo) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() { 37 } 38 39 func __unmarshalUnionNoFragmentsQueryRandomLeafLeafContent(b []byte, v *UnionNoFragmentsQueryRandomLeafLeafContent) error { 40 if string(b) == "null" { 41 return nil 42 } 43 44 var tn struct { 45 TypeName string `json:"__typename"` 46 } 47 err := json.Unmarshal(b, &tn) 48 if err != nil { 49 return err 50 } 51 52 switch tn.TypeName { 53 case "Article": 54 *v = new(UnionNoFragmentsQueryRandomLeafArticle) 55 return json.Unmarshal(b, *v) 56 case "Video": 57 *v = new(UnionNoFragmentsQueryRandomLeafVideo) 58 return json.Unmarshal(b, *v) 59 case "": 60 return fmt.Errorf( 61 "response was missing LeafContent.__typename") 62 default: 63 return fmt.Errorf( 64 `unexpected concrete type for UnionNoFragmentsQueryRandomLeafLeafContent: "%v"`, tn.TypeName) 65 } 66 } 67 68 func __marshalUnionNoFragmentsQueryRandomLeafLeafContent(v *UnionNoFragmentsQueryRandomLeafLeafContent) ([]byte, error) { 69 70 var typename string 71 switch v := (*v).(type) { 72 case *UnionNoFragmentsQueryRandomLeafArticle: 73 typename = "Article" 74 75 result := struct { 76 TypeName string `json:"__typename"` 77 *UnionNoFragmentsQueryRandomLeafArticle 78 }{typename, v} 79 return json.Marshal(result) 80 case *UnionNoFragmentsQueryRandomLeafVideo: 81 typename = "Video" 82 83 result := struct { 84 TypeName string `json:"__typename"` 85 *UnionNoFragmentsQueryRandomLeafVideo 86 }{typename, v} 87 return json.Marshal(result) 88 case nil: 89 return []byte("null"), nil 90 default: 91 return nil, fmt.Errorf( 92 `unexpected concrete type for UnionNoFragmentsQueryRandomLeafLeafContent: "%T"`, v) 93 } 94 } 95 96 // UnionNoFragmentsQueryRandomLeafVideo includes the requested fields of the GraphQL type Video. 97 type UnionNoFragmentsQueryRandomLeafVideo struct { 98 Typename string `json:"__typename"` 99 } 100 101 // GetTypename returns UnionNoFragmentsQueryRandomLeafVideo.Typename, and is useful for accessing the field via an interface. 102 func (v *UnionNoFragmentsQueryRandomLeafVideo) GetTypename() string { return v.Typename } 103 104 // UnionNoFragmentsQueryResponse is returned by UnionNoFragmentsQuery on success. 105 type UnionNoFragmentsQueryResponse struct { 106 RandomLeaf UnionNoFragmentsQueryRandomLeafLeafContent `json:"-"` 107 } 108 109 // GetRandomLeaf returns UnionNoFragmentsQueryResponse.RandomLeaf, and is useful for accessing the field via an interface. 110 func (v *UnionNoFragmentsQueryResponse) GetRandomLeaf() UnionNoFragmentsQueryRandomLeafLeafContent { 111 return v.RandomLeaf 112 } 113 114 func (v *UnionNoFragmentsQueryResponse) UnmarshalJSON(b []byte) error { 115 116 if string(b) == "null" { 117 return nil 118 } 119 120 var firstPass struct { 121 *UnionNoFragmentsQueryResponse 122 RandomLeaf json.RawMessage `json:"randomLeaf"` 123 graphql.NoUnmarshalJSON 124 } 125 firstPass.UnionNoFragmentsQueryResponse = v 126 127 err := json.Unmarshal(b, &firstPass) 128 if err != nil { 129 return err 130 } 131 132 { 133 dst := &v.RandomLeaf 134 src := firstPass.RandomLeaf 135 if len(src) != 0 && string(src) != "null" { 136 err = __unmarshalUnionNoFragmentsQueryRandomLeafLeafContent( 137 src, dst) 138 if err != nil { 139 return fmt.Errorf( 140 "unable to unmarshal UnionNoFragmentsQueryResponse.RandomLeaf: %w", err) 141 } 142 } 143 } 144 return nil 145 } 146 147 type __premarshalUnionNoFragmentsQueryResponse struct { 148 RandomLeaf json.RawMessage `json:"randomLeaf"` 149 } 150 151 func (v *UnionNoFragmentsQueryResponse) MarshalJSON() ([]byte, error) { 152 premarshaled, err := v.__premarshalJSON() 153 if err != nil { 154 return nil, err 155 } 156 return json.Marshal(premarshaled) 157 } 158 159 func (v *UnionNoFragmentsQueryResponse) __premarshalJSON() (*__premarshalUnionNoFragmentsQueryResponse, error) { 160 var retval __premarshalUnionNoFragmentsQueryResponse 161 162 { 163 164 dst := &retval.RandomLeaf 165 src := v.RandomLeaf 166 var err error 167 *dst, err = __marshalUnionNoFragmentsQueryRandomLeafLeafContent( 168 &src) 169 if err != nil { 170 return nil, fmt.Errorf( 171 "unable to marshal UnionNoFragmentsQueryResponse.RandomLeaf: %w", err) 172 } 173 } 174 return &retval, nil 175 } 176 177 // The query or mutation executed by UnionNoFragmentsQuery. 178 const UnionNoFragmentsQuery_Operation = ` 179 query UnionNoFragmentsQuery { 180 randomLeaf { 181 __typename 182 } 183 } 184 ` 185 186 func UnionNoFragmentsQuery( 187 client_ graphql.Client, 188 ) (*UnionNoFragmentsQueryResponse, error) { 189 req_ := &graphql.Request{ 190 OpName: "UnionNoFragmentsQuery", 191 Query: UnionNoFragmentsQuery_Operation, 192 } 193 var err_ error 194 195 var data_ UnionNoFragmentsQueryResponse 196 resp_ := &graphql.Response{Data: &data_} 197 198 err_ = client_.MakeRequest( 199 nil, 200 req_, 201 resp_, 202 ) 203 204 return &data_, err_ 205 } 206