github.com/Desuuuu/genqlient@v0.5.3/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go (about) 1 // Code generated by github.com/Desuuuu/genqlient, DO NOT EDIT. 2 3 package test 4 5 import ( 6 "encoding/json" 7 "fmt" 8 9 "github.com/Desuuuu/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 GetLeafContentArticle() (*UnionNoFragmentsQueryRandomLeafArticle, bool) 33 GetLeafContentVideo() (*UnionNoFragmentsQueryRandomLeafVideo, bool) 34 } 35 36 func (v *UnionNoFragmentsQueryRandomLeafArticle) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() { 37 } 38 func (v *UnionNoFragmentsQueryRandomLeafArticle) GetLeafContentArticle() (*UnionNoFragmentsQueryRandomLeafArticle, bool) { 39 return v, true 40 } 41 func (v *UnionNoFragmentsQueryRandomLeafArticle) GetLeafContentVideo() (*UnionNoFragmentsQueryRandomLeafVideo, bool) { 42 return nil, false 43 } 44 func (v *UnionNoFragmentsQueryRandomLeafVideo) implementsGraphQLInterfaceUnionNoFragmentsQueryRandomLeafLeafContent() { 45 } 46 func (v *UnionNoFragmentsQueryRandomLeafVideo) GetLeafContentArticle() (*UnionNoFragmentsQueryRandomLeafArticle, bool) { 47 return nil, false 48 } 49 func (v *UnionNoFragmentsQueryRandomLeafVideo) GetLeafContentVideo() (*UnionNoFragmentsQueryRandomLeafVideo, bool) { 50 return v, true 51 } 52 53 func __unmarshalUnionNoFragmentsQueryRandomLeafLeafContent(b []byte, v *UnionNoFragmentsQueryRandomLeafLeafContent) error { 54 if string(b) == "null" { 55 return nil 56 } 57 58 var tn struct { 59 TypeName string `json:"__typename"` 60 } 61 err := json.Unmarshal(b, &tn) 62 if err != nil { 63 return err 64 } 65 66 switch tn.TypeName { 67 case "Article": 68 *v = new(UnionNoFragmentsQueryRandomLeafArticle) 69 return json.Unmarshal(b, *v) 70 case "Video": 71 *v = new(UnionNoFragmentsQueryRandomLeafVideo) 72 return json.Unmarshal(b, *v) 73 case "": 74 return fmt.Errorf( 75 "response was missing LeafContent.__typename") 76 default: 77 return fmt.Errorf( 78 `unexpected concrete type for UnionNoFragmentsQueryRandomLeafLeafContent: "%v"`, tn.TypeName) 79 } 80 } 81 82 func __marshalUnionNoFragmentsQueryRandomLeafLeafContent(v *UnionNoFragmentsQueryRandomLeafLeafContent) ([]byte, error) { 83 84 var typename string 85 switch v := (*v).(type) { 86 case *UnionNoFragmentsQueryRandomLeafArticle: 87 typename = "Article" 88 89 result := struct { 90 TypeName string `json:"__typename"` 91 *UnionNoFragmentsQueryRandomLeafArticle 92 }{typename, v} 93 return json.Marshal(result) 94 case *UnionNoFragmentsQueryRandomLeafVideo: 95 typename = "Video" 96 97 result := struct { 98 TypeName string `json:"__typename"` 99 *UnionNoFragmentsQueryRandomLeafVideo 100 }{typename, v} 101 return json.Marshal(result) 102 case nil: 103 return []byte("null"), nil 104 default: 105 return nil, fmt.Errorf( 106 `unexpected concrete type for UnionNoFragmentsQueryRandomLeafLeafContent: "%T"`, v) 107 } 108 } 109 110 // UnionNoFragmentsQueryRandomLeafVideo includes the requested fields of the GraphQL type Video. 111 type UnionNoFragmentsQueryRandomLeafVideo struct { 112 Typename string `json:"__typename"` 113 } 114 115 // GetTypename returns UnionNoFragmentsQueryRandomLeafVideo.Typename, and is useful for accessing the field via an interface. 116 func (v *UnionNoFragmentsQueryRandomLeafVideo) GetTypename() string { return v.Typename } 117 118 // UnionNoFragmentsQueryResponse is returned by UnionNoFragmentsQuery on success. 119 type UnionNoFragmentsQueryResponse struct { 120 RandomLeaf UnionNoFragmentsQueryRandomLeafLeafContent `json:"-"` 121 } 122 123 // GetRandomLeaf returns UnionNoFragmentsQueryResponse.RandomLeaf, and is useful for accessing the field via an interface. 124 func (v *UnionNoFragmentsQueryResponse) GetRandomLeaf() UnionNoFragmentsQueryRandomLeafLeafContent { 125 return v.RandomLeaf 126 } 127 128 func (v *UnionNoFragmentsQueryResponse) UnmarshalJSON(b []byte) error { 129 130 if string(b) == "null" { 131 return nil 132 } 133 134 var firstPass struct { 135 *UnionNoFragmentsQueryResponse 136 RandomLeaf json.RawMessage `json:"randomLeaf"` 137 graphql.NoUnmarshalJSON 138 } 139 firstPass.UnionNoFragmentsQueryResponse = v 140 141 err := json.Unmarshal(b, &firstPass) 142 if err != nil { 143 return err 144 } 145 146 { 147 dst := &v.RandomLeaf 148 src := firstPass.RandomLeaf 149 if len(src) != 0 && string(src) != "null" { 150 err = __unmarshalUnionNoFragmentsQueryRandomLeafLeafContent( 151 src, dst) 152 if err != nil { 153 return fmt.Errorf( 154 "Unable to unmarshal UnionNoFragmentsQueryResponse.RandomLeaf: %w", err) 155 } 156 } 157 } 158 return nil 159 } 160 161 type __premarshalUnionNoFragmentsQueryResponse struct { 162 RandomLeaf json.RawMessage `json:"randomLeaf"` 163 } 164 165 func (v *UnionNoFragmentsQueryResponse) MarshalJSON() ([]byte, error) { 166 premarshaled, err := v.__premarshalJSON() 167 if err != nil { 168 return nil, err 169 } 170 return json.Marshal(premarshaled) 171 } 172 173 func (v *UnionNoFragmentsQueryResponse) __premarshalJSON() (*__premarshalUnionNoFragmentsQueryResponse, error) { 174 var retval __premarshalUnionNoFragmentsQueryResponse 175 176 { 177 178 dst := &retval.RandomLeaf 179 src := v.RandomLeaf 180 var err error 181 *dst, err = __marshalUnionNoFragmentsQueryRandomLeafLeafContent( 182 &src) 183 if err != nil { 184 return nil, fmt.Errorf( 185 "Unable to marshal UnionNoFragmentsQueryResponse.RandomLeaf: %w", err) 186 } 187 } 188 return &retval, nil 189 } 190 191 func UnionNoFragmentsQuery( 192 client graphql.Client, 193 ) (*UnionNoFragmentsQueryResponse, error) { 194 req := &graphql.Request{ 195 OpName: "UnionNoFragmentsQuery", 196 Query: ` 197 query UnionNoFragmentsQuery { 198 randomLeaf { 199 __typename 200 } 201 } 202 `, 203 } 204 var err error 205 206 var data UnionNoFragmentsQueryResponse 207 resp := &graphql.Response{Data: &data} 208 209 err = client.MakeRequest( 210 nil, 211 req, 212 resp, 213 ) 214 215 return &data, err 216 } 217