github.com/operandinc/gqlgen@v0.16.1/codegen/testserver/followschema/maps.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) _MapStringInterfaceType_a(ctx context.Context, field graphql.CollectedField, obj map[string]interface{}) (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:     "MapStringInterfaceType",
    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  		switch v := obj["a"].(type) {
    47  		case *string:
    48  			return v, nil
    49  		case string:
    50  			return &v, nil
    51  		case nil:
    52  			return (*string)(nil), nil
    53  		default:
    54  			return nil, fmt.Errorf("unexpected type %T for field %s", v, "a")
    55  		}
    56  	})
    57  
    58  	if resTmp == nil {
    59  		return graphql.Null
    60  	}
    61  	res := resTmp.(*string)
    62  	fc.Result = res
    63  	return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
    64  }
    65  
    66  func (ec *executionContext) _MapStringInterfaceType_b(ctx context.Context, field graphql.CollectedField, obj map[string]interface{}) (ret graphql.Marshaler) {
    67  	defer func() {
    68  		if r := recover(); r != nil {
    69  			ec.Error(ctx, ec.Recover(ctx, r))
    70  			ret = graphql.Null
    71  		}
    72  	}()
    73  	fc := &graphql.FieldContext{
    74  		Object:     "MapStringInterfaceType",
    75  		Field:      field,
    76  		Args:       nil,
    77  		IsMethod:   false,
    78  		IsResolver: false,
    79  	}
    80  
    81  	ctx = graphql.WithFieldContext(ctx, fc)
    82  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    83  		ctx = rctx // use context from middleware stack in children
    84  		switch v := obj["b"].(type) {
    85  		case *int:
    86  			return v, nil
    87  		case int:
    88  			return &v, nil
    89  		case nil:
    90  			return (*int)(nil), nil
    91  		default:
    92  			return nil, fmt.Errorf("unexpected type %T for field %s", v, "b")
    93  		}
    94  	})
    95  
    96  	if resTmp == nil {
    97  		return graphql.Null
    98  	}
    99  	res := resTmp.(*int)
   100  	fc.Result = res
   101  	return ec.marshalOInt2ᚖint(ctx, field.Selections, res)
   102  }
   103  
   104  // endregion **************************** field.gotpl *****************************
   105  
   106  // region    **************************** input.gotpl *****************************
   107  
   108  func (ec *executionContext) unmarshalInputNestedMapInput(ctx context.Context, obj interface{}) (NestedMapInput, error) {
   109  	var it NestedMapInput
   110  	asMap := map[string]interface{}{}
   111  	for k, v := range obj.(map[string]interface{}) {
   112  		asMap[k] = v
   113  	}
   114  
   115  	for k, v := range asMap {
   116  		switch k {
   117  		case "map":
   118  			var err error
   119  
   120  			ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("map"))
   121  			it.Map, err = ec.unmarshalOMapStringInterfaceInput2map(ctx, v)
   122  			if err != nil {
   123  				return it, err
   124  			}
   125  		}
   126  	}
   127  
   128  	return it, nil
   129  }
   130  
   131  // endregion **************************** input.gotpl *****************************
   132  
   133  // region    ************************** interface.gotpl ***************************
   134  
   135  // endregion ************************** interface.gotpl ***************************
   136  
   137  // region    **************************** object.gotpl ****************************
   138  
   139  var mapStringInterfaceTypeImplementors = []string{"MapStringInterfaceType"}
   140  
   141  func (ec *executionContext) _MapStringInterfaceType(ctx context.Context, sel ast.SelectionSet, obj map[string]interface{}) graphql.Marshaler {
   142  	fields := graphql.CollectFields(ec.OperationContext, sel, mapStringInterfaceTypeImplementors)
   143  	out := graphql.NewFieldSet(fields)
   144  	var invalids uint32
   145  	for i, field := range fields {
   146  		switch field.Name {
   147  		case "__typename":
   148  			out.Values[i] = graphql.MarshalString("MapStringInterfaceType")
   149  		case "a":
   150  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   151  				return ec._MapStringInterfaceType_a(ctx, field, obj)
   152  			}
   153  
   154  			out.Values[i] = innerFunc(ctx)
   155  
   156  		case "b":
   157  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   158  				return ec._MapStringInterfaceType_b(ctx, field, obj)
   159  			}
   160  
   161  			out.Values[i] = innerFunc(ctx)
   162  
   163  		default:
   164  			panic("unknown field " + strconv.Quote(field.Name))
   165  		}
   166  	}
   167  	out.Dispatch()
   168  	if invalids > 0 {
   169  		return graphql.Null
   170  	}
   171  	return out
   172  }
   173  
   174  // endregion **************************** object.gotpl ****************************
   175  
   176  // region    ***************************** type.gotpl *****************************
   177  
   178  func (ec *executionContext) unmarshalOMapStringInterfaceInput2map(ctx context.Context, v interface{}) (map[string]interface{}, error) {
   179  	if v == nil {
   180  		return nil, nil
   181  	}
   182  	return v.(map[string]interface{}), nil
   183  }
   184  
   185  func (ec *executionContext) marshalOMapStringInterfaceType2map(ctx context.Context, sel ast.SelectionSet, v map[string]interface{}) graphql.Marshaler {
   186  	if v == nil {
   187  		return graphql.Null
   188  	}
   189  	return ec._MapStringInterfaceType(ctx, sel, v)
   190  }
   191  
   192  func (ec *executionContext) unmarshalONestedMapInput2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐNestedMapInput(ctx context.Context, v interface{}) (*NestedMapInput, error) {
   193  	if v == nil {
   194  		return nil, nil
   195  	}
   196  	res, err := ec.unmarshalInputNestedMapInput(ctx, v)
   197  	return &res, graphql.ErrorOnPath(ctx, err)
   198  }
   199  
   200  // endregion ***************************** type.gotpl *****************************