Пример #1
0
 public InterfaceFieldsController(IMetaFieldRepository metaFieldRepository, IInterfaceFieldsRepository interfaceFieldsRepository, IInterfaceFieldsService InterfaceFieldsService, IMetaFieldService metaFieldService)
 {
     _metaFieldRepository       = metaFieldRepository;
     _interfaceFieldsRepository = interfaceFieldsRepository;
     _metaFieldService          = metaFieldService;
     _interfaceFieldsService    = InterfaceFieldsService;
 }
 public MetaFieldController(
     IMetaFieldService _metaFieldService,
     IMetaObjectService _metaObjectService
     )
 {
     metaFieldService  = _metaFieldService;
     metaObjectService = _metaObjectService;
 }
Пример #3
0
 public InterfaceConditionController(IMetaFieldRepository metaFieldRepository, IInterfaceSettingApp interfaceSettingApp, IInterfaceConditionRepository InterfaceConditionRepository, IInterfaceConditionService InterfaceConditionService, IMetaFieldService metaFieldService)
 {
     _metaFieldRepository          = metaFieldRepository;
     _interfaceSettingApp          = interfaceSettingApp;
     _InterfaceConditionRepository = InterfaceConditionRepository;
     _metaFieldService             = metaFieldService;
     _InterfaceConditionService    = InterfaceConditionService;
 }
 public FormMetaFieldService(
     MultiTenantPlatformDbContext multiTenantPlatformDbContext,
     IMetaFieldService _metaFieldService
     ) : base(multiTenantPlatformDbContext)
 {
     dbContext        = multiTenantPlatformDbContext;
     metaFieldService = _metaFieldService;
 }
 public FieldListAggregationService(
     MultiTenantPlatformDbContext multiTenantPlatformDbContext,
     IMetaFieldService _metaFieldService
     ) : base(multiTenantPlatformDbContext)
 {
     dbContext        = multiTenantPlatformDbContext;
     metaFieldService = _metaFieldService;
 }
 public SearchConditionNodeService(
     MultiTenantPlatformDbContext multiTenantPlatformDbContext,
     IMetaFieldService _metaFieldService
     ) : base(multiTenantPlatformDbContext)
 {
     dbContext        = multiTenantPlatformDbContext;
     metaFieldService = _metaFieldService;
 }
 public FormController(
     IFormService formService,
     IMetaFieldService _metaFieldService,
     IFormMetaFieldService formMetaFieldService
     )
 {
     _formService          = formService;
     metaFieldService      = _metaFieldService;
     _formMetaFieldService = formMetaFieldService;
 }
Пример #8
0
 public SearchConditionController(
     ISearchConditionService _searchConditionService,
     IMetaFieldService _metaFieldService,
     ISearchConditionNodeService _conditionAggregationService
     )
 {
     searchConditionService      = _searchConditionService;
     metaFieldService            = _metaFieldService;
     conditionAggregationService = _conditionAggregationService;
 }
 public FieldListController(
     IFieldListService _interfaceFieldService,
     IMetaFieldService _metaFieldService,
     IInterfaceAggregationService _interfaceAggregationService,
     IFieldListAggregationService _fieldAggregationService
     )
 {
     fieldListService            = _interfaceFieldService;
     metaFieldService            = _metaFieldService;
     interfaceAggregationService = _interfaceAggregationService;
     fieldAggregationService     = _fieldAggregationService;
 }
 public InterfaceSettingController(IInterfaceSortRepository interfaceSortRepository, IInterfaceConditionService interfaceConditionService, IInterfaceVerificationService interfaceVerificationService, IInterfaceFieldsService interfaceFieldsService, IInterfaceFieldsRepository interfaceFieldsRepository, IInterfaceVerificationRepository interfaceVerificationRepository, IInterfaceConditionRepository interfaceConditionRepository, IInterfaceSettingApp interfaceSettingApp, IInterfaceSettingRepository InterfaceSettingRepository, IInterfaceSettingService InterfaceSettingService, IMetaFieldService metaFieldService)
 {
     _interfaceSortRepository         = interfaceSortRepository;
     _interfaceConditionService       = interfaceConditionService;
     _interfaceVerificationService    = interfaceVerificationService;
     _interfaceFieldsService          = interfaceFieldsService;
     _interfaceFieldsRepository       = interfaceFieldsRepository;
     _interfaceVerificationRepository = interfaceVerificationRepository;
     _interfaceConditionRepository    = interfaceConditionRepository;
     _interfaceSettingApp             = interfaceSettingApp;
     _InterfaceSettingRepository      = InterfaceSettingRepository;
     _metaFieldService        = metaFieldService;
     _InterfaceSettingService = InterfaceSettingService;
 }
 public DataAccessService(
     MultiTenantDataDbContext _db,
     IMetaFieldService _metaFieldService,
     IMetaObjectService _metaObjectService,
     IFieldBizDataService _fieldBizDataService,
     IFieldListAggregationService _fieldListAggregationService
     )
 {
     db = _db;
     metaFieldService            = _metaFieldService;
     metaObjectService           = _metaObjectService;
     fieldBizDataService         = _fieldBizDataService;
     fieldListAggregationService = _fieldListAggregationService;
 }
