...

Source file src/github.com/99designs/gqlgen/codegen/testserver/followschema/useptr.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  	"fmt"
     9  	"strconv"
    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  // endregion ************************** generated!.gotpl **************************
    19  
    20  // region    ***************************** args.gotpl *****************************
    21  
    22  // endregion ***************************** args.gotpl *****************************
    23  
    24  // region    ************************** directives.gotpl **************************
    25  
    26  // endregion ************************** directives.gotpl **************************
    27  
    28  // region    **************************** field.gotpl *****************************
    29  
    30  func (ec *executionContext) _A_id(ctx context.Context, field graphql.CollectedField, obj *A) (ret graphql.Marshaler) {
    31  	fc, err := ec.fieldContext_A_id(ctx, field)
    32  	if err != nil {
    33  		return graphql.Null
    34  	}
    35  	ctx = graphql.WithFieldContext(ctx, fc)
    36  	defer func() {
    37  		if r := recover(); r != nil {
    38  			ec.Error(ctx, ec.Recover(ctx, r))
    39  			ret = graphql.Null
    40  		}
    41  	}()
    42  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    43  		ctx = rctx // use context from middleware stack in children
    44  		return obj.ID, nil
    45  	})
    46  
    47  	if resTmp == nil {
    48  		if !graphql.HasFieldError(ctx, fc) {
    49  			ec.Errorf(ctx, "must not be null")
    50  		}
    51  		return graphql.Null
    52  	}
    53  	res := resTmp.(string)
    54  	fc.Result = res
    55  	return ec.marshalNID2string(ctx, field.Selections, res)
    56  }
    57  
    58  func (ec *executionContext) fieldContext_A_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
    59  	fc = &graphql.FieldContext{
    60  		Object:     "A",
    61  		Field:      field,
    62  		IsMethod:   false,
    63  		IsResolver: false,
    64  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
    65  			return nil, errors.New("field of type ID does not have child fields")
    66  		},
    67  	}
    68  	return fc, nil
    69  }
    70  
    71  func (ec *executionContext) _B_id(ctx context.Context, field graphql.CollectedField, obj *B) (ret graphql.Marshaler) {
    72  	fc, err := ec.fieldContext_B_id(ctx, field)
    73  	if err != nil {
    74  		return graphql.Null
    75  	}
    76  	ctx = graphql.WithFieldContext(ctx, fc)
    77  	defer func() {
    78  		if r := recover(); r != nil {
    79  			ec.Error(ctx, ec.Recover(ctx, r))
    80  			ret = graphql.Null
    81  		}
    82  	}()
    83  	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
    84  		ctx = rctx // use context from middleware stack in children
    85  		return obj.ID, nil
    86  	})
    87  
    88  	if resTmp == nil {
    89  		if !graphql.HasFieldError(ctx, fc) {
    90  			ec.Errorf(ctx, "must not be null")
    91  		}
    92  		return graphql.Null
    93  	}
    94  	res := resTmp.(string)
    95  	fc.Result = res
    96  	return ec.marshalNID2string(ctx, field.Selections, res)
    97  }
    98  
    99  func (ec *executionContext) fieldContext_B_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
   100  	fc = &graphql.FieldContext{
   101  		Object:     "B",
   102  		Field:      field,
   103  		IsMethod:   false,
   104  		IsResolver: false,
   105  		Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
   106  			return nil, errors.New("field of type ID does not have child fields")
   107  		},
   108  	}
   109  	return fc, nil
   110  }
   111  
   112  // endregion **************************** field.gotpl *****************************
   113  
   114  // region    **************************** input.gotpl *****************************
   115  
   116  // endregion **************************** input.gotpl *****************************
   117  
   118  // region    ************************** interface.gotpl ***************************
   119  
   120  func (ec *executionContext) _TestUnion(ctx context.Context, sel ast.SelectionSet, obj TestUnion) graphql.Marshaler {
   121  	switch obj := (obj).(type) {
   122  	case nil:
   123  		return graphql.Null
   124  	case A:
   125  		return ec._A(ctx, sel, &obj)
   126  	case *A:
   127  		if obj == nil {
   128  			return graphql.Null
   129  		}
   130  		return ec._A(ctx, sel, obj)
   131  	case B:
   132  		return ec._B(ctx, sel, &obj)
   133  	case *B:
   134  		if obj == nil {
   135  			return graphql.Null
   136  		}
   137  		return ec._B(ctx, sel, obj)
   138  	default:
   139  		panic(fmt.Errorf("unexpected type %T", obj))
   140  	}
   141  }
   142  
   143  // endregion ************************** interface.gotpl ***************************
   144  
   145  // region    **************************** object.gotpl ****************************
   146  
   147  var aImplementors = []string{"A", "TestUnion"}
   148  
   149  func (ec *executionContext) _A(ctx context.Context, sel ast.SelectionSet, obj *A) graphql.Marshaler {
   150  	fields := graphql.CollectFields(ec.OperationContext, sel, aImplementors)
   151  
   152  	out := graphql.NewFieldSet(fields)
   153  	deferred := make(map[string]*graphql.FieldSet)
   154  	for i, field := range fields {
   155  		switch field.Name {
   156  		case "__typename":
   157  			out.Values[i] = graphql.MarshalString("A")
   158  		case "id":
   159  			out.Values[i] = ec._A_id(ctx, field, obj)
   160  			if out.Values[i] == graphql.Null {
   161  				out.Invalids++
   162  			}
   163  		default:
   164  			panic("unknown field " + strconv.Quote(field.Name))
   165  		}
   166  	}
   167  	out.Dispatch(ctx)
   168  	if out.Invalids > 0 {
   169  		return graphql.Null
   170  	}
   171  
   172  	atomic.AddInt32(&ec.deferred, int32(len(deferred)))
   173  
   174  	for label, dfs := range deferred {
   175  		ec.processDeferredGroup(graphql.DeferredGroup{
   176  			Label:    label,
   177  			Path:     graphql.GetPath(ctx),
   178  			FieldSet: dfs,
   179  			Context:  ctx,
   180  		})
   181  	}
   182  
   183  	return out
   184  }
   185  
   186  var bImplementors = []string{"B", "TestUnion"}
   187  
   188  func (ec *executionContext) _B(ctx context.Context, sel ast.SelectionSet, obj *B) graphql.Marshaler {
   189  	fields := graphql.CollectFields(ec.OperationContext, sel, bImplementors)
   190  
   191  	out := graphql.NewFieldSet(fields)
   192  	deferred := make(map[string]*graphql.FieldSet)
   193  	for i, field := range fields {
   194  		switch field.Name {
   195  		case "__typename":
   196  			out.Values[i] = graphql.MarshalString("B")
   197  		case "id":
   198  			out.Values[i] = ec._B_id(ctx, field, obj)
   199  			if out.Values[i] == graphql.Null {
   200  				out.Invalids++
   201  			}
   202  		default:
   203  			panic("unknown field " + strconv.Quote(field.Name))
   204  		}
   205  	}
   206  	out.Dispatch(ctx)
   207  	if out.Invalids > 0 {
   208  		return graphql.Null
   209  	}
   210  
   211  	atomic.AddInt32(&ec.deferred, int32(len(deferred)))
   212  
   213  	for label, dfs := range deferred {
   214  		ec.processDeferredGroup(graphql.DeferredGroup{
   215  			Label:    label,
   216  			Path:     graphql.GetPath(ctx),
   217  			FieldSet: dfs,
   218  			Context:  ctx,
   219  		})
   220  	}
   221  
   222  	return out
   223  }
   224  
   225  // endregion **************************** object.gotpl ****************************
   226  
   227  // region    ***************************** type.gotpl *****************************
   228  
   229  func (ec *executionContext) marshalOTestUnion2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐTestUnion(ctx context.Context, sel ast.SelectionSet, v TestUnion) graphql.Marshaler {
   230  	if v == nil {
   231  		return graphql.Null
   232  	}
   233  	return ec._TestUnion(ctx, sel, v)
   234  }
   235  
   236  // endregion ***************************** type.gotpl *****************************
   237  

View as plain text