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