Пример #12
0
 public DataAccessApp(ITriggerScriptService triggerScriptService, ITriggerScriptRepository triggerScriptRepository, IInterfaceSortRepository interfaceSortRepository, IInterfaceFieldsRepository interfaceFieldsRepository, IInterfaceVerificationRepository interfaceVerificationRepository, IInterfaceVerificationService interfaceVerificationService, IMetaFieldRepository metaFieldRepository, ChameleonDataDbContext chameleonDataDbContext, IInterfaceSettingService interfaceSettingService, IInterfaceConditionService interfaceConditionService, IInterfaceFieldsService interfaceFieldsService, IMetaFieldService metaFieldService)
 {
     _triggerScriptService            = triggerScriptService;
     _triggerScriptRepository         = triggerScriptRepository;
     _interfaceSortRepository         = interfaceSortRepository;
     _interfaceFieldsRepository       = interfaceFieldsRepository;
     _interfaceVerificationRepository = interfaceVerificationRepository;
     _interfaceVerificationService    = interfaceVerificationService;
     _metaFieldRepository             = metaFieldRepository;
     _chameleonDataDbContext          = chameleonDataDbContext;
     _interfaceSettingService         = interfaceSettingService;
     _metaFieldService          = metaFieldService;
     _interfaceFieldsService    = interfaceFieldsService;
     _interfaceConditionService = interfaceConditionService;
 }
Пример #13
0
 public HomeController(
     ICategoryService categoryService,
     IListingService listingService,
     IContentPageService contentPageService,
     IContentPageRoleService contentPageRoleService,
     ICustomFieldCategoryService customFieldCategoryService,
     IMetaFieldService metaFieldService)
 {
     _categoryService            = categoryService;
     _listingService             = listingService;
     _contentPageService         = contentPageService;
     _contentPageRoleService     = contentPageRoleService;
     _customFieldCategoryService = customFieldCategoryService;
     _metaFieldService           = metaFieldService;
 }
Пример #14
0
 public MetaObjectService(
     MultiTenantPlatformDbContext multiTenantPlatformDbContext,
     IMetaFieldService _metaFieldService,
     IFieldListService _fieldListService,
     IInterfaceAggregationService _interfaceAggregationService,
     ISearchConditionService _searchConditionService,
     ITriggerScriptService _triggerScriptService
     ) : base(multiTenantPlatformDbContext)
 {
     dbContext                   = multiTenantPlatformDbContext;
     metaFieldService            = _metaFieldService;
     fieldListService            = _fieldListService;
     interfaceAggregationService = _interfaceAggregationService;
     searchConditionService      = _searchConditionService;
     triggerScriptService        = _triggerScriptService;
 }
