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