github.com/operandinc/gqlgen@v0.16.1/codegen/testserver/followschema/useptr.generated.go (about) 1 // Code generated by github.com/operandinc/gqlgen, DO NOT EDIT. 2 3 package followschema 4 5 import ( 6 "context" 7 "fmt" 8 "strconv" 9 10 "github.com/operandinc/gqlgen/graphql" 11 "github.com/vektah/gqlparser/v2/ast" 12 ) 13 14 // region ************************** generated!.gotpl ************************** 15 16 // endregion ************************** generated!.gotpl ************************** 17 18 // region ***************************** args.gotpl ***************************** 19 20 // endregion ***************************** args.gotpl ***************************** 21 22 // region ************************** directives.gotpl ************************** 23 24 // endregion ************************** directives.gotpl ************************** 25 26 // region **************************** field.gotpl ***************************** 27 28 func (ec *executionContext) _A_id(ctx context.Context, field graphql.CollectedField, obj *A) (ret graphql.Marshaler) { 29 defer func() { 30 if r := recover(); r != nil { 31 ec.Error(ctx, ec.Recover(ctx, r)) 32 ret = graphql.Null 33 } 34 }() 35 fc := &graphql.FieldContext{ 36 Object: "A", 37 Field: field, 38 Args: nil, 39 IsMethod: false, 40 IsResolver: false, 41 } 42 43 ctx = graphql.WithFieldContext(ctx, fc) 44 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { 45 ctx = rctx // use context from middleware stack in children 46 return obj.ID, nil 47 }) 48 49 if resTmp == nil { 50 if !graphql.HasFieldError(ctx, fc) { 51 ec.Errorf(ctx, "must not be null") 52 } 53 return graphql.Null 54 } 55 res := resTmp.(string) 56 fc.Result = res 57 return ec.marshalNID2string(ctx, field.Selections, res) 58 } 59 60 func (ec *executionContext) _B_id(ctx context.Context, field graphql.CollectedField, obj *B) (ret graphql.Marshaler) { 61 defer func() { 62 if r := recover(); r != nil { 63 ec.Error(ctx, ec.Recover(ctx, r)) 64 ret = graphql.Null 65 } 66 }() 67 fc := &graphql.FieldContext{ 68 Object: "B", 69 Field: field, 70 Args: nil, 71 IsMethod: false, 72 IsResolver: false, 73 } 74 75 ctx = graphql.WithFieldContext(ctx, fc) 76 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { 77 ctx = rctx // use context from middleware stack in children 78 return obj.ID, nil 79 }) 80 81 if resTmp == nil { 82 if !graphql.HasFieldError(ctx, fc) { 83 ec.Errorf(ctx, "must not be null") 84 } 85 return graphql.Null 86 } 87 res := resTmp.(string) 88 fc.Result = res 89 return ec.marshalNID2string(ctx, field.Selections, res) 90 } 91 92 // endregion **************************** field.gotpl ***************************** 93 94 // region **************************** input.gotpl ***************************** 95 96 // endregion **************************** input.gotpl ***************************** 97 98 // region ************************** interface.gotpl *************************** 99 100 func (ec *executionContext) _TestUnion(ctx context.Context, sel ast.SelectionSet, obj TestUnion) graphql.Marshaler { 101 switch obj := (obj).(type) { 102 case nil: 103 return graphql.Null 104 case A: 105 return ec._A(ctx, sel, &obj) 106 case *A: 107 if obj == nil { 108 return graphql.Null 109 } 110 return ec._A(ctx, sel, obj) 111 case B: 112 return ec._B(ctx, sel, &obj) 113 case *B: 114 if obj == nil { 115 return graphql.Null 116 } 117 return ec._B(ctx, sel, obj) 118 default: 119 panic(fmt.Errorf("unexpected type %T", obj)) 120 } 121 } 122 123 // endregion ************************** interface.gotpl *************************** 124 125 // region **************************** object.gotpl **************************** 126 127 var aImplementors = []string{"A", "TestUnion"} 128 129 func (ec *executionContext) _A(ctx context.Context, sel ast.SelectionSet, obj *A) graphql.Marshaler { 130 fields := graphql.CollectFields(ec.OperationContext, sel, aImplementors) 131 out := graphql.NewFieldSet(fields) 132 var invalids uint32 133 for i, field := range fields { 134 switch field.Name { 135 case "__typename": 136 out.Values[i] = graphql.MarshalString("A") 137 case "id": 138 innerFunc := func(ctx context.Context) (res graphql.Marshaler) { 139 return ec._A_id(ctx, field, obj) 140 } 141 142 out.Values[i] = innerFunc(ctx) 143 144 if out.Values[i] == graphql.Null { 145 invalids++ 146 } 147 default: 148 panic("unknown field " + strconv.Quote(field.Name)) 149 } 150 } 151 out.Dispatch() 152 if invalids > 0 { 153 return graphql.Null 154 } 155 return out 156 } 157 158 var bImplementors = []string{"B", "TestUnion"} 159 160 func (ec *executionContext) _B(ctx context.Context, sel ast.SelectionSet, obj *B) graphql.Marshaler { 161 fields := graphql.CollectFields(ec.OperationContext, sel, bImplementors) 162 out := graphql.NewFieldSet(fields) 163 var invalids uint32 164 for i, field := range fields { 165 switch field.Name { 166 case "__typename": 167 out.Values[i] = graphql.MarshalString("B") 168 case "id": 169 innerFunc := func(ctx context.Context) (res graphql.Marshaler) { 170 return ec._B_id(ctx, field, obj) 171 } 172 173 out.Values[i] = innerFunc(ctx) 174 175 if out.Values[i] == graphql.Null { 176 invalids++ 177 } 178 default: 179 panic("unknown field " + strconv.Quote(field.Name)) 180 } 181 } 182 out.Dispatch() 183 if invalids > 0 { 184 return graphql.Null 185 } 186 return out 187 } 188 189 // endregion **************************** object.gotpl **************************** 190 191 // region ***************************** type.gotpl ***************************** 192 193 func (ec *executionContext) marshalOTestUnion2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐTestUnion(ctx context.Context, sel ast.SelectionSet, v TestUnion) graphql.Marshaler { 194 if v == nil { 195 return graphql.Null 196 } 197 return ec._TestUnion(ctx, sel, v) 198 } 199 200 // endregion ***************************** type.gotpl *****************************