Пример #15
0
 public IndexPageController(
     IDataAccessService _dataAccessService,
     ISearchConditionService _searchConditionService,
     ISearchConditionAggregationService _conditionAggregationService,
     IIndexViewService _indexViewService,
     IFieldBizDataService _fieldBizDataService,
     ITriggerScriptEngineService _triggerScriptEngineService,
     IMetaObjectService _metaObjectService,
     IMetaFieldService _metaFieldService
     )
 {
     dataAccessService           = _dataAccessService;
     conditionAggregationService = _conditionAggregationService;
     indexViewService            = _indexViewService;
     fieldBizDataService         = _fieldBizDataService;
     triggerScriptEngineService  = _triggerScriptEngineService;
     searchConditionService      = _searchConditionService;
     metaObjectService           = _metaObjectService;
     metaFieldService            = _metaFieldService;
 }
Пример #16
0
 public CloudDataController(
     IDataAccessService _dataAccessService,
     ISearchConditionNodeService _conditionAggregationService,
     IInterfaceAggregationService _interfaceAggregationService,
     ITriggerScriptService triggerScriptService,
     IDataSourceService dataSourceService,
     IMetaObjectService _metaObjectService,
     IMetaFieldService _metaFieldService,
     IFormMetaFieldService formMetaFieldService,
     IFieldListMetaFieldService fieldListMetaFieldService
     )
 {
     dataAccessService           = _dataAccessService;
     conditionAggregationService = _conditionAggregationService;
     interfaceAggregationService = _interfaceAggregationService;
     _triggerScriptService       = triggerScriptService;
     metaObjectService           = _metaObjectService;
     metaFieldService            = _metaFieldService;
     _dataSourceService          = dataSourceService;
     _formMetaFieldService       = formMetaFieldService;
     _fieldListMetaFieldService  = fieldListMetaFieldService;
 }
Пример #17
0
 public MetaFieldController(IMetaFieldRepository metaFieldRepository, IMetaFieldService metaFieldService)
 {
     _metaFieldRepository = metaFieldRepository;
     _metaFieldService    = metaFieldService;
 }
 public InterfaceConditionService(IMetaFieldService metaFieldService, IInterfaceConditionRepository repository, IMetaFieldRepository metaFieldRepository) : base(repository)
 {
     _metaFieldService             = metaFieldService;
     _metaFieldRepository          = metaFieldRepository;
     _InterfaceConditionRepository = repository;
 }
Пример #19
0
        public NavigationGraphType(
            IDataLoaderContextAccessor dataLoaderContextAccessor,
            IMetaFieldServiceProvider metaFieldServiceProvider,
            IMetaFieldService metaFieldService,
            IMetaFieldLookupService metaFieldLookupService
            )
        {
            Name = "Navigation";

            Field <StringGraphType, string>()
            .Name("Id")
            .Description("Globally unique identifier, eg: gid://Navigation/1000")
            .Resolve(ctx => ctx.Source.Id);

            Field <StringGraphType, string>()
            .Name("ParentId")
            .Description("Globally unique identifier of parent, 'gid://' if none")
            .Resolve(ctx => ctx.Source.ParentId);

            Field <StringGraphType, string>()
            .Name("Handle")
            .Description("A human-friendly unique string for the navigation")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Handles
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <StringGraphType, string>()
            .Name("Type")
            .Description("The type of the navigation")
            .Resolve(ctx => ctx.Source.Type);

            Field <DateTimeGraphType, DateTime>()
            .Name("CreatedAt")
            .Description("The timestamp of navigation creation")
            .Resolve(ctx => ctx.Source.CreatedAt.ToDateTime());

            Field <DateTimeGraphType, DateTime>()
            .Name("UpdatedAt")
            .Description("The timestamp of the latest navigation update")
            .Resolve(ctx => ctx.Source.UpdatedAt.ToDateTime());

            Field <NavigationLinkGraphType, NavigationLink>()
            .Name("Header")
            .Description("The header link of the navigation")
            .Resolve(ctx => ctx.Source.Header);

            Field <ListGraphType <NavigationLinkGraphType>, IList <NavigationLink> >()
            .Name("Links")
            .Description("The links in the navigation")
            .Resolve(ctx => ctx.Source.Links);

            Field <ListGraphType <SubNavigationGraphType>, IList <SubNavigation> >()
            .Name("SubNavigations")
            .Description("The embedded sub-navigations")
            .Resolve(ctx => ctx.Source.SubNavigations);

            #region Meta-fields

            Field <MetaFieldGraphType, MetaField>()
            .Name("MetaField")
            .Description("Connection to a specific meta-field")
            .Argument <NonNullGraphType <StringGraphType> >("namespace", "Namespace of the meta-field")
            .Argument <NonNullGraphType <StringGraphType> >("name", "Name of the meta-field")
            .ResolveAsync(async ctx =>
            {
                if (!metaFieldServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Meta-fields not supported.");
                }

                var result = await metaFieldService.GetBySearchAsync(
                    ctx.Source.Id,
                    ctx.GetArgument <string>("namespace"),
                    ctx.GetArgument <string>("name"));

                return(result.FirstOrDefault());
            });

            Field <ListGraphType <MetaFieldGraphType>, IList <MetaField> >()
            .Name("MetaFields")
            .Description("Connection to a all meta-fields")
            .ResolveAsync(ctx =>
            {
                if (!metaFieldServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Meta-fields not supported.");
                }

                var loader = dataLoaderContextAccessor.Context
                             .GetOrAddBatchLoader <string, IList <MetaField> >("MetaField.LookupByParentIdsAsync", metaFieldLookupService.LookupByParentIdsAsync);
                return(loader.LoadAsync(ctx.Source.Id));
            });

            #endregion Meta-fields
        }
