...

Source file src/github.com/99designs/gqlgen/codegen/testserver/followschema/defer.generated.go

Documentation: github.com/99designs/gqlgen/codegen/testserver/followschema

     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"
    10  	"sync/atomic"
    11  
    12  	"github.com/99designs/gqlgen/graphql"
    13  	"github.com/vektah/gqlparser/v2/ast"
    14  )
    15  
    16  // region    ************************** generated!.gotpl **************************
    17  
    18  type DeferModelResolver interface {
    19  	Values(ctx context.Context, obj *DeferModel) ([]string, error)
    20  }
    21  
    22  // endregion ************************** generated!.gotpl **************************
    23  
    24  // region    ***************************** args.gotpl *****************************
    25  
    26  // endregion ***************************** args.gotpl *****************************
    27  
    28  // region    ************************** directives.gotpl **************************
    29  
    30  // endregion ************************** directives.gotpl **************************
    31  
    32  // region    **************************** field.gotpl *****************************
    33  
    34  func (ec *executionContext) _DeferModel_id(ctx context.Context, field graphql.CollectedField, obj *DeferModel) (ret graphql.Marshaler) {
    35  	fc, err := ec.fieldContext_DeferModel_id(ctx, field)
    36  	if err != nil {
    37  		return graphql.Null
    38  	}
    39  	ctx = graphql.WithFieldContext(ctx, fc)
    40  	defer func() {
    41  		if r := recover(); r != nil {
    42  			ec.Error(ctx, ec.Recover(ctx, r))
    43  			ret = graphql.Null
    44  		}
    45  	}()
    46  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    47  		ctx = rctx // use context from middleware stack in children
    48  		return obj.ID, nil
    49  	})
    50  
    51  	if resTmp == nil {
    52  		if !graphql.HasFieldError(ctx, fc) {
    53  			ec.Errorf(ctx, "must not be null")
    54  		}
    55  		return graphql.Null
    56  	}
    57  	res := resTmp.(string)
    58  	fc.Result = res
    59  	return ec.marshalNID2string(ctx, field.Selections, res)
    60  }
    61  
    62  func (ec *executionContext) fieldContext_DeferModel_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
    63  	fc = &graphql.FieldContext{
    64  		Object:     "DeferModel",
    65  		Field:      field,
    66  		IsMethod:   false,
    67  		IsResolver: false,
    68  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
    69  			return nil, errors.New("field of type ID does not have child fields")
    70  		},
    71  	}
    72  	return fc, nil
    73  }
    74  
    75  func (ec *executionContext) _DeferModel_name(ctx context.Context, field graphql.CollectedField, obj *DeferModel) (ret graphql.Marshaler) {
    76  	fc, err := ec.fieldContext_DeferModel_name(ctx, field)
    77  	if err != nil {
    78  		return graphql.Null
    79  	}
    80  	ctx = graphql.WithFieldContext(ctx, fc)
    81  	defer func() {
    82  		if r := recover(); r != nil {
    83  			ec.Error(ctx, ec.Recover(ctx, r))
    84  			ret = graphql.Null
    85  		}
    86  	}()
    87  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    88  		ctx = rctx // use context from middleware stack in children
    89  		return obj.Name, nil
    90  	})
    91  
    92  	if resTmp == nil {
    93  		if !graphql.HasFieldError(ctx, fc) {
    94  			ec.Errorf(ctx, "must not be null")
    95  		}
    96  		return graphql.Null
    97  	}
    98  	res := resTmp.(string)
    99  	fc.Result = res
   100  	return ec.marshalNString2string(ctx, field.Selections, res)
   101  }
   102  
   103  func (ec *executionContext) fieldContext_DeferModel_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   104  	fc = &graphql.FieldContext{
   105  		Object:     "DeferModel",
   106  		Field:      field,
   107  		IsMethod:   false,
   108  		IsResolver: false,
   109  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   110  			return nil, errors.New("field of type String does not have child fields")
   111  		},
   112  	}
   113  	return fc, nil
   114  }
   115  
   116  func (ec *executionContext) _DeferModel_values(ctx context.Context, field graphql.CollectedField, obj *DeferModel) (ret graphql.Marshaler) {
   117  	fc, err := ec.fieldContext_DeferModel_values(ctx, field)
   118  	if err != nil {
   119  		return graphql.Null
   120  	}
   121  	ctx = graphql.WithFieldContext(ctx, fc)
   122  	defer func() {
   123  		if r := recover(); r != nil {
   124  			ec.Error(ctx, ec.Recover(ctx, r))
   125  			ret = graphql.Null
   126  		}
   127  	}()
   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.DeferModel().Values(rctx, obj)
   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.marshalNString2ᚕstringᚄ(ctx, field.Selections, res)
   142  }
   143  
   144  func (ec *executionContext) fieldContext_DeferModel_values(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   145  	fc = &graphql.FieldContext{
   146  		Object:     "DeferModel",
   147  		Field:      field,
   148  		IsMethod:   true,
   149  		IsResolver: true,
   150  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   151  			return nil, errors.New("field of type String does not have child fields")
   152  		},
   153  	}
   154  	return fc, nil
   155  }
   156  
   157  // endregion **************************** field.gotpl *****************************
   158  
   159  // region    **************************** input.gotpl *****************************
   160  
   161  // endregion **************************** input.gotpl *****************************
   162  
   163  // region    ************************** interface.gotpl ***************************
   164  
   165  // endregion ************************** interface.gotpl ***************************
   166  
   167  // region    **************************** object.gotpl ****************************
   168  
   169  var deferModelImplementors = []string{"DeferModel"}
   170  
   171  func (ec *executionContext) _DeferModel(ctx context.Context, sel ast.SelectionSet, obj *DeferModel) graphql.Marshaler {
   172  	fields := graphql.CollectFields(ec.OperationContext, sel, deferModelImplementors)
   173  
   174  	out := graphql.NewFieldSet(fields)
   175  	deferred := make(map[string]*graphql.FieldSet)
   176  	for i, field := range fields {
   177  		switch field.Name {
   178  		case "__typename":
   179  			out.Values[i] = graphql.MarshalString("DeferModel")
   180  		case "id":
   181  			out.Values[i] = ec._DeferModel_id(ctx, field, obj)
   182  			if out.Values[i] == graphql.Null {
   183  				atomic.AddUint32(&out.Invalids, 1)
   184  			}
   185  		case "name":
   186  			out.Values[i] = ec._DeferModel_name(ctx, field, obj)
   187  			if out.Values[i] == graphql.Null {
   188  				atomic.AddUint32(&out.Invalids, 1)
   189  			}
   190  		case "values":
   191  			field := field
   192  
   193  			innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
   194  				defer func() {
   195  					if r := recover(); r != nil {
   196  						ec.Error(ctx, ec.Recover(ctx, r))
   197  					}
   198  				}()
   199  				res = ec._DeferModel_values(ctx, field, obj)
   200  				if res == graphql.Null {
   201  					atomic.AddUint32(&fs.Invalids, 1)
   202  				}
   203  				return res
   204  			}
   205  
   206  			if field.Deferrable != nil {
   207  				dfs, ok := deferred[field.Deferrable.Label]
   208  				di := 0
   209  				if ok {
   210  					dfs.AddField(field)
   211  					di = len(dfs.Values) - 1
   212  				} else {
   213  					dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
   214  					deferred[field.Deferrable.Label] = dfs
   215  				}
   216  				dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
   217  					return innerFunc(ctx, dfs)
   218  				})
   219  
   220  				// don't run the out.Concurrently() call below
   221  				out.Values[i] = graphql.Null
   222  				continue
   223  			}
   224  
   225  			out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
   226  		default:
   227  			panic("unknown field " + strconv.Quote(field.Name))
   228  		}
   229  	}
   230  	out.Dispatch(ctx)
   231  	if out.Invalids > 0 {
   232  		return graphql.Null
   233  	}
   234  
   235  	atomic.AddInt32(&ec.deferred, int32(len(deferred)))
   236  
   237  	for label, dfs := range deferred {
   238  		ec.processDeferredGroup(graphql.DeferredGroup{
   239  			Label:    label,
   240  			Path:     graphql.GetPath(ctx),
   241  			FieldSet: dfs,
   242  			Context:  ctx,
   243  		})
   244  	}
   245  
   246  	return out
   247  }
   248  
   249  // endregion **************************** object.gotpl ****************************
   250  
   251  // region    ***************************** type.gotpl *****************************
   252  
   253  func (ec *executionContext) marshalNDeferModel2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐDeferModel(ctx context.Context, sel ast.SelectionSet, v *DeferModel) graphql.Marshaler {
   254  	if v == nil {
   255  		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
   256  			ec.Errorf(ctx, "the requested element is null which the schema does not allow")
   257  		}
   258  		return graphql.Null
   259  	}
   260  	return ec._DeferModel(ctx, sel, v)
   261  }
   262  
   263  func (ec *executionContext) marshalODeferModel2ᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐDeferModelᚄ(ctx context.Context, sel ast.SelectionSet, v []*DeferModel) graphql.Marshaler {
   264  	if v == nil {
   265  		return graphql.Null
   266  	}
   267  	ret := make(graphql.Array, len(v))
   268  	var wg sync.WaitGroup
   269  	isLen1 := len(v) == 1
   270  	if !isLen1 {
   271  		wg.Add(len(v))
   272  	}
   273  	for i := range v {
   274  		i := i
   275  		fc := &graphql.FieldContext{
   276  			Index:  &i,
   277  			Result: &v[i],
   278  		}
   279  		ctx := graphql.WithFieldContext(ctx, fc)
   280  		f := func(i int) {
   281  			defer func() {
   282  				if r := recover(); r != nil {
   283  					ec.Error(ctx, ec.Recover(ctx, r))
   284  					ret = nil
   285  				}
   286  			}()
   287  			if !isLen1 {
   288  				defer wg.Done()
   289  			}
   290  			ret[i] = ec.marshalNDeferModel2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐDeferModel(ctx, sel, v[i])
   291  		}
   292  		if isLen1 {
   293  			f(i)
   294  		} else {
   295  			go f(i)
   296  		}
   297  
   298  	}
   299  	wg.Wait()
   300  
   301  	for _, e := range ret {
   302  		if e == graphql.Null {
   303  			return graphql.Null
   304  		}
   305  	}
   306  
   307  	return ret
   308  }
   309  
   310  func (ec *executionContext) marshalODeferModel2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐDeferModel(ctx context.Context, sel ast.SelectionSet, v *DeferModel) graphql.Marshaler {
   311  	if v == nil {
   312  		return graphql.Null
   313  	}
   314  	return ec._DeferModel(ctx, sel, v)
   315  }
   316  
   317  // endregion ***************************** type.gotpl *****************************
   318  

View as plain text