/// <summary> /// Populates the type with ck related attributes and associations /// </summary> /// <param name="entityDtoCache">The entity type cache</param> /// <param name="entityCacheItem">The cache item</param> public void Populate(IGraphTypesCache entityDtoCache, EntityCacheItem entityCacheItem) { AddConstructionKit(entityCacheItem); foreach (var attribute in entityCacheItem.Attributes.Values) { AddAttribute(attribute); } foreach (var cacheItems in entityCacheItem.OutboundAssociations) { var allowedTypes = cacheItems.Value.SelectMany(x => x.AllowedTypes).ToList(); string name = cacheItems.Key; if (!allowedTypes.Any()) { continue; // All Ck entities are abstract for that associations } this.AssociationField(entityDtoCache, name, allowedTypes.Select(x => x.CkId).Distinct().ToList(), cacheItems.Value.First().RoleId, GraphDirections.Outbound); } foreach (var cacheItems in entityCacheItem.InboundAssociations) { var allowedTypes = cacheItems.Value.SelectMany(x => x.AllowedTypes).ToList(); string name = cacheItems.Key; if (!allowedTypes.Any()) { continue; // All Ck entities are abstract for that associations } this.AssociationField(entityDtoCache, name, allowedTypes.Select(x => x.CkId).Distinct().ToList(), cacheItems.Value.First().RoleId, GraphDirections.Inbound); } }
/// <summary> /// Constructor /// </summary> /// <param name="entityCacheItems">List of CkEntities for RT generation</param> /// <param name="graphTypesCache">The cache</param> /// <param name="ckCache"></param> public OspMutation(IEnumerable <EntityCacheItem> entityCacheItems, IGraphTypesCache graphTypesCache, ICkCache ckCache) { _ckCache = ckCache; foreach (var cacheItem in entityCacheItems) { var inputType = graphTypesCache.GetOrCreateInput(cacheItem.CkId); var outputType = graphTypesCache.GetOrCreate(cacheItem.CkId); var createArgument = new QueryArgument(new NonNullGraphType(new ListGraphType(inputType))) { Name = Statics.EntitiesArg }; var updateArgument = new QueryArgument(new NonNullGraphType(new ListGraphType(new UpdateMutationDtoType <RtEntityDto>(inputType)))) { Name = Statics.EntitiesArg }; var deleteArgument = new QueryArgument(new NonNullGraphType(new ListGraphType(new DeleteMutationDtoType(inputType)))) { Name = Statics.EntitiesArg }; this.FieldAsync($"create{outputType.Name}s", $"Creates new entities of type '{outputType.Name}'.", new ListGraphType(outputType), new QueryArguments(createArgument), resolve: ResolveCreate) .AddMetadata(Statics.CkId, cacheItem.CkId); this.FieldAsync($"update{outputType.Name}s", $"Updates existing entity of type '{outputType.Name}'.", new ListGraphType(outputType), new QueryArguments(updateArgument), resolve: ResolveUpdate) .AddMetadata(Statics.CkId, cacheItem.CkId); this.FieldAsync($"delete{outputType.Name}s", $"Deletes an entity of type '{outputType.Name}'.", new BooleanGraphType(), new QueryArguments(deleteArgument), resolve: ResolveDelete) .AddMetadata(Statics.CkId, cacheItem.CkId); } }
public RtEntityAssociationType(string name, string description, IGraphTypesCache entityDtoCache, IEnumerable <RtEntityDtoType> rtEntityDtoTypes, string roleId, GraphDirections graphDirection) { ArgumentValidation.ValidateString(nameof(name), name); ArgumentValidation.ValidateString(nameof(description), description); Name = name; Description = description; foreach (var rtEntityDtoType in rtEntityDtoTypes) { this.Connection <object, IGraphType, RtEntityDto>(entityDtoCache, rtEntityDtoType, rtEntityDtoType.Name) .AddMetadata(Statics.CkId, rtEntityDtoType.CkId) .AddMetadata(Statics.RoleId, roleId) .AddMetadata(Statics.GraphDirection, graphDirection) .Argument <OspObjectIdType>(Statics.RtIdArg, "Returns the entity with the given rtId.") .Argument <ListGraphType <OspObjectIdType> >(Statics.RtIdsArg, "Returns entities with the given rtIds.") .Argument <SearchFilterDtoType>(Statics.SearchFilterArg, "Filters items based on text search") .Argument <ListGraphType <SortDtoType> >(Statics.SortOrderArg, "Sort order for items") .Argument <ListGraphType <FieldFilterDtoType> >(Statics.FieldFilterArg, "Filters items based on field compare") .ResolveAsync(ResolveRtEntitiesQuery); } }
public static FieldType AssociationField <TSourceType>( this ComplexGraphType <TSourceType> _this, IGraphTypesCache graphTypesCache, string name, IReadOnlyList <string> allowedTypes, string roleId, GraphDirections graphDirection) { var graphTypes = allowedTypes.Select(ckId => graphTypesCache.GetOrCreate(ckId)); var unionType = new RtEntityAssociationType( $"{_this.Name}_{name}{CommonConstants.GraphQlUnionSuffix}", $"Association {roleId} ({graphDirection}) of entity type {_this.Name}", graphTypesCache, graphTypes, roleId, graphDirection); return(_this.Field(name, null, unionType, resolve: context => context.Source)); }
/// <summary> /// Constructor /// </summary > /// <param name="entityDtoCache">The cache of a RtEntityTypes that is build </param> /// <param name="rtEntityDtoTypes">List of RT entities accessible as query</param> public OspQuery(IGraphTypesCache entityDtoCache, IEnumerable <RtEntityDtoType> rtEntityDtoTypes) { Name = "OspQuery"; Connection <CkEntityDtoType>() .Argument <StringGraphType>(Statics.CkIdArg, "Returns the construction kit type with the given id.") .Argument <ListGraphType <StringGraphType> >(Statics.CkIdsArg, "Returns the construction kit types with the given ids.") .Argument <SearchFilterDtoType>(Statics.SearchFilterArg, "Filters items based on text search") .Argument <ListGraphType <SortDtoType> >(Statics.SortOrderArg, "Sort order for items") .Argument <ListGraphType <FieldFilterDtoType> >(Statics.FieldFilterArg, "Filters items based on field compare") .Name("ConstructionKitTypes") .Resolve(ResolveCkEntitiesQuery); Connection <CkAttributeDtoType>() .Argument <StringGraphType>(Statics.AttributeIdArg, "Returns the entity with the given attribute id.") .Argument <ListGraphType <StringGraphType> >(Statics.AttributeIdsArg, "Returns entities with the given attribute ids.") .Argument <SearchFilterDtoType>(Statics.SearchFilterArg, "Filters items based on text search") .Argument <ListGraphType <SortDtoType> >(Statics.SortOrderArg, "Sort order for items") .Argument <ListGraphType <FieldFilterDtoType> >(Statics.FieldFilterArg, "Filters items based on field compare") .Name("ConstructionKitAttributes") .Resolve(ResolveCkAttributesQuery); Connection <RtEntityGenericDtoType>() .Argument <StringGraphType>(Statics.CkIdArg, "The construction kit type with the given id.") .Argument <OspObjectIdType>(Statics.RtIdArg, "Returns the entity with the given rtId.") .Argument <ListGraphType <OspObjectIdType> >(Statics.RtIdsArg, "Returns entities with the given rtIds.") .Argument <SearchFilterDtoType>(Statics.SearchFilterArg, "Filters items based on text search") .Argument <ListGraphType <SortDtoType> >(Statics.SortOrderArg, "Sort order for items") .Argument <ListGraphType <FieldFilterDtoType> >(Statics.FieldFilterArg, "Filters items based on field compare") .Name("RuntimeEntities") .ResolveAsync(ResolveGenericRtEntitiesQuery); foreach (var rtEntityDtoType in rtEntityDtoTypes) { this.Connection <object, IGraphType, RtEntityDto>(entityDtoCache, rtEntityDtoType, rtEntityDtoType.Name) .AddMetadata(Statics.CkId, rtEntityDtoType.CkId) .Argument <OspObjectIdType>(Statics.RtIdArg, "Returns the entity with the given rtId.") .Argument <ListGraphType <OspObjectIdType> >(Statics.RtIdsArg, "Returns entities with the given rtIds.") .Argument <SearchFilterDtoType>(Statics.SearchFilterArg, "Filters items based on text search") .Argument <ListGraphType <SortDtoType> >(Statics.SortOrderArg, "Sort order for items") .Argument <ListGraphType <FieldFilterDtoType> >(Statics.FieldFilterArg, "Filters items based on field compare") .ResolveAsync(ResolveRtEntitiesQuery); } }
public static ConnectionBuilder <TSourceType> Connection <TNodeType, TGraphType, TSourceType>( this ComplexGraphType <TNodeType> _this, IGraphTypesCache entityDtoCache, TGraphType itemType, string prefixName) where TGraphType : IGraphType { var type = entityDtoCache.GetOrCreateConnection(itemType, prefixName); var connectionBuilder = ConnectionBuilder <TSourceType> .Create <TGraphType>( $"{prefixName}{CommonConstants.GraphQlConnectionSuffix}"); connectionBuilder.FieldType.ResolvedType = type; _this.AddField(connectionBuilder.FieldType); return(connectionBuilder); }