Пример #20
0
 public MetaFieldLookupService(
     IMetaFieldService metaFieldService)
 {
     _metaFieldService = metaFieldService;
 }
Пример #21
0
 public MetaObjectApp(IMetaObjectRepository metaObjectRepository, IMetaObjectService metaObjectService, IMetaFieldService metaFieldService)
 {
     _metaFieldService     = metaFieldService;
     _metaObjectRepository = metaObjectRepository;
     _metaObjectService    = metaObjectService;
 }
        public ProductGraphType(
            IDataLoaderContextAccessor dataLoaderContextAccessor,
            IMetaFieldServiceProvider metaFieldServiceProvider,
            IMetaFieldService metaFieldService,
            IMetaFieldLookupService metaFieldLookupService,
            ICategoryServiceProvider categoryServiceProvider,
            ICategoryLookupService categoryLookupService,
            IMappingService mappingService
            )
        {
            Name = "Product";

            Field <StringGraphType, string>()
            .Name("Id")
            .Description("Globally unique identifier, eg: gid://Product/1000")
            .Resolve(ctx => ctx.Source.Id);

            Field <StringGraphType, string>()
            .Name("ParentId")
            .Description("Globally unique identifier of parent, 'gid://' if none")
            .Resolve(ctx => ctx.Source.ParentId);

            Field <StringGraphType, string>()
            .Name("Handle")
            .Description("A human-friendly unique string for the product")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Handles
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <StringGraphType, string>()
            .Name("Title")
            .Description("The title of the product")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Titles
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <StringGraphType, string>()
            .Name("Url")
            .Description("The url of the product")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Urls
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <StringGraphType, string>()
            .Name("Type")
            .Description("The type of the product")
            .Resolve(ctx => ctx.Source.Type);

            Field <StringGraphType, string>()
            .Name("Description")
            .Description("The description of the product")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Descriptions
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <DateTimeGraphType, DateTime>()
            .Name("CreatedAt")
            .Description("The timestamp of product creation")
            .Resolve(ctx => ctx.Source.CreatedAt.ToDateTime());

            Field <DateTimeGraphType, DateTime>()
            .Name("UpdatedAt")
            .Description("The timestamp of the latest product update")
            .Resolve(ctx => ctx.Source.UpdatedAt.ToDateTime());

            Field <StringGraphType, string>()
            .Name("PrimaryCategoryId")
            .Description("Globally unique identifier of the primary category the product belong to")
            .Resolve(ctx => ctx.Source.PrimaryCategoryId);

            Field <ListGraphType <StringGraphType>, IList <string> >()
            .Name("CategoryIds")
            .Description("Globally unique identifiers of categories the product belong to")
            .Resolve(ctx => ctx.Source.CategoryIds);

            Field <ListGraphType <ProductVariantGraphType>, IList <ProductVariant> >()
            .Name("Variants")
            .Description("The variants of the product")
            .Resolve(ctx => ctx.Source.Variants
                     .OrderBy(x => x.SortOrder)
                     .ToList());

            Field <ListGraphType <ImageGraphType>, IList <Image> >()
            .Name("Images")
            .Description("The images of the product")
            .Resolve(ctx => ctx.Source.Images);

            Field <ImageGraphType, Image>()
            .Name("PrimaryImage")
            .Description("The primary image of the product")
            .Resolve(ctx =>
            {
                if (ctx.Source.Images.Any())
                {
                    // First image of product
                    return(ctx.Source.Images.First());
                }

                foreach (var productVariant in ctx.Source.Variants)
                {
                    if (productVariant.Images.Any())
                    {
                        // First image of product product
                        return(ctx.Source.Images.First());
                    }
                }

                // No images
                return(null);
            });

            Field <MoneyGraphType, NodaMoney.Money>()
            .Name("UnitPriceFrom")
            .Description("The unit price of the cheapest variant")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                // Join unit prices for currency code and map to NodaMoney, return smallest
                return(mappingService
                       .Map <Proto.Types.Money, NodaMoney.Money>(
                           ctx.Source.Variants
                           .SelectMany(x =>
                                       x.UnitPrices.Where(p => p.CurrencyCode == userContext.CurrencyCode)))
                       .Min());
            });
            #region Meta-fields

            Field <MetaFieldGraphType, MetaField>()
            .Name("MetaField")
            .Description("Connection to a specific meta-field")
            .Argument <NonNullGraphType <StringGraphType> >("namespace", "Namespace of the meta-field")
            .Argument <NonNullGraphType <StringGraphType> >("name", "Name of the meta-field")
            .ResolveAsync(async ctx =>
            {
                if (!metaFieldServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Meta-fields not supported.");
                }

                var result = await metaFieldService.GetBySearchAsync(
                    ctx.Source.Id,
                    ctx.GetArgument <string>("namespace"),
                    ctx.GetArgument <string>("name"));

                return(result.FirstOrDefault());
            });

            Field <ListGraphType <MetaFieldGraphType>, IList <MetaField> >()
            .Name("MetaFields")
            .Description("Connection to a all meta-fields")
            .ResolveAsync(ctx =>
            {
                if (!metaFieldServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Meta-fields not supported.");
                }

                var loader = dataLoaderContextAccessor.Context
                             .GetOrAddBatchLoader <string, IList <MetaField> >("MetaField.LookupByParentIdsAsync", metaFieldLookupService.LookupByParentIdsAsync);
                return(loader.LoadAsync(ctx.Source.Id));
            });

            #endregion Meta-fields

            #region Categories

            Field <CategoryGraphType, Category>()
            .Name("PrimaryCategory")
            .ResolveAsync(ctx =>
            {
                if (!categoryServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Categories not supported.");
                }

                var loader = dataLoaderContextAccessor.Context
                             .GetOrAddBatchLoader <string, Category>("Category.LookupByIdAsync", categoryLookupService.LookupByIdAsync);
                return(loader.LoadAsync(ctx.Source.PrimaryCategoryId));
            });

            Field <ListGraphType <CategoryGraphType>, Category[]>()
            .Name("Categories")
            .ResolveAsync(ctx =>
            {
                if (!categoryServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Categories not supported.");
                }

                var loader = dataLoaderContextAccessor.Context
                             .GetOrAddBatchLoader <string, Category>("Category.LookupByIdAsync", categoryLookupService.LookupByIdAsync);
                return(loader.LoadAsync(ctx.Source.CategoryIds));
            });

            #endregion Categories
        }
