github.com/operandinc/gqlgen@v0.16.1/codegen/testserver/followschema/wrapped_type.generated.go (about)

     1  // Code generated by github.com/operandinc/gqlgen, DO NOT EDIT.
     2  
     3  package followschema
     4  
     5  import (
     6  	"context"
     7  	"strconv"
     8  	"sync/atomic"
     9  
    10  	"github.com/operandinc/gqlgen/codegen/testserver/followschema/otherpkg"
    11  	"github.com/operandinc/gqlgen/graphql"
    12  	"github.com/vektah/gqlparser/v2/ast"
    13  )
    14  
    15  // region    ************************** generated!.gotpl **************************
    16  
    17  type WrappedMapResolver interface {
    18  	Get(ctx context.Context, obj WrappedMap, key string) (string, error)
    19  }
    20  type WrappedSliceResolver interface {
    21  	Get(ctx context.Context, obj WrappedSlice, idx int) (string, error)
    22  }
    23  
    24  // endregion ************************** generated!.gotpl **************************
    25  
    26  // region    ***************************** args.gotpl *****************************
    27  
    28  func (ec *executionContext) field_WrappedMap_get_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
    29  	var err error
    30  	args := map[string]interface{}{}
    31  	var arg0 string
    32  	if tmp, ok := rawArgs["key"]; ok {
    33  		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("key"))
    34  		arg0, err = ec.unmarshalNString2string(ctx, tmp)
    35  		if err != nil {
    36  			return nil, err
    37  		}
    38  	}
    39  	args["key"] = arg0
    40  	return args, nil
    41  }
    42  
    43  func (ec *executionContext) field_WrappedSlice_get_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
    44  	var err error
    45  	args := map[string]interface{}{}
    46  	var arg0 int
    47  	if tmp, ok := rawArgs["idx"]; ok {
    48  		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idx"))
    49  		arg0, err = ec.unmarshalNInt2int(ctx, tmp)
    50  		if err != nil {
    51  			return nil, err
    52  		}
    53  	}
    54  	args["idx"] = arg0
    55  	return args, nil
    56  }
    57  
    58  // endregion ***************************** args.gotpl *****************************
    59  
    60  // region    ************************** directives.gotpl **************************
    61  
    62  // endregion ************************** directives.gotpl **************************
    63  
    64  // region    **************************** field.gotpl *****************************
    65  
    66  func (ec *executionContext) _WrappedMap_get(ctx context.Context, field graphql.CollectedField, obj WrappedMap) (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:     "WrappedMap",
    75  		Field:      field,
    76  		Args:       nil,
    77  		IsMethod:   true,
    78  		IsResolver: true,
    79  	}
    80  
    81  	ctx = graphql.WithFieldContext(ctx, fc)
    82  	rawArgs := field.ArgumentMap(ec.Variables)
    83  	args, err := ec.field_WrappedMap_get_args(ctx, rawArgs)
    84  	if err != nil {
    85  		ec.Error(ctx, err)
    86  		return graphql.Null
    87  	}
    88  	fc.Args = args
    89  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    90  		ctx = rctx // use context from middleware stack in children
    91  		return ec.resolvers.WrappedMap().Get(rctx, obj, args["key"].(string))
    92  	})
    93  
    94  	if resTmp == nil {
    95  		if !graphql.HasFieldError(ctx, fc) {
    96  			ec.Errorf(ctx, "must not be null")
    97  		}
    98  		return graphql.Null
    99  	}
   100  	res := resTmp.(string)
   101  	fc.Result = res
   102  	return ec.marshalNString2string(ctx, field.Selections, res)
   103  }
   104  
   105  func (ec *executionContext) _WrappedSlice_get(ctx context.Context, field graphql.CollectedField, obj WrappedSlice) (ret graphql.Marshaler) {
   106  	defer func() {
   107  		if r := recover(); r != nil {
   108  			ec.Error(ctx, ec.Recover(ctx, r))
   109  			ret = graphql.Null
   110  		}
   111  	}()
   112  	fc := &graphql.FieldContext{
   113  		Object:     "WrappedSlice",
   114  		Field:      field,
   115  		Args:       nil,
   116  		IsMethod:   true,
   117  		IsResolver: true,
   118  	}
   119  
   120  	ctx = graphql.WithFieldContext(ctx, fc)
   121  	rawArgs := field.ArgumentMap(ec.Variables)
   122  	args, err := ec.field_WrappedSlice_get_args(ctx, rawArgs)
   123  	if err != nil {
   124  		ec.Error(ctx, err)
   125  		return graphql.Null
   126  	}
   127  	fc.Args = args
   128  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   129  		ctx = rctx // use context from middleware stack in children
   130  		return ec.resolvers.WrappedSlice().Get(rctx, obj, args["idx"].(int))
   131  	})
   132  
   133  	if resTmp == nil {
   134  		if !graphql.HasFieldError(ctx, fc) {
   135  			ec.Errorf(ctx, "must not be null")
   136  		}
   137  		return graphql.Null
   138  	}
   139  	res := resTmp.(string)
   140  	fc.Result = res
   141  	return ec.marshalNString2string(ctx, field.Selections, res)
   142  }
   143  
   144  func (ec *executionContext) _WrappedStruct_name(ctx context.Context, field graphql.CollectedField, obj *WrappedStruct) (ret graphql.Marshaler) {
   145  	defer func() {
   146  		if r := recover(); r != nil {
   147  			ec.Error(ctx, ec.Recover(ctx, r))
   148  			ret = graphql.Null
   149  		}
   150  	}()
   151  	fc := &graphql.FieldContext{
   152  		Object:     "WrappedStruct",
   153  		Field:      field,
   154  		Args:       nil,
   155  		IsMethod:   false,
   156  		IsResolver: false,
   157  	}
   158  
   159  	ctx = graphql.WithFieldContext(ctx, fc)
   160  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   161  		ctx = rctx // use context from middleware stack in children
   162  		return obj.Name, nil
   163  	})
   164  
   165  	if resTmp == nil {
   166  		if !graphql.HasFieldError(ctx, fc) {
   167  			ec.Errorf(ctx, "must not be null")
   168  		}
   169  		return graphql.Null
   170  	}
   171  	res := resTmp.(otherpkg.Scalar)
   172  	fc.Result = res
   173  	return ec.marshalNWrappedScalar2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx, field.Selections, res)
   174  }
   175  
   176  func (ec *executionContext) _WrappedStruct_desc(ctx context.Context, field graphql.CollectedField, obj *WrappedStruct) (ret graphql.Marshaler) {
   177  	defer func() {
   178  		if r := recover(); r != nil {
   179  			ec.Error(ctx, ec.Recover(ctx, r))
   180  			ret = graphql.Null
   181  		}
   182  	}()
   183  	fc := &graphql.FieldContext{
   184  		Object:     "WrappedStruct",
   185  		Field:      field,
   186  		Args:       nil,
   187  		IsMethod:   false,
   188  		IsResolver: false,
   189  	}
   190  
   191  	ctx = graphql.WithFieldContext(ctx, fc)
   192  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   193  		ctx = rctx // use context from middleware stack in children
   194  		return obj.Desc, nil
   195  	})
   196  
   197  	if resTmp == nil {
   198  		return graphql.Null
   199  	}
   200  	res := resTmp.(*otherpkg.Scalar)
   201  	fc.Result = res
   202  	return ec.marshalOWrappedScalar2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx, field.Selections, res)
   203  }
   204  
   205  // endregion **************************** field.gotpl *****************************
   206  
   207  // region    **************************** input.gotpl *****************************
   208  
   209  // endregion **************************** input.gotpl *****************************
   210  
   211  // region    ************************** interface.gotpl ***************************
   212  
   213  // endregion ************************** interface.gotpl ***************************
   214  
   215  // region    **************************** object.gotpl ****************************
   216  
   217  var wrappedMapImplementors = []string{"WrappedMap"}
   218  
   219  func (ec *executionContext) _WrappedMap(ctx context.Context, sel ast.SelectionSet, obj WrappedMap) graphql.Marshaler {
   220  	fields := graphql.CollectFields(ec.OperationContext, sel, wrappedMapImplementors)
   221  	out := graphql.NewFieldSet(fields)
   222  	var invalids uint32
   223  	for i, field := range fields {
   224  		switch field.Name {
   225  		case "__typename":
   226  			out.Values[i] = graphql.MarshalString("WrappedMap")
   227  		case "get":
   228  			field := field
   229  
   230  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   231  				defer func() {
   232  					if r := recover(); r != nil {
   233  						ec.Error(ctx, ec.Recover(ctx, r))
   234  					}
   235  				}()
   236  				res = ec._WrappedMap_get(ctx, field, obj)
   237  				if res == graphql.Null {
   238  					atomic.AddUint32(&invalids, 1)
   239  				}
   240  				return res
   241  			}
   242  
   243  			out.Concurrently(i, func() graphql.Marshaler {
   244  				return innerFunc(ctx)
   245  
   246  			})
   247  		default:
   248  			panic("unknown field " + strconv.Quote(field.Name))
   249  		}
   250  	}
   251  	out.Dispatch()
   252  	if invalids > 0 {
   253  		return graphql.Null
   254  	}
   255  	return out
   256  }
   257  
   258  var wrappedSliceImplementors = []string{"WrappedSlice"}
   259  
   260  func (ec *executionContext) _WrappedSlice(ctx context.Context, sel ast.SelectionSet, obj WrappedSlice) graphql.Marshaler {
   261  	fields := graphql.CollectFields(ec.OperationContext, sel, wrappedSliceImplementors)
   262  	out := graphql.NewFieldSet(fields)
   263  	var invalids uint32
   264  	for i, field := range fields {
   265  		switch field.Name {
   266  		case "__typename":
   267  			out.Values[i] = graphql.MarshalString("WrappedSlice")
   268  		case "get":
   269  			field := field
   270  
   271  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   272  				defer func() {
   273  					if r := recover(); r != nil {
   274  						ec.Error(ctx, ec.Recover(ctx, r))
   275  					}
   276  				}()
   277  				res = ec._WrappedSlice_get(ctx, field, obj)
   278  				if res == graphql.Null {
   279  					atomic.AddUint32(&invalids, 1)
   280  				}
   281  				return res
   282  			}
   283  
   284  			out.Concurrently(i, func() graphql.Marshaler {
   285  				return innerFunc(ctx)
   286  
   287  			})
   288  		default:
   289  			panic("unknown field " + strconv.Quote(field.Name))
   290  		}
   291  	}
   292  	out.Dispatch()
   293  	if invalids > 0 {
   294  		return graphql.Null
   295  	}
   296  	return out
   297  }
   298  
   299  var wrappedStructImplementors = []string{"WrappedStruct"}
   300  
   301  func (ec *executionContext) _WrappedStruct(ctx context.Context, sel ast.SelectionSet, obj *WrappedStruct) graphql.Marshaler {
   302  	fields := graphql.CollectFields(ec.OperationContext, sel, wrappedStructImplementors)
   303  	out := graphql.NewFieldSet(fields)
   304  	var invalids uint32
   305  	for i, field := range fields {
   306  		switch field.Name {
   307  		case "__typename":
   308  			out.Values[i] = graphql.MarshalString("WrappedStruct")
   309  		case "name":
   310  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   311  				return ec._WrappedStruct_name(ctx, field, obj)
   312  			}
   313  
   314  			out.Values[i] = innerFunc(ctx)
   315  
   316  			if out.Values[i] == graphql.Null {
   317  				invalids++
   318  			}
   319  		case "desc":
   320  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   321  				return ec._WrappedStruct_desc(ctx, field, obj)
   322  			}
   323  
   324  			out.Values[i] = innerFunc(ctx)
   325  
   326  		default:
   327  			panic("unknown field " + strconv.Quote(field.Name))
   328  		}
   329  	}
   330  	out.Dispatch()
   331  	if invalids > 0 {
   332  		return graphql.Null
   333  	}
   334  	return out
   335  }
   336  
   337  // endregion **************************** object.gotpl ****************************
   338  
   339  // region    ***************************** type.gotpl *****************************
   340  
   341  func (ec *executionContext) marshalNWrappedMap2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐWrappedMap(ctx context.Context, sel ast.SelectionSet, v WrappedMap) graphql.Marshaler {
   342  	if v == nil {
   343  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   344  			ec.Errorf(ctx, "must not be null")
   345  		}
   346  		return graphql.Null
   347  	}
   348  	return ec._WrappedMap(ctx, sel, v)
   349  }
   350  
   351  func (ec *executionContext) unmarshalNWrappedScalar2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx context.Context, v interface{}) (otherpkg.Scalar, error) {
   352  	tmp, err := graphql.UnmarshalString(v)
   353  	res := otherpkg.Scalar(tmp)
   354  	return res, graphql.ErrorOnPath(ctx, err)
   355  }
   356  
   357  func (ec *executionContext) marshalNWrappedScalar2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx context.Context, sel ast.SelectionSet, v otherpkg.Scalar) graphql.Marshaler {
   358  	res := graphql.MarshalString(string(v))
   359  	if res == graphql.Null {
   360  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   361  			ec.Errorf(ctx, "must not be null")
   362  		}
   363  	}
   364  	return res
   365  }
   366  
   367  func (ec *executionContext) marshalNWrappedSlice2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐWrappedSlice(ctx context.Context, sel ast.SelectionSet, v WrappedSlice) graphql.Marshaler {
   368  	if v == nil {
   369  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   370  			ec.Errorf(ctx, "must not be null")
   371  		}
   372  		return graphql.Null
   373  	}
   374  	return ec._WrappedSlice(ctx, sel, v)
   375  }
   376  
   377  func (ec *executionContext) marshalNWrappedStruct2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐWrappedStruct(ctx context.Context, sel ast.SelectionSet, v WrappedStruct) graphql.Marshaler {
   378  	return ec._WrappedStruct(ctx, sel, &v)
   379  }
   380  
   381  func (ec *executionContext) marshalNWrappedStruct2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐWrappedStruct(ctx context.Context, sel ast.SelectionSet, v *WrappedStruct) graphql.Marshaler {
   382  	if v == nil {
   383  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   384  			ec.Errorf(ctx, "must not be null")
   385  		}
   386  		return graphql.Null
   387  	}
   388  	return ec._WrappedStruct(ctx, sel, v)
   389  }
   390  
   391  func (ec *executionContext) unmarshalOWrappedScalar2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx context.Context, v interface{}) (*otherpkg.Scalar, error) {
   392  	if v == nil {
   393  		return nil, nil
   394  	}
   395  	tmp, err := graphql.UnmarshalString(v)
   396  	res := otherpkg.Scalar(tmp)
   397  	return &res, graphql.ErrorOnPath(ctx, err)
   398  }
   399  
   400  func (ec *executionContext) marshalOWrappedScalar2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx context.Context, sel ast.SelectionSet, v *otherpkg.Scalar) graphql.Marshaler {
   401  	if v == nil {
   402  		return graphql.Null
   403  	}
   404  	res := graphql.MarshalString(string(*v))
   405  	return res
   406  }
   407  
   408  // endregion ***************************** type.gotpl *****************************