github.com/maeglindeveloper/gqlgen@v0.13.1-0.20210413081235-57808b12a0a0/example/federation/products/graph/generated/federation.go (about)

     1  // Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
     2  
     3  package generated
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  	"strings"
    10  
    11  	"github.com/99designs/gqlgen/plugin/federation/fedruntime"
    12  )
    13  
    14  func (ec *executionContext) __resolve__service(ctx context.Context) (fedruntime.Service, error) {
    15  	if ec.DisableIntrospection {
    16  		return fedruntime.Service{}, errors.New("federated introspection disabled")
    17  	}
    18  
    19  	var sdl []string
    20  
    21  	for _, src := range sources {
    22  		if src.BuiltIn {
    23  			continue
    24  		}
    25  		sdl = append(sdl, src.Input)
    26  	}
    27  
    28  	return fedruntime.Service{
    29  		SDL: strings.Join(sdl, "\n"),
    30  	}, nil
    31  }
    32  
    33  func (ec *executionContext) __resolve_entities(ctx context.Context, representations []map[string]interface{}) ([]fedruntime.Entity, error) {
    34  	list := []fedruntime.Entity{}
    35  	for _, rep := range representations {
    36  		typeName, ok := rep["__typename"].(string)
    37  		if !ok {
    38  			return nil, errors.New("__typename must be an existing string")
    39  		}
    40  		switch typeName {
    41  
    42  		case "Product":
    43  			id0, err := ec.unmarshalNString2string(ctx, rep["upc"])
    44  			if err != nil {
    45  				return nil, errors.New(fmt.Sprintf("Field %s undefined in schema.", "upc"))
    46  			}
    47  
    48  			entity, err := ec.resolvers.Entity().FindProductByUpc(ctx,
    49  				id0)
    50  			if err != nil {
    51  				return nil, err
    52  			}
    53  
    54  			list = append(list, entity)
    55  
    56  		default:
    57  			return nil, errors.New("unknown type: " + typeName)
    58  		}
    59  	}
    60  	return list, nil
    61  }