github.com/luciferinlove/gqlgen@v0.17.16-bzc.1/codegen/testserver/followschema/primitive_objects.generated.go (about)

     1  // Code generated by github.com/luciferinlove/gqlgen, DO NOT EDIT.
     2  
     3  package followschema
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"strconv"
     9  	"sync"
    10  	"sync/atomic"
    11  
    12  	"github.com/luciferinlove/gqlgen/graphql"
    13  	"github.com/vektah/gqlparser/v2/ast"
    14  )
    15  
    16  // region    ************************** generated!.gotpl **************************
    17  
    18  type PrimitiveResolver interface {
    19  	Value(ctx context.Context, obj *Primitive) (int, error)
    20  }
    21  type PrimitiveStringResolver interface {
    22  	Value(ctx context.Context, obj *PrimitiveString) (string, error)
    23  
    24  	Len(ctx context.Context, obj *PrimitiveString) (int, error)
    25  }
    26  
    27  // endregion ************************** generated!.gotpl **************************
    28  
    29  // region    ***************************** args.gotpl *****************************
    30  
    31  // endregion ***************************** args.gotpl *****************************
    32  
    33  // region    ************************** directives.gotpl **************************
    34  
    35  // endregion ************************** directives.gotpl **************************
    36  
    37  // region    **************************** field.gotpl *****************************
    38  
    39  func (ec *executionContext) _Primitive_value(ctx context.Context, field graphql.CollectedField, obj *Primitive) (ret graphql.Marshaler) {
    40  	fc, err := ec.fieldContext_Primitive_value(ctx, field)
    41  	if err != nil {
    42  		return graphql.Null
    43  	}
    44  	ctx = graphql.WithFieldContext(ctx, fc)
    45  	defer func() {
    46  		if r := recover(); r != nil {
    47  			ec.Error(ctx, ec.Recover(ctx, r))
    48  			ret = graphql.Null
    49  		}
    50  	}()
    51  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    52  		ctx = rctx // use context from middleware stack in children
    53  		return ec.resolvers.Primitive().Value(rctx, obj)
    54  	})
    55  
    56  	if resTmp == nil {
    57  		if !graphql.HasFieldError(ctx, fc) {
    58  			ec.Errorf(ctx, "must not be null")
    59  		}
    60  		return graphql.Null
    61  	}
    62  	res := resTmp.(int)
    63  	fc.Result = res
    64  	return ec.marshalNInt2int(ctx, field.Selections, res)
    65  }
    66  
    67  func (ec *executionContext) fieldContext_Primitive_value(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
    68  	fc = &graphql.FieldContext{
    69  		Object:     "Primitive",
    70  		Field:      field,
    71  		IsMethod:   true,
    72  		IsResolver: true,
    73  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
    74  			return nil, errors.New("field of type Int does not have child fields")
    75  		},
    76  	}
    77  	return fc, nil
    78  }
    79  
    80  func (ec *executionContext) _Primitive_squared(ctx context.Context, field graphql.CollectedField, obj *Primitive) (ret graphql.Marshaler) {
    81  	fc, err := ec.fieldContext_Primitive_squared(ctx, field)
    82  	if err != nil {
    83  		return graphql.Null
    84  	}
    85  	ctx = graphql.WithFieldContext(ctx, fc)
    86  	defer func() {
    87  		if r := recover(); r != nil {
    88  			ec.Error(ctx, ec.Recover(ctx, r))
    89  			ret = graphql.Null
    90  		}
    91  	}()
    92  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    93  		ctx = rctx // use context from middleware stack in children
    94  		return obj.Squared(), nil
    95  	})
    96  
    97  	if resTmp == nil {
    98  		if !graphql.HasFieldError(ctx, fc) {
    99  			ec.Errorf(ctx, "must not be null")
   100  		}
   101  		return graphql.Null
   102  	}
   103  	res := resTmp.(int)
   104  	fc.Result = res
   105  	return ec.marshalNInt2int(ctx, field.Selections, res)
   106  }
   107  
   108  func (ec *executionContext) fieldContext_Primitive_squared(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   109  	fc = &graphql.FieldContext{
   110  		Object:     "Primitive",
   111  		Field:      field,
   112  		IsMethod:   true,
   113  		IsResolver: false,
   114  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   115  			return nil, errors.New("field of type Int does not have child fields")
   116  		},
   117  	}
   118  	return fc, nil
   119  }
   120  
   121  func (ec *executionContext) _PrimitiveString_value(ctx context.Context, field graphql.CollectedField, obj *PrimitiveString) (ret graphql.Marshaler) {
   122  	fc, err := ec.fieldContext_PrimitiveString_value(ctx, field)
   123  	if err != nil {
   124  		return graphql.Null
   125  	}
   126  	ctx = graphql.WithFieldContext(ctx, fc)
   127  	defer func() {
   128  		if r := recover(); r != nil {
   129  			ec.Error(ctx, ec.Recover(ctx, r))
   130  			ret = graphql.Null
   131  		}
   132  	}()
   133  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   134  		ctx = rctx // use context from middleware stack in children
   135  		return ec.resolvers.PrimitiveString().Value(rctx, obj)
   136  	})
   137  
   138  	if resTmp == nil {
   139  		if !graphql.HasFieldError(ctx, fc) {
   140  			ec.Errorf(ctx, "must not be null")
   141  		}
   142  		return graphql.Null
   143  	}
   144  	res := resTmp.(string)
   145  	fc.Result = res
   146  	return ec.marshalNString2string(ctx, field.Selections, res)
   147  }
   148  
   149  func (ec *executionContext) fieldContext_PrimitiveString_value(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   150  	fc = &graphql.FieldContext{
   151  		Object:     "PrimitiveString",
   152  		Field:      field,
   153  		IsMethod:   true,
   154  		IsResolver: true,
   155  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   156  			return nil, errors.New("field of type String does not have child fields")
   157  		},
   158  	}
   159  	return fc, nil
   160  }
   161  
   162  func (ec *executionContext) _PrimitiveString_doubled(ctx context.Context, field graphql.CollectedField, obj *PrimitiveString) (ret graphql.Marshaler) {
   163  	fc, err := ec.fieldContext_PrimitiveString_doubled(ctx, field)
   164  	if err != nil {
   165  		return graphql.Null
   166  	}
   167  	ctx = graphql.WithFieldContext(ctx, fc)
   168  	defer func() {
   169  		if r := recover(); r != nil {
   170  			ec.Error(ctx, ec.Recover(ctx, r))
   171  			ret = graphql.Null
   172  		}
   173  	}()
   174  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   175  		ctx = rctx // use context from middleware stack in children
   176  		return obj.Doubled(), nil
   177  	})
   178  
   179  	if resTmp == nil {
   180  		if !graphql.HasFieldError(ctx, fc) {
   181  			ec.Errorf(ctx, "must not be null")
   182  		}
   183  		return graphql.Null
   184  	}
   185  	res := resTmp.(string)
   186  	fc.Result = res
   187  	return ec.marshalNString2string(ctx, field.Selections, res)
   188  }
   189  
   190  func (ec *executionContext) fieldContext_PrimitiveString_doubled(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   191  	fc = &graphql.FieldContext{
   192  		Object:     "PrimitiveString",
   193  		Field:      field,
   194  		IsMethod:   true,
   195  		IsResolver: false,
   196  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   197  			return nil, errors.New("field of type String does not have child fields")
   198  		},
   199  	}
   200  	return fc, nil
   201  }
   202  
   203  func (ec *executionContext) _PrimitiveString_len(ctx context.Context, field graphql.CollectedField, obj *PrimitiveString) (ret graphql.Marshaler) {
   204  	fc, err := ec.fieldContext_PrimitiveString_len(ctx, field)
   205  	if err != nil {
   206  		return graphql.Null
   207  	}
   208  	ctx = graphql.WithFieldContext(ctx, fc)
   209  	defer func() {
   210  		if r := recover(); r != nil {
   211  			ec.Error(ctx, ec.Recover(ctx, r))
   212  			ret = graphql.Null
   213  		}
   214  	}()
   215  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
   216  		ctx = rctx // use context from middleware stack in children
   217  		return ec.resolvers.PrimitiveString().Len(rctx, obj)
   218  	})
   219  
   220  	if resTmp == nil {
   221  		if !graphql.HasFieldError(ctx, fc) {
   222  			ec.Errorf(ctx, "must not be null")
   223  		}
   224  		return graphql.Null
   225  	}
   226  	res := resTmp.(int)
   227  	fc.Result = res
   228  	return ec.marshalNInt2int(ctx, field.Selections, res)
   229  }
   230  
   231  func (ec *executionContext) fieldContext_PrimitiveString_len(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   232  	fc = &graphql.FieldContext{
   233  		Object:     "PrimitiveString",
   234  		Field:      field,
   235  		IsMethod:   true,
   236  		IsResolver: true,
   237  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   238  			return nil, errors.New("field of type Int does not have child fields")
   239  		},
   240  	}
   241  	return fc, nil
   242  }
   243  
   244  // endregion **************************** field.gotpl *****************************
   245  
   246  // region    **************************** input.gotpl *****************************
   247  
   248  // endregion **************************** input.gotpl *****************************
   249  
   250  // region    ************************** interface.gotpl ***************************
   251  
   252  // endregion ************************** interface.gotpl ***************************
   253  
   254  // region    **************************** object.gotpl ****************************
   255  
   256  var primitiveImplementors = []string{"Primitive"}
   257  
   258  func (ec *executionContext) _Primitive(ctx context.Context, sel ast.SelectionSet, obj *Primitive) graphql.Marshaler {
   259  	fields := graphql.CollectFields(ec.OperationContext, sel, primitiveImplementors)
   260  	out := graphql.NewFieldSet(fields)
   261  	var invalids uint32
   262  	for i, field := range fields {
   263  		switch field.Name {
   264  		case "__typename":
   265  			out.Values[i] = graphql.MarshalString("Primitive")
   266  		case "value":
   267  			field := field
   268  
   269  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   270  				defer func() {
   271  					if r := recover(); r != nil {
   272  						ec.Error(ctx, ec.Recover(ctx, r))
   273  					}
   274  				}()
   275  				res = ec._Primitive_value(ctx, field, obj)
   276  				if res == graphql.Null {
   277  					atomic.AddUint32(&invalids, 1)
   278  				}
   279  				return res
   280  			}
   281  
   282  			out.Concurrently(i, func() graphql.Marshaler {
   283  				return innerFunc(ctx)
   284  
   285  			})
   286  		case "squared":
   287  
   288  			out.Values[i] = ec._Primitive_squared(ctx, field, obj)
   289  
   290  			if out.Values[i] == graphql.Null {
   291  				atomic.AddUint32(&invalids, 1)
   292  			}
   293  		default:
   294  			panic("unknown field " + strconv.Quote(field.Name))
   295  		}
   296  	}
   297  	out.Dispatch()
   298  	if invalids > 0 {
   299  		return graphql.Null
   300  	}
   301  	return out
   302  }
   303  
   304  var primitiveStringImplementors = []string{"PrimitiveString"}
   305  
   306  func (ec *executionContext) _PrimitiveString(ctx context.Context, sel ast.SelectionSet, obj *PrimitiveString) graphql.Marshaler {
   307  	fields := graphql.CollectFields(ec.OperationContext, sel, primitiveStringImplementors)
   308  	out := graphql.NewFieldSet(fields)
   309  	var invalids uint32
   310  	for i, field := range fields {
   311  		switch field.Name {
   312  		case "__typename":
   313  			out.Values[i] = graphql.MarshalString("PrimitiveString")
   314  		case "value":
   315  			field := field
   316  
   317  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   318  				defer func() {
   319  					if r := recover(); r != nil {
   320  						ec.Error(ctx, ec.Recover(ctx, r))
   321  					}
   322  				}()
   323  				res = ec._PrimitiveString_value(ctx, field, obj)
   324  				if res == graphql.Null {
   325  					atomic.AddUint32(&invalids, 1)
   326  				}
   327  				return res
   328  			}
   329  
   330  			out.Concurrently(i, func() graphql.Marshaler {
   331  				return innerFunc(ctx)
   332  
   333  			})
   334  		case "doubled":
   335  
   336  			out.Values[i] = ec._PrimitiveString_doubled(ctx, field, obj)
   337  
   338  			if out.Values[i] == graphql.Null {
   339  				atomic.AddUint32(&invalids, 1)
   340  			}
   341  		case "len":
   342  			field := field
   343  
   344  			innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
   345  				defer func() {
   346  					if r := recover(); r != nil {
   347  						ec.Error(ctx, ec.Recover(ctx, r))
   348  					}
   349  				}()
   350  				res = ec._PrimitiveString_len(ctx, field, obj)
   351  				if res == graphql.Null {
   352  					atomic.AddUint32(&invalids, 1)
   353  				}
   354  				return res
   355  			}
   356  
   357  			out.Concurrently(i, func() graphql.Marshaler {
   358  				return innerFunc(ctx)
   359  
   360  			})
   361  		default:
   362  			panic("unknown field " + strconv.Quote(field.Name))
   363  		}
   364  	}
   365  	out.Dispatch()
   366  	if invalids > 0 {
   367  		return graphql.Null
   368  	}
   369  	return out
   370  }
   371  
   372  // endregion **************************** object.gotpl ****************************
   373  
   374  // region    ***************************** type.gotpl *****************************
   375  
   376  func (ec *executionContext) marshalNPrimitive2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitive(ctx context.Context, sel ast.SelectionSet, v Primitive) graphql.Marshaler {
   377  	return ec._Primitive(ctx, sel, &v)
   378  }
   379  
   380  func (ec *executionContext) marshalNPrimitive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitiveᚄ(ctx context.Context, sel ast.SelectionSet, v []Primitive) graphql.Marshaler {
   381  	ret := make(graphql.Array, len(v))
   382  	var wg sync.WaitGroup
   383  	isLen1 := len(v) == 1
   384  	if !isLen1 {
   385  		wg.Add(len(v))
   386  	}
   387  	for i := range v {
   388  		i := i
   389  		fc := &graphql.FieldContext{
   390  			Index:  &i,
   391  			Result: &v[i],
   392  		}
   393  		ctx := graphql.WithFieldContext(ctx, fc)
   394  		f := func(i int) {
   395  			defer func() {
   396  				if r := recover(); r != nil {
   397  					ec.Error(ctx, ec.Recover(ctx, r))
   398  					ret = nil
   399  				}
   400  			}()
   401  			if !isLen1 {
   402  				defer wg.Done()
   403  			}
   404  			ret[i] = ec.marshalNPrimitive2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitive(ctx, sel, v[i])
   405  		}
   406  		if isLen1 {
   407  			f(i)
   408  		} else {
   409  			go f(i)
   410  		}
   411  
   412  	}
   413  	wg.Wait()
   414  
   415  	for _, e := range ret {
   416  		if e == graphql.Null {
   417  			return graphql.Null
   418  		}
   419  	}
   420  
   421  	return ret
   422  }
   423  
   424  func (ec *executionContext) marshalNPrimitiveString2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitiveString(ctx context.Context, sel ast.SelectionSet, v PrimitiveString) graphql.Marshaler {
   425  	return ec._PrimitiveString(ctx, sel, &v)
   426  }
   427  
   428  func (ec *executionContext) marshalNPrimitiveString2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitiveStringᚄ(ctx context.Context, sel ast.SelectionSet, v []PrimitiveString) graphql.Marshaler {
   429  	ret := make(graphql.Array, len(v))
   430  	var wg sync.WaitGroup
   431  	isLen1 := len(v) == 1
   432  	if !isLen1 {
   433  		wg.Add(len(v))
   434  	}
   435  	for i := range v {
   436  		i := i
   437  		fc := &graphql.FieldContext{
   438  			Index:  &i,
   439  			Result: &v[i],
   440  		}
   441  		ctx := graphql.WithFieldContext(ctx, fc)
   442  		f := func(i int) {
   443  			defer func() {
   444  				if r := recover(); r != nil {
   445  					ec.Error(ctx, ec.Recover(ctx, r))
   446  					ret = nil
   447  				}
   448  			}()
   449  			if !isLen1 {
   450  				defer wg.Done()
   451  			}
   452  			ret[i] = ec.marshalNPrimitiveString2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitiveString(ctx, sel, v[i])
   453  		}
   454  		if isLen1 {
   455  			f(i)
   456  		} else {
   457  			go f(i)
   458  		}
   459  
   460  	}
   461  	wg.Wait()
   462  
   463  	for _, e := range ret {
   464  		if e == graphql.Null {
   465  			return graphql.Null
   466  		}
   467  	}
   468  
   469  	return ret
   470  }
   471  
   472  // endregion ***************************** type.gotpl *****************************