github.com/mstephano/gqlgen-schemagen@v0.0.0-20230113041936-dd2cd4ea46aa/codegen/testserver/followschema/maps.generated.go (about) 1 // Code generated by github.com/mstephano/gqlgen-schemagen, DO NOT EDIT. 2 3 package followschema 4 5 import ( 6 "context" 7 "errors" 8 "fmt" 9 "strconv" 10 11 "github.com/mstephano/gqlgen-schemagen/graphql" 12 "github.com/vektah/gqlparser/v2/ast" 13 ) 14 15 // region ************************** generated!.gotpl ************************** 16 17 // endregion ************************** generated!.gotpl ************************** 18 19 // region ***************************** args.gotpl ***************************** 20 21 // endregion ***************************** args.gotpl ***************************** 22 23 // region ************************** directives.gotpl ************************** 24 25 // endregion ************************** directives.gotpl ************************** 26 27 // region **************************** field.gotpl ***************************** 28 29 func (ec *executionContext) _MapStringInterfaceType_a(ctx context.Context, field graphql.CollectedField, obj map[string]interface{}) (ret graphql.Marshaler) { 30 fc, err := ec.fieldContext_MapStringInterfaceType_a(ctx, field) 31 if err != nil { 32 return graphql.Null 33 } 34 ctx = graphql.WithFieldContext(ctx, fc) 35 defer func() { 36 if r := recover(); r != nil { 37 ec.Error(ctx, ec.Recover(ctx, r)) 38 ret = graphql.Null 39 } 40 }() 41 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { 42 ctx = rctx // use context from middleware stack in children 43 switch v := obj["a"].(type) { 44 case *string: 45 return v, nil 46 case string: 47 return &v, nil 48 case nil: 49 return (*string)(nil), nil 50 default: 51 return nil, fmt.Errorf("unexpected type %T for field %s", v, "a") 52 } 53 }) 54 55 if resTmp == nil { 56 return graphql.Null 57 } 58 res := resTmp.(*string) 59 fc.Result = res 60 return ec.marshalOString2ᚖstring(ctx, field.Selections, res) 61 } 62 63 func (ec *executionContext) fieldContext_MapStringInterfaceType_a(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { 64 fc = &graphql.FieldContext{ 65 Object: "MapStringInterfaceType", 66 Field: field, 67 IsMethod: false, 68 IsResolver: false, 69 Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { 70 return nil, errors.New("field of type String does not have child fields") 71 }, 72 } 73 return fc, nil 74 } 75 76 func (ec *executionContext) _MapStringInterfaceType_b(ctx context.Context, field graphql.CollectedField, obj map[string]interface{}) (ret graphql.Marshaler) { 77 fc, err := ec.fieldContext_MapStringInterfaceType_b(ctx, field) 78 if err != nil { 79 return graphql.Null 80 } 81 ctx = graphql.WithFieldContext(ctx, fc) 82 defer func() { 83 if r := recover(); r != nil { 84 ec.Error(ctx, ec.Recover(ctx, r)) 85 ret = graphql.Null 86 } 87 }() 88 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { 89 ctx = rctx // use context from middleware stack in children 90 switch v := obj["b"].(type) { 91 case *int: 92 return v, nil 93 case int: 94 return &v, nil 95 case nil: 96 return (*int)(nil), nil 97 default: 98 return nil, fmt.Errorf("unexpected type %T for field %s", v, "b") 99 } 100 }) 101 102 if resTmp == nil { 103 return graphql.Null 104 } 105 res := resTmp.(*int) 106 fc.Result = res 107 return ec.marshalOInt2ᚖint(ctx, field.Selections, res) 108 } 109 110 func (ec *executionContext) fieldContext_MapStringInterfaceType_b(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { 111 fc = &graphql.FieldContext{ 112 Object: "MapStringInterfaceType", 113 Field: field, 114 IsMethod: false, 115 IsResolver: false, 116 Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { 117 return nil, errors.New("field of type Int does not have child fields") 118 }, 119 } 120 return fc, nil 121 } 122 123 // endregion **************************** field.gotpl ***************************** 124 125 // region **************************** input.gotpl ***************************** 126 127 func (ec *executionContext) unmarshalInputNestedMapInput(ctx context.Context, obj interface{}) (NestedMapInput, error) { 128 var it NestedMapInput 129 asMap := map[string]interface{}{} 130 for k, v := range obj.(map[string]interface{}) { 131 asMap[k] = v 132 } 133 134 fieldsInOrder := [...]string{"map"} 135 for _, k := range fieldsInOrder { 136 v, ok := asMap[k] 137 if !ok { 138 continue 139 } 140 switch k { 141 case "map": 142 var err error 143 144 ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("map")) 145 it.Map, err = ec.unmarshalOMapStringInterfaceInput2map(ctx, v) 146 if err != nil { 147 return it, err 148 } 149 } 150 } 151 152 return it, nil 153 } 154 155 // endregion **************************** input.gotpl ***************************** 156 157 // region ************************** interface.gotpl *************************** 158 159 // endregion ************************** interface.gotpl *************************** 160 161 // region **************************** object.gotpl **************************** 162 163 var mapStringInterfaceTypeImplementors = []string{"MapStringInterfaceType"} 164 165 func (ec *executionContext) _MapStringInterfaceType(ctx context.Context, sel ast.SelectionSet, obj map[string]interface{}) graphql.Marshaler { 166 fields := graphql.CollectFields(ec.OperationContext, sel, mapStringInterfaceTypeImplementors) 167 out := graphql.NewFieldSet(fields) 168 var invalids uint32 169 for i, field := range fields { 170 switch field.Name { 171 case "__typename": 172 out.Values[i] = graphql.MarshalString("MapStringInterfaceType") 173 case "a": 174 175 out.Values[i] = ec._MapStringInterfaceType_a(ctx, field, obj) 176 177 case "b": 178 179 out.Values[i] = ec._MapStringInterfaceType_b(ctx, field, obj) 180 181 default: 182 panic("unknown field " + strconv.Quote(field.Name)) 183 } 184 } 185 out.Dispatch() 186 if invalids > 0 { 187 return graphql.Null 188 } 189 return out 190 } 191 192 // endregion **************************** object.gotpl **************************** 193 194 // region ***************************** type.gotpl ***************************** 195 196 func (ec *executionContext) unmarshalOMapStringInterfaceInput2map(ctx context.Context, v interface{}) (map[string]interface{}, error) { 197 if v == nil { 198 return nil, nil 199 } 200 return v.(map[string]interface{}), nil 201 } 202 203 func (ec *executionContext) marshalOMapStringInterfaceType2map(ctx context.Context, sel ast.SelectionSet, v map[string]interface{}) graphql.Marshaler { 204 if v == nil { 205 return graphql.Null 206 } 207 return ec._MapStringInterfaceType(ctx, sel, v) 208 } 209 210 func (ec *executionContext) unmarshalONestedMapInput2ᚖgithubᚗcomᚋmstephanoᚋgqlgenᚑschemagenᚋcodegenᚋtestserverᚋfollowschemaᚐNestedMapInput(ctx context.Context, v interface{}) (*NestedMapInput, error) { 211 if v == nil { 212 return nil, nil 213 } 214 res, err := ec.unmarshalInputNestedMapInput(ctx, v) 215 return &res, graphql.ErrorOnPath(ctx, err) 216 } 217 218 // endregion ***************************** type.gotpl *****************************