public AppMutationsGraphType(IGraphModel model, IEnumerable <ISchemaEntity> schemas) { foreach (var schema in schemas) { var schemaId = schema.NamedId(); var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); var contentType = model.GetContentType(schema.Id); var contentDataType = model.GetContentDataType(schema.Id); var resultType = new ContentDataChangedResultGraphType(schemaType, schemaName, contentDataType); var inputType = new ContentDataGraphInputType(model, schema); AddContentCreate(schemaId, schemaType, schemaName, inputType, contentDataType, contentType); AddContentUpdate(schemaType, schemaName, inputType, resultType); AddContentPatch(schemaType, schemaName, inputType, resultType); AddContentPublish(schemaType, schemaName); AddContentUnpublish(schemaType, schemaName); AddContentArchive(schemaType, schemaName); AddContentRestore(schemaType, schemaName); AddContentDelete(schemaType, schemaName); } Description = "The app mutations."; }
private void AddContentPatch(string schemaType, string schemaName, ContentDataGraphInputType inputType, IComplexGraphType resultType) { AddField(new FieldType { Name = $"patch{schemaType}Content", Arguments = new QueryArguments { new QueryArgument(AllTypes.None) { Name = "id", Description = $"The id of the {schemaName} content (GUID)", DefaultValue = string.Empty, ResolvedType = AllTypes.NonNullGuid }, new QueryArgument(AllTypes.None) { Name = "data", Description = $"The data for the {schemaName} content.", DefaultValue = null, ResolvedType = new NonNullGraphType(inputType), }, new QueryArgument(AllTypes.None) { Name = "expectedVersion", Description = "The expected version", DefaultValue = EtagVersion.Any, ResolvedType = AllTypes.Int } }, ResolvedType = new NonNullGraphType(resultType), Resolver = ResolveAsync(async(c, publish) => { var contentId = c.GetArgument <Guid>("id"); var contentData = GetContentData(c); var command = new PatchContent { ContentId = contentId, Data = contentData }; var commandContext = await publish(command); var result = commandContext.Result <ContentDataChangedResult>(); return(result); }), Description = $"Patch a {schemaName} content." }); }
private void AddContentCreate(NamedId <Guid> schemaId, string schemaType, string schemaName, ContentDataGraphInputType inputType, IComplexGraphType contentDataType, IComplexGraphType contentType) { AddField(new FieldType { Name = $"create{schemaType}Content", Arguments = new QueryArguments { new QueryArgument(AllTypes.None) { Name = "data", Description = $"The data for the {schemaName} content.", DefaultValue = null, ResolvedType = new NonNullGraphType(inputType), }, new QueryArgument(AllTypes.None) { Name = "publish", Description = "Set to true to autopublish content.", DefaultValue = false, ResolvedType = AllTypes.Boolean }, new QueryArgument(AllTypes.None) { Name = "expectedVersion", Description = "The expected version", DefaultValue = EtagVersion.Any, ResolvedType = AllTypes.Int } }, ResolvedType = new NonNullGraphType(contentType), Resolver = ResolveAsync(async(c, publish) => { var argPublish = c.GetArgument <bool>("publish"); var contentData = GetContentData(c); var command = new CreateContent { SchemaId = schemaId, Data = contentData, Publish = argPublish }; var commandContext = await publish(command); var result = commandContext.Result <EntityCreatedResult <NamedContentData> >(); var response = ContentEntity.Create(command, result); return((IContentEntity)ContentEntity.Create(command, result)); }), Description = $"Creates an {schemaName} content." }); }