Пример #23
0
 public InterfaceSettingApp(IInterfaceConditionService interfaceConditionService, IInterfaceFieldsService interfaceFieldsService, IMetaFieldService metaFieldService)
 {
     _metaFieldService          = metaFieldService;
     _interfaceFieldsService    = interfaceFieldsService;
     _interfaceConditionService = interfaceConditionService;
 }
        public ContentPageGraphType(
            IDataLoaderContextAccessor dataLoaderContextAccessor,
            IMetaFieldServiceProvider metaFieldServiceProvider,
            IMetaFieldService metaFieldService,
            IMetaFieldLookupService metaFieldLookupService,
            IContentPageService contentPageService,
            IContentPageLookupService contentPageLookupService
            )
        {
            Name = "ContentPage";

            Field <StringGraphType, string>()
            .Name("Id")
            .Description("Globally unique identifier, eg: gid://ContentPage/1000")
            .Resolve(ctx => ctx.Source.Id);

            Field <StringGraphType, string>()
            .Name("ParentId")
            .Description("Globally unique identifier of parent, 'gid://' if none")
            .Resolve(ctx => ctx.Source.ParentId);

            Field <StringGraphType, string>()
            .Name("Handle")
            .Description("A human-friendly unique string for the content page")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Handles
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <StringGraphType, string>()
            .Name("Title")
            .Description("The title of the content page")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Titles
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <StringGraphType, string>()
            .Name("Url")
            .Description("The url of the content page")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Urls
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <StringGraphType, string>()
            .Name("Type")
            .Description("The type of the content page")
            .Resolve(ctx => ctx.Source.Type);

            Field <StringGraphType, string>()
            .Name("Description")
            .Description("The description of the content page")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Descriptions
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <DateTimeGraphType, DateTime>()
            .Name("CreatedAt")
            .Description("The timestamp of content page creation")
            .Resolve(ctx => ctx.Source.CreatedAt.ToDateTime());

            Field <DateTimeGraphType, DateTime>()
            .Name("UpdatedAt")
            .Description("The timestamp of the latest content page update")
            .Resolve(ctx => ctx.Source.UpdatedAt.ToDateTime());

            Field <ImageGraphType, Image>()
            .Name("PrimaryImage")
            .Description("The primary image of the content page")
            .Resolve(ctx => ctx.Source.PrimaryImage);

            #region Meta-fields

            Field <MetaFieldGraphType, MetaField>()
            .Name("MetaField")
            .Description("Connection to a specific meta-field")
            .Argument <NonNullGraphType <StringGraphType> >("namespace", "Namespace of the meta-field")
            .Argument <NonNullGraphType <StringGraphType> >("name", "Name of the meta-field")
            .ResolveAsync(async ctx =>
            {
                if (!metaFieldServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Meta-fields not supported.");
                }

                var result = await metaFieldService.GetBySearchAsync(
                    ctx.Source.Id,
                    ctx.GetArgument <string>("namespace"),
                    ctx.GetArgument <string>("name"));

                return(result.FirstOrDefault());
            });

            Field <ListGraphType <MetaFieldGraphType>, IList <MetaField> >()
            .Name("MetaFields")
            .Description("Connection to a all meta-fields")
            .ResolveAsync(ctx =>
            {
                if (!metaFieldServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Meta-fields not supported.");
                }

                var loader = dataLoaderContextAccessor.Context
                             .GetOrAddBatchLoader <string, IList <MetaField> >("MetaField.LookupByParentIdsAsync", metaFieldLookupService.LookupByParentIdsAsync);
                return(loader.LoadAsync(ctx.Source.Id));
            });

            #endregion Meta-fields

            #region Content pages

            Field <ContentPageGraphType, ContentPage>()
            .Name("Parent")
            .ResolveAsync(ctx =>
            {
                if (string.IsNullOrEmpty(ctx.Source.ParentId))
                {
                    return(null);
                }

                var loader = dataLoaderContextAccessor.Context
                             .GetOrAddBatchLoader <string, ContentPage>("ContentPage.LookupByIdAsync", contentPageLookupService.LookupByIdAsync);
                return(loader.LoadAsync(ctx.Source.ParentId));
            });
            Connection <ContentPageGraphType>()
            .Name("Children")
            .Unidirectional()
            .Argument <StringGraphType>("query", "The search query to filter children by")
            .Argument <ContentPageSortKeyGraphType>("sortKey", "The key to sort the underlying list by")
            .Argument <StringGraphType>("reverse", "Reverse the order of the underlying list")
            .ResolveAsync(async ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                var result = await contentPageService.GetBySearchAsync(
                    ctx.GetArgument <string>("query"),
                    userContext.LanguageCode,
                    ctx.Source.Id,
                    ctx.GetArgument <string>("after"),
                    ctx.GetArgument <int>("first", 24),
                    ctx.GetArgument <ContentPageSortKey>("sortKey"),
                    ctx.GetArgument <bool>("reverse"));

                return(result.ToGraphConnection());
            });

            #endregion Content pages
        }
