github.com/geneva/gqlgen@v0.17.7-0.20230801155730-7b9317164836/codegen/testserver/followschema/maps.generated.go (about)

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