func()

in _examples/federation/products/graph/federation.go [142:212]


func (ec *executionContext) resolveEntity(
	ctx context.Context,
	typeName string,
	rep EntityRepresentation,
) (e fedruntime.Entity, 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 "Manufacturer":
		resolverName, err := entityResolverNameForManufacturer(ctx, rep)
		if err != nil {
			return nil, fmt.Errorf(`finding resolver for Entity "Manufacturer": %w`, err)
		}
		switch resolverName {

		case "findManufacturerByID":
			id0, err := ec.unmarshalNString2string(ctx, rep["id"])
			if err != nil {
				return nil, fmt.Errorf(`unmarshalling param 0 for findManufacturerByID(): %w`, err)
			}
			entity, err := ec.resolvers.Entity().FindManufacturerByID(ctx, id0)
			if err != nil {
				return nil, fmt.Errorf(`resolving Entity "Manufacturer": %w`, err)
			}

			return entity, nil
		}
	case "Product":
		resolverName, err := entityResolverNameForProduct(ctx, rep)
		if err != nil {
			return nil, fmt.Errorf(`finding resolver for Entity "Product": %w`, err)
		}
		switch resolverName {

		case "findProductByManufacturerIDAndID":
			id0, err := ec.unmarshalNString2string(ctx, rep["manufacturer"].(map[string]interface{})["id"])
			if err != nil {
				return nil, fmt.Errorf(`unmarshalling param 0 for findProductByManufacturerIDAndID(): %w`, err)
			}
			id1, err := ec.unmarshalNString2string(ctx, rep["id"])
			if err != nil {
				return nil, fmt.Errorf(`unmarshalling param 1 for findProductByManufacturerIDAndID(): %w`, err)
			}
			entity, err := ec.resolvers.Entity().FindProductByManufacturerIDAndID(ctx, id0, id1)
			if err != nil {
				return nil, fmt.Errorf(`resolving Entity "Product": %w`, err)
			}

			return entity, nil
		case "findProductByUpc":
			id0, err := ec.unmarshalNString2string(ctx, rep["upc"])
			if err != nil {
				return nil, fmt.Errorf(`unmarshalling param 0 for findProductByUpc(): %w`, err)
			}
			entity, err := ec.resolvers.Entity().FindProductByUpc(ctx, id0)
			if err != nil {
				return nil, fmt.Errorf(`resolving Entity "Product": %w`, err)
			}

			return entity, nil
		}

	}
	return nil, fmt.Errorf("%w: %s", ErrUnknownType, typeName)
}