123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- // Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
- package generated
- import (
- "context"
- "errors"
- "fmt"
- "strings"
- "sync"
- "github.com/99designs/gqlgen/plugin/federation/fedruntime"
- )
- var (
- ErrUnknownType = errors.New("unknown type")
- ErrTypeNotFound = errors.New("type not found")
- )
- func (ec *executionContext) __resolve__service(ctx context.Context) (fedruntime.Service, error) {
- if ec.DisableIntrospection {
- return fedruntime.Service{}, errors.New("federated introspection disabled")
- }
- var sdl []string
- for _, src := range sources {
- if src.BuiltIn {
- continue
- }
- sdl = append(sdl, src.Input)
- }
- return fedruntime.Service{
- SDL: strings.Join(sdl, "\n"),
- }, nil
- }
- func (ec *executionContext) __resolve_entities(ctx context.Context, representations []map[string]interface{}) []fedruntime.Entity {
- list := make([]fedruntime.Entity, len(representations))
- repsMap := map[string]struct {
- i []int
- r []map[string]interface{}
- }{}
- // We group entities by typename so that we can parallelize their resolution.
- // This is particularly helpful when there are entity groups in multi mode.
- buildRepresentationGroups := func(reps []map[string]interface{}) {
- for i, rep := range reps {
- typeName, ok := rep["__typename"].(string)
- if !ok {
- // If there is no __typename, we just skip the representation;
- // we just won't be resolving these unknown types.
- ec.Error(ctx, errors.New("__typename must be an existing string"))
- continue
- }
- _r := repsMap[typeName]
- _r.i = append(_r.i, i)
- _r.r = append(_r.r, rep)
- repsMap[typeName] = _r
- }
- }
- isMulti := func(typeName string) bool {
- switch typeName {
- default:
- return false
- }
- }
- resolveEntity := func(ctx context.Context, typeName string, rep map[string]interface{}, idx []int, i int) (err error) {
- // we need to do our own panic handling, because we may be called in a
- // goroutine, where the usual panic handling can't catch us
- defer func() {
- if r := recover(); r != nil {
- err = ec.Recover(ctx, r)
- }
- }()
- switch typeName {
- case "Collection":
- resolverName, err := entityResolverNameForCollection(ctx, rep)
- if err != nil {
- return fmt.Errorf(`finding resolver for Entity "Collection": %w`, err)
- }
- switch resolverName {
- case "findCollectionByID":
- id0, err := ec.unmarshalNID2string(ctx, rep["id"])
- if err != nil {
- return fmt.Errorf(`unmarshalling param 0 for findCollectionByID(): %w`, err)
- }
- entity, err := ec.resolvers.Entity().FindCollectionByID(ctx, id0)
- if err != nil {
- return fmt.Errorf(`resolving Entity "Collection": %w`, err)
- }
- list[idx[i]] = entity
- return nil
- }
- case "FulfillmentService":
- resolverName, err := entityResolverNameForFulfillmentService(ctx, rep)
- if err != nil {
- return fmt.Errorf(`finding resolver for Entity "FulfillmentService": %w`, err)
- }
- switch resolverName {
- case "findFulfillmentServiceByID":
- id0, err := ec.unmarshalNID2string(ctx, rep["id"])
- if err != nil {
- return fmt.Errorf(`unmarshalling param 0 for findFulfillmentServiceByID(): %w`, err)
- }
- entity, err := ec.resolvers.Entity().FindFulfillmentServiceByID(ctx, id0)
- if err != nil {
- return fmt.Errorf(`resolving Entity "FulfillmentService": %w`, err)
- }
- list[idx[i]] = entity
- return nil
- }
- case "InventoryLevel":
- resolverName, err := entityResolverNameForInventoryLevel(ctx, rep)
- if err != nil {
- return fmt.Errorf(`finding resolver for Entity "InventoryLevel": %w`, err)
- }
- switch resolverName {
- case "findInventoryLevelByID":
- id0, err := ec.unmarshalNID2string(ctx, rep["id"])
- if err != nil {
- return fmt.Errorf(`unmarshalling param 0 for findInventoryLevelByID(): %w`, err)
- }
- entity, err := ec.resolvers.Entity().FindInventoryLevelByID(ctx, id0)
- if err != nil {
- return fmt.Errorf(`resolving Entity "InventoryLevel": %w`, err)
- }
- list[idx[i]] = entity
- return nil
- }
- case "Product":
- resolverName, err := entityResolverNameForProduct(ctx, rep)
- if err != nil {
- return fmt.Errorf(`finding resolver for Entity "Product": %w`, err)
- }
- switch resolverName {
- case "findProductByID":
- id0, err := ec.unmarshalNID2string(ctx, rep["id"])
- if err != nil {
- return fmt.Errorf(`unmarshalling param 0 for findProductByID(): %w`, err)
- }
- entity, err := ec.resolvers.Entity().FindProductByID(ctx, id0)
- if err != nil {
- return fmt.Errorf(`resolving Entity "Product": %w`, err)
- }
- list[idx[i]] = entity
- return nil
- }
- case "ProductOption":
- resolverName, err := entityResolverNameForProductOption(ctx, rep)
- if err != nil {
- return fmt.Errorf(`finding resolver for Entity "ProductOption": %w`, err)
- }
- switch resolverName {
- case "findProductOptionByID":
- id0, err := ec.unmarshalNID2string(ctx, rep["id"])
- if err != nil {
- return fmt.Errorf(`unmarshalling param 0 for findProductOptionByID(): %w`, err)
- }
- entity, err := ec.resolvers.Entity().FindProductOptionByID(ctx, id0)
- if err != nil {
- return fmt.Errorf(`resolving Entity "ProductOption": %w`, err)
- }
- list[idx[i]] = entity
- return nil
- }
- case "ProductVariant":
- resolverName, err := entityResolverNameForProductVariant(ctx, rep)
- if err != nil {
- return fmt.Errorf(`finding resolver for Entity "ProductVariant": %w`, err)
- }
- switch resolverName {
- case "findProductVariantByID":
- id0, err := ec.unmarshalNID2string(ctx, rep["id"])
- if err != nil {
- return fmt.Errorf(`unmarshalling param 0 for findProductVariantByID(): %w`, err)
- }
- entity, err := ec.resolvers.Entity().FindProductVariantByID(ctx, id0)
- if err != nil {
- return fmt.Errorf(`resolving Entity "ProductVariant": %w`, err)
- }
- list[idx[i]] = entity
- return nil
- }
- }
- return fmt.Errorf("%w: %s", ErrUnknownType, typeName)
- }
- resolveManyEntities := func(ctx context.Context, typeName string, reps []map[string]interface{}, idx []int) (err error) {
- // we need to do our own panic handling, because we may be called in a
- // goroutine, where the usual panic handling can't catch us
- defer func() {
- if r := recover(); r != nil {
- err = ec.Recover(ctx, r)
- }
- }()
- switch typeName {
- default:
- return errors.New("unknown type: " + typeName)
- }
- }
- resolveEntityGroup := func(typeName string, reps []map[string]interface{}, idx []int) {
- if isMulti(typeName) {
- err := resolveManyEntities(ctx, typeName, reps, idx)
- if err != nil {
- ec.Error(ctx, err)
- }
- } else {
- // if there are multiple entities to resolve, parallelize (similar to
- // graphql.FieldSet.Dispatch)
- var e sync.WaitGroup
- e.Add(len(reps))
- for i, rep := range reps {
- i, rep := i, rep
- go func(i int, rep map[string]interface{}) {
- err := resolveEntity(ctx, typeName, rep, idx, i)
- if err != nil {
- ec.Error(ctx, err)
- }
- e.Done()
- }(i, rep)
- }
- e.Wait()
- }
- }
- buildRepresentationGroups(representations)
- switch len(repsMap) {
- case 0:
- return list
- case 1:
- for typeName, reps := range repsMap {
- resolveEntityGroup(typeName, reps.r, reps.i)
- }
- return list
- default:
- var g sync.WaitGroup
- g.Add(len(repsMap))
- for typeName, reps := range repsMap {
- go func(typeName string, reps []map[string]interface{}, idx []int) {
- resolveEntityGroup(typeName, reps, idx)
- g.Done()
- }(typeName, reps.r, reps.i)
- }
- g.Wait()
- return list
- }
- }
- func entityResolverNameForCollection(ctx context.Context, rep map[string]interface{}) (string, error) {
- for {
- var (
- m map[string]interface{}
- val interface{}
- ok bool
- )
- _ = val
- m = rep
- if _, ok = m["id"]; !ok {
- break
- }
- return "findCollectionByID", nil
- }
- return "", fmt.Errorf("%w for Collection", ErrTypeNotFound)
- }
- func entityResolverNameForFulfillmentService(ctx context.Context, rep map[string]interface{}) (string, error) {
- for {
- var (
- m map[string]interface{}
- val interface{}
- ok bool
- )
- _ = val
- m = rep
- if _, ok = m["id"]; !ok {
- break
- }
- return "findFulfillmentServiceByID", nil
- }
- return "", fmt.Errorf("%w for FulfillmentService", ErrTypeNotFound)
- }
- func entityResolverNameForInventoryLevel(ctx context.Context, rep map[string]interface{}) (string, error) {
- for {
- var (
- m map[string]interface{}
- val interface{}
- ok bool
- )
- _ = val
- m = rep
- if _, ok = m["id"]; !ok {
- break
- }
- return "findInventoryLevelByID", nil
- }
- return "", fmt.Errorf("%w for InventoryLevel", ErrTypeNotFound)
- }
- func entityResolverNameForProduct(ctx context.Context, rep map[string]interface{}) (string, error) {
- for {
- var (
- m map[string]interface{}
- val interface{}
- ok bool
- )
- _ = val
- m = rep
- if _, ok = m["id"]; !ok {
- break
- }
- return "findProductByID", nil
- }
- return "", fmt.Errorf("%w for Product", ErrTypeNotFound)
- }
- func entityResolverNameForProductOption(ctx context.Context, rep map[string]interface{}) (string, error) {
- for {
- var (
- m map[string]interface{}
- val interface{}
- ok bool
- )
- _ = val
- m = rep
- if _, ok = m["id"]; !ok {
- break
- }
- return "findProductOptionByID", nil
- }
- return "", fmt.Errorf("%w for ProductOption", ErrTypeNotFound)
- }
- func entityResolverNameForProductVariant(ctx context.Context, rep map[string]interface{}) (string, error) {
- for {
- var (
- m map[string]interface{}
- val interface{}
- ok bool
- )
- _ = val
- m = rep
- if _, ok = m["id"]; !ok {
- break
- }
- return "findProductVariantByID", nil
- }
- return "", fmt.Errorf("%w for ProductVariant", ErrTypeNotFound)
- }
|