Пример #25
0
        public ProductVariantGraphType(
            IDataLoaderContextAccessor dataLoaderContextAccessor,
            IMetaFieldServiceProvider metaFieldServiceProvider,
            IMetaFieldService metaFieldService,
            IMetaFieldLookupService metaFieldLookupService,
            IMappingService mappingService
            )
        {
            Name = "ProductVariant";

            Field <StringGraphType, string>()
            .Name("Id")
            .Description("Globally unique identifier, eg: gid://ProductVariant/1000")
            .Resolve(ctx => ctx.Source.Id);

            Field <StringGraphType, string>()
            .Name("ProductId")
            .Description("Globally unique identifier of the parent product")
            .Resolve(ctx => ctx.Source.ProductId);

            Field <StringGraphType, string>()
            .Name("Title")
            .Description("The title of the product variant")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(ctx.Source.Titles
                       .FirstOrDefault(x => x.LanguageCode == userContext.LanguageCode)
                       ?.Value);
            });

            Field <StringGraphType, string>()
            .Name("Sku")
            .Description("The stock keeping unit of the product variant")
            .Resolve(ctx => ctx.Source.Sku);

            Field <MoneyGraphType, NodaMoney.Money>()
            .Name("UnitPrice")
            .Description("The unit price of the product variant")
            .Resolve(ctx =>
            {
                var userContext = (StorefrontGraphUserContext)ctx.UserContext;

                return(mappingService
                       .Map <Proto.Types.Money, NodaMoney.Money>(
                           ctx.Source.UnitPrices.FirstOrDefault(p => p.CurrencyCode == userContext.CurrencyCode)));
            });

            Field <ListGraphType <ImageGraphType>, IList <Image> >()
            .Name("Images")
            .Description("The images of the product variant")
            .Resolve(ctx => ctx.Source.Images);

            Field <ImageGraphType, Image>()
            .Name("PrimaryImage")
            .Description("The primary image of the product variant")
            .Resolve(ctx => ctx.Source.Images.FirstOrDefault());

            #region Meta-fields

            Field <MetaFieldGraphType, MetaField>()
            .Name("MetaField")
            .Description("Connection to a specific meta-field")
            .Argument <NonNullGraphType <StringGraphType> >("namespace", "Namespace of the meta-field")
            .Argument <NonNullGraphType <StringGraphType> >("name", "Name of the meta-field")
            .ResolveAsync(async ctx =>
            {
                if (!metaFieldServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Meta-fields not supported.");
                }

                var result = await metaFieldService.GetBySearchAsync(
                    ctx.Source.Id,
                    ctx.GetArgument <string>("namespace"),
                    ctx.GetArgument <string>("name"));

                return(result.FirstOrDefault());
            });

            Field <ListGraphType <MetaFieldGraphType>, IList <MetaField> >()
            .Name("MetaFields")
            .Description("Connection to a all meta-fields")
            .ResolveAsync(ctx =>
            {
                if (!metaFieldServiceProvider.IsEnabled)
                {
                    throw new ExecutionError("Meta-fields not supported.");
                }

                var loader = dataLoaderContextAccessor.Context
                             .GetOrAddBatchLoader <string, IList <MetaField> >("MetaField.LookupByParentIdsAsync", metaFieldLookupService.LookupByParentIdsAsync);
                return(loader.LoadAsync(ctx.Source.Id));
            });

            #endregion Meta-fields
        }