github.com/99designs/gqlgen@v0.17.45/codegen/testserver/followschema/wrapped_type.generated.go (about)

     1  // Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
     2  
     3  package followschema
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"strconv"
     9  	"sync/atomic"
    10  
    11  	"github.com/99designs/gqlgen/codegen/testserver/followschema/otherpkg"
    12  	"github.com/99designs/gqlgen/graphql"
    13  	"github.com/vektah/gqlparser/v2/ast"
    14  )
    15  
    16  // region    ************************** generated!.gotpl **************************
    17  
    18  type WrappedMapResolver interface {
    19  	Get(ctx context.Context, obj WrappedMap, key string) (string, error)
    20  }
    21  type WrappedSliceResolver interface {
    22  	Get(ctx context.Context, obj WrappedSlice, idx int) (string, error)
    23  }
    24  
    25  // endregion ************************** generated!.gotpl **************************
    26  
    27  // region    ***************************** args.gotpl *****************************
    28  
    29  func (ec *executionContext) field_WrappedMap_get_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
    30  	var err error
    31  	args := map[string]interface{}{}
    32  	var arg0 string
    33  	if tmp, ok := rawArgs["key"]; ok {
    34  		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("key"))
    35  		arg0, err = ec.unmarshalNString2string(ctx, tmp)
    36  		if err != nil {
    37  			return nil, err
    38  		}
    39  	}
    40  	args["key"] = arg0
    41  	return args, nil
    42  }
    43  
    44  func (ec *executionContext) field_WrappedSlice_get_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
    45  	var err error
    46  	args := map[string]interface{}{}
    47  	var arg0 int
    48  	if tmp, ok := rawArgs["idx"]; ok {
    49  		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("idx"))
    50  		arg0, err = ec.unmarshalNInt2int(ctx, tmp)
    51  		if err != nil {
    52  			return nil, err
    53  		}
    54  	}
    55  	args["idx"] = arg0
    56  	return args, nil
    57  }
    58  
    59  // endregion ***************************** args.gotpl *****************************
    60  
    61  // region    ************************** directives.gotpl **************************
    62  
    63  // endregion ************************** directives.gotpl **************************
    64  
    65  // region    **************************** field.gotpl *****************************
    66  
    67  func (ec *executionContext) _WrappedMap_get(ctx context.Context, field graphql.CollectedField, obj WrappedMap) (ret graphql.Marshaler) {
    68  	fc, err := ec.fieldContext_WrappedMap_get(ctx, field)
    69  	if err != nil {
    70  		return graphql.Null
    71  	}
    72  	ctx = graphql.WithFieldContext(ctx, fc)
    73  	defer func() {
    74  		if r := recover(); r != nil {
    75  			ec.Error(ctx, ec.Recover(ctx, r))
    76  			ret = graphql.Null
    77  		}
    78  	}()
    79  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    80  		ctx = rctx // use context from middleware stack in children
    81  		return ec.resolvers.WrappedMap().Get(rctx, obj, fc.Args["key"].(string))
    82  	})
    83  
    84  	if resTmp == nil {
    85  		if !graphql.HasFieldError(ctx, fc) {
    86  			ec.Errorf(ctx, "must not be null")
    87  		}
    88  		return graphql.Null
    89  	}
    90  	res := resTmp.(string)
    91  	fc.Result = res
    92  	return ec.marshalNString2string(ctx, field.Selections, res)
    93  }
    94  
    95  func (ec *executionContext) fieldContext_WrappedMap_get(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
    96  	fc = &graphql.FieldContext{
    97  		Object:     "WrappedMap",
    98  		Field:      field,
    99  		IsMethod:   true,
   100  		IsResolver: true,
   101  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   102  			return nil, errors.New("field of type String does not have child fields")
   103  		},
   104  	}
   105  	defer func() {
   106  		if r := recover(); r != nil {
   107  			err = ec.Recover(ctx, r)
   108  			ec.Error(ctx, err)
   109  		}
   110  	}()
   111  	ctx = graphql.WithFieldContext(ctx, fc)
   112  	if fc.Args, err = ec.field_WrappedMap_get_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
   113  		ec.Error(ctx, err)
   114  		return fc, err
   115  	}
   116  	return fc, nil
   117  }
   118  
   119  func (ec *executionContext) _WrappedSlice_get(ctx context.Context, field graphql.CollectedField, obj WrappedSlice) (ret graphql.Marshaler) {
   120  	fc, err := ec.fieldContext_WrappedSlice_get(ctx, field)
   121  	if err != nil {
   122  		return graphql.Null
   123  	}
   124  	ctx = graphql.WithFieldContext(ctx, fc)
   125  	defer func() {
   126  		if r := recover(); r != nil {
   127  			ec.Error(ctx, ec.Recover(ctx, r))
   128  			ret = graphql.Null
   129  		}
   130  	}()
   131  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   132  		ctx = rctx // use context from middleware stack in children
   133  		return ec.resolvers.WrappedSlice().Get(rctx, obj, fc.Args["idx"].(int))
   134  	})
   135  
   136  	if resTmp == nil {
   137  		if !graphql.HasFieldError(ctx, fc) {
   138  			ec.Errorf(ctx, "must not be null")
   139  		}
   140  		return graphql.Null
   141  	}
   142  	res := resTmp.(string)
   143  	fc.Result = res
   144  	return ec.marshalNString2string(ctx, field.Selections, res)
   145  }
   146  
   147  func (ec *executionContext) fieldContext_WrappedSlice_get(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   148  	fc = &graphql.FieldContext{
   149  		Object:     "WrappedSlice",
   150  		Field:      field,
   151  		IsMethod:   true,
   152  		IsResolver: true,
   153  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   154  			return nil, errors.New("field of type String does not have child fields")
   155  		},
   156  	}
   157  	defer func() {
   158  		if r := recover(); r != nil {
   159  			err = ec.Recover(ctx, r)
   160  			ec.Error(ctx, err)
   161  		}
   162  	}()
   163  	ctx = graphql.WithFieldContext(ctx, fc)
   164  	if fc.Args, err = ec.field_WrappedSlice_get_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
   165  		ec.Error(ctx, err)
   166  		return fc, err
   167  	}
   168  	return fc, nil
   169  }
   170  
   171  func (ec *executionContext) _WrappedStruct_name(ctx context.Context, field graphql.CollectedField, obj *WrappedStruct) (ret graphql.Marshaler) {
   172  	fc, err := ec.fieldContext_WrappedStruct_name(ctx, field)
   173  	if err != nil {
   174  		return graphql.Null
   175  	}
   176  	ctx = graphql.WithFieldContext(ctx, fc)
   177  	defer func() {
   178  		if r := recover(); r != nil {
   179  			ec.Error(ctx, ec.Recover(ctx, r))
   180  			ret = graphql.Null
   181  		}
   182  	}()
   183  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   184  		ctx = rctx // use context from middleware stack in children
   185  		return obj.Name, nil
   186  	})
   187  
   188  	if resTmp == nil {
   189  		if !graphql.HasFieldError(ctx, fc) {
   190  			ec.Errorf(ctx, "must not be null")
   191  		}
   192  		return graphql.Null
   193  	}
   194  	res := resTmp.(otherpkg.Scalar)
   195  	fc.Result = res
   196  	return ec.marshalNWrappedScalar2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx, field.Selections, res)
   197  }
   198  
   199  func (ec *executionContext) fieldContext_WrappedStruct_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   200  	fc = &graphql.FieldContext{
   201  		Object:     "WrappedStruct",
   202  		Field:      field,
   203  		IsMethod:   false,
   204  		IsResolver: false,
   205  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   206  			return nil, errors.New("field of type WrappedScalar does not have child fields")
   207  		},
   208  	}
   209  	return fc, nil
   210  }
   211  
   212  func (ec *executionContext) _WrappedStruct_desc(ctx context.Context, field graphql.CollectedField, obj *WrappedStruct) (ret graphql.Marshaler) {
   213  	fc, err := ec.fieldContext_WrappedStruct_desc(ctx, field)
   214  	if err != nil {
   215  		return graphql.Null
   216  	}
   217  	ctx = graphql.WithFieldContext(ctx, fc)
   218  	defer func() {
   219  		if r := recover(); r != nil {
   220  			ec.Error(ctx, ec.Recover(ctx, r))
   221  			ret = graphql.Null
   222  		}
   223  	}()
   224  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   225  		ctx = rctx // use context from middleware stack in children
   226  		return obj.Desc, nil
   227  	})
   228  
   229  	if resTmp == nil {
   230  		return graphql.Null
   231  	}
   232  	res := resTmp.(*otherpkg.Scalar)
   233  	fc.Result = res
   234  	return ec.marshalOWrappedScalar2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx, field.Selections, res)
   235  }
   236  
   237  func (ec *executionContext) fieldContext_WrappedStruct_desc(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   238  	fc = &graphql.FieldContext{
   239  		Object:     "WrappedStruct",
   240  		Field:      field,
   241  		IsMethod:   false,
   242  		IsResolver: false,
   243  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   244  			return nil, errors.New("field of type WrappedScalar does not have child fields")
   245  		},
   246  	}
   247  	return fc, nil
   248  }
   249  
   250  // endregion **************************** field.gotpl *****************************
   251  
   252  // region    **************************** input.gotpl *****************************
   253  
   254  // endregion **************************** input.gotpl *****************************
   255  
   256  // region    ************************** interface.gotpl ***************************
   257  
   258  // endregion ************************** interface.gotpl ***************************
   259  
   260  // region    **************************** object.gotpl ****************************
   261  
   262  var wrappedMapImplementors = []string{"WrappedMap"}
   263  
   264  func (ec *executionContext) _WrappedMap(ctx context.Context, sel ast.SelectionSet, obj WrappedMap) graphql.Marshaler {
   265  	fields := graphql.CollectFields(ec.OperationContext, sel, wrappedMapImplementors)
   266  
   267  	out := graphql.NewFieldSet(fields)
   268  	deferred := make(map[string]*graphql.FieldSet)
   269  	for i, field := range fields {
   270  		switch field.Name {
   271  		case "__typename":
   272  			out.Values[i] = graphql.MarshalString("WrappedMap")
   273  		case "get":
   274  			field := field
   275  
   276  			innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
   277  				defer func() {
   278  					if r := recover(); r != nil {
   279  						ec.Error(ctx, ec.Recover(ctx, r))
   280  					}
   281  				}()
   282  				res = ec._WrappedMap_get(ctx, field, obj)
   283  				if res == graphql.Null {
   284  					atomic.AddUint32(&fs.Invalids, 1)
   285  				}
   286  				return res
   287  			}
   288  
   289  			if field.Deferrable != nil {
   290  				dfs, ok := deferred[field.Deferrable.Label]
   291  				di := 0
   292  				if ok {
   293  					dfs.AddField(field)
   294  					di = len(dfs.Values) - 1
   295  				} else {
   296  					dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
   297  					deferred[field.Deferrable.Label] = dfs
   298  				}
   299  				dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
   300  					return innerFunc(ctx, dfs)
   301  				})
   302  
   303  				// don't run the out.Concurrently() call below
   304  				out.Values[i] = graphql.Null
   305  				continue
   306  			}
   307  
   308  			out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
   309  		default:
   310  			panic("unknown field " + strconv.Quote(field.Name))
   311  		}
   312  	}
   313  	out.Dispatch(ctx)
   314  	if out.Invalids > 0 {
   315  		return graphql.Null
   316  	}
   317  
   318  	atomic.AddInt32(&ec.deferred, int32(len(deferred)))
   319  
   320  	for label, dfs := range deferred {
   321  		ec.processDeferredGroup(graphql.DeferredGroup{
   322  			Label:    label,
   323  			Path:     graphql.GetPath(ctx),
   324  			FieldSet: dfs,
   325  			Context:  ctx,
   326  		})
   327  	}
   328  
   329  	return out
   330  }
   331  
   332  var wrappedSliceImplementors = []string{"WrappedSlice"}
   333  
   334  func (ec *executionContext) _WrappedSlice(ctx context.Context, sel ast.SelectionSet, obj WrappedSlice) graphql.Marshaler {
   335  	fields := graphql.CollectFields(ec.OperationContext, sel, wrappedSliceImplementors)
   336  
   337  	out := graphql.NewFieldSet(fields)
   338  	deferred := make(map[string]*graphql.FieldSet)
   339  	for i, field := range fields {
   340  		switch field.Name {
   341  		case "__typename":
   342  			out.Values[i] = graphql.MarshalString("WrappedSlice")
   343  		case "get":
   344  			field := field
   345  
   346  			innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
   347  				defer func() {
   348  					if r := recover(); r != nil {
   349  						ec.Error(ctx, ec.Recover(ctx, r))
   350  					}
   351  				}()
   352  				res = ec._WrappedSlice_get(ctx, field, obj)
   353  				if res == graphql.Null {
   354  					atomic.AddUint32(&fs.Invalids, 1)
   355  				}
   356  				return res
   357  			}
   358  
   359  			if field.Deferrable != nil {
   360  				dfs, ok := deferred[field.Deferrable.Label]
   361  				di := 0
   362  				if ok {
   363  					dfs.AddField(field)
   364  					di = len(dfs.Values) - 1
   365  				} else {
   366  					dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
   367  					deferred[field.Deferrable.Label] = dfs
   368  				}
   369  				dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
   370  					return innerFunc(ctx, dfs)
   371  				})
   372  
   373  				// don't run the out.Concurrently() call below
   374  				out.Values[i] = graphql.Null
   375  				continue
   376  			}
   377  
   378  			out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
   379  		default:
   380  			panic("unknown field " + strconv.Quote(field.Name))
   381  		}
   382  	}
   383  	out.Dispatch(ctx)
   384  	if out.Invalids > 0 {
   385  		return graphql.Null
   386  	}
   387  
   388  	atomic.AddInt32(&ec.deferred, int32(len(deferred)))
   389  
   390  	for label, dfs := range deferred {
   391  		ec.processDeferredGroup(graphql.DeferredGroup{
   392  			Label:    label,
   393  			Path:     graphql.GetPath(ctx),
   394  			FieldSet: dfs,
   395  			Context:  ctx,
   396  		})
   397  	}
   398  
   399  	return out
   400  }
   401  
   402  var wrappedStructImplementors = []string{"WrappedStruct"}
   403  
   404  func (ec *executionContext) _WrappedStruct(ctx context.Context, sel ast.SelectionSet, obj *WrappedStruct) graphql.Marshaler {
   405  	fields := graphql.CollectFields(ec.OperationContext, sel, wrappedStructImplementors)
   406  
   407  	out := graphql.NewFieldSet(fields)
   408  	deferred := make(map[string]*graphql.FieldSet)
   409  	for i, field := range fields {
   410  		switch field.Name {
   411  		case "__typename":
   412  			out.Values[i] = graphql.MarshalString("WrappedStruct")
   413  		case "name":
   414  			out.Values[i] = ec._WrappedStruct_name(ctx, field, obj)
   415  			if out.Values[i] == graphql.Null {
   416  				out.Invalids++
   417  			}
   418  		case "desc":
   419  			out.Values[i] = ec._WrappedStruct_desc(ctx, field, obj)
   420  		default:
   421  			panic("unknown field " + strconv.Quote(field.Name))
   422  		}
   423  	}
   424  	out.Dispatch(ctx)
   425  	if out.Invalids > 0 {
   426  		return graphql.Null
   427  	}
   428  
   429  	atomic.AddInt32(&ec.deferred, int32(len(deferred)))
   430  
   431  	for label, dfs := range deferred {
   432  		ec.processDeferredGroup(graphql.DeferredGroup{
   433  			Label:    label,
   434  			Path:     graphql.GetPath(ctx),
   435  			FieldSet: dfs,
   436  			Context:  ctx,
   437  		})
   438  	}
   439  
   440  	return out
   441  }
   442  
   443  // endregion **************************** object.gotpl ****************************
   444  
   445  // region    ***************************** type.gotpl *****************************
   446  
   447  func (ec *executionContext) marshalNWrappedMap2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐWrappedMap(ctx context.Context, sel ast.SelectionSet, v WrappedMap) graphql.Marshaler {
   448  	if v == nil {
   449  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   450  			ec.Errorf(ctx, "the requested element is null which the schema does not allow")
   451  		}
   452  		return graphql.Null
   453  	}
   454  	return ec._WrappedMap(ctx, sel, v)
   455  }
   456  
   457  func (ec *executionContext) unmarshalNWrappedScalar2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx context.Context, v interface{}) (otherpkg.Scalar, error) {
   458  	tmp, err := graphql.UnmarshalString(v)
   459  	res := otherpkg.Scalar(tmp)
   460  	return res, graphql.ErrorOnPath(ctx, err)
   461  }
   462  
   463  func (ec *executionContext) marshalNWrappedScalar2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx context.Context, sel ast.SelectionSet, v otherpkg.Scalar) graphql.Marshaler {
   464  	res := graphql.MarshalString(string(v))
   465  	if res == graphql.Null {
   466  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   467  			ec.Errorf(ctx, "the requested element is null which the schema does not allow")
   468  		}
   469  	}
   470  	return res
   471  }
   472  
   473  func (ec *executionContext) marshalNWrappedSlice2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐWrappedSlice(ctx context.Context, sel ast.SelectionSet, v WrappedSlice) graphql.Marshaler {
   474  	if v == nil {
   475  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   476  			ec.Errorf(ctx, "the requested element is null which the schema does not allow")
   477  		}
   478  		return graphql.Null
   479  	}
   480  	return ec._WrappedSlice(ctx, sel, v)
   481  }
   482  
   483  func (ec *executionContext) marshalNWrappedStruct2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐWrappedStruct(ctx context.Context, sel ast.SelectionSet, v WrappedStruct) graphql.Marshaler {
   484  	return ec._WrappedStruct(ctx, sel, &v)
   485  }
   486  
   487  func (ec *executionContext) marshalNWrappedStruct2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐWrappedStruct(ctx context.Context, sel ast.SelectionSet, v *WrappedStruct) graphql.Marshaler {
   488  	if v == nil {
   489  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   490  			ec.Errorf(ctx, "the requested element is null which the schema does not allow")
   491  		}
   492  		return graphql.Null
   493  	}
   494  	return ec._WrappedStruct(ctx, sel, v)
   495  }
   496  
   497  func (ec *executionContext) unmarshalOWrappedScalar2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx context.Context, v interface{}) (*otherpkg.Scalar, error) {
   498  	if v == nil {
   499  		return nil, nil
   500  	}
   501  	tmp, err := graphql.UnmarshalString(v)
   502  	res := otherpkg.Scalar(tmp)
   503  	return &res, graphql.ErrorOnPath(ctx, err)
   504  }
   505  
   506  func (ec *executionContext) marshalOWrappedScalar2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚋotherpkgᚐScalar(ctx context.Context, sel ast.SelectionSet, v *otherpkg.Scalar) graphql.Marshaler {
   507  	if v == nil {
   508  		return graphql.Null
   509  	}
   510  	res := graphql.MarshalString(string(*v))
   511  	return res
   512  }
   513  
   514  // endregion ***************************** type.gotpl *****************************