/// <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 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)); }