New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content mutations #70

Closed
wants to merge 13 commits into
base: dev
from

Conversation

Projects
None yet
1 participant
@bdunogier
Copy link
Owner

bdunogier commented Nov 14, 2018

Adds support for creating, updating and deleting content over GraphQL.

For each content type:

  • two mutations are defined create{ContentType} (createBlogPost, createImage, ...) and update{ContentType} (updatePlace, updateVideo, ...)
  • two input types are defined, one for each operation: updateArticleInput, createImageInput

Usage:

mutation CreateMyBlogPost
{
  createBlogPost(
    parentLocationId: 216,
    input: {
      title: "The post's title",
      author: [
        {name: "Bertrand Dunogier", email: "noemail@ez.no"}
      ],
      body: {
        format: html,
        input: "<h1>title</h1><p>paragraph</p>"
      }
    } 
  ) {
    _info { id mainLocationId }
    title
    body { html5 }
  }
}

bdunogier added some commits Nov 2, 2018

Added deleteContent mutation
```
mutation deleteBlogPost
{
  deleteContent(contentId: 256) {
    id
    contentId
  }
}
```

or

```
mutation deleteBlogPost
{
  deleteContent(id: "QmxvZ1Bvc3RDb250ZW50OjI1Ng==") {
    id
    contentId
  }
}
```
Implemented update domain content mutation
Example:

```
mutation updateBlogPost(
  $id: ID!,
  $input: BlogPostContentInput!
) {
  updateBlogPost(id: $id, input: $input) {
    _info { id currentVersionNo }
    title
  }
}
```

The input is like the create one, but without any mandatory field.

A versionNo argument is supported:
- if not specified, a draft is created from the current version
- if specified, it depends on the version's status:
  - if it is a draft, it is used for the update.
  - if it is an archived or published, it is used to create a draft

Then the draft gets published immediately.
Prototyped file upload for ezimage
Example with curl (required, graphiql won't let you upload files):

```
curl -v -X POST \
  http://localhost:8000/graphql \
  -H 'Cookie: eZSESSIDWhatever=cookievalue' \
  -F 'operations={"query":"mutation CreateImage($name: String!, $alternativeText: String!, $file: ImageUpload!) { createImage( parentLocationId: 51, input: { name: $name, image: {alternativeText: $alternativeText, file: $file} } ) { _info { id mainLocationId } name image { fileName alternativeText uri } } }","variables":{"file": null, "name": "2nd image upload", "alternativeText": "With generated schema"}}' \
  -F 'map={"0":["variables.file"]}' \
  -F "0"=@/Users/bdunogier/Desktop/screenshot.png
```
Drafted richtext html input
```
mutation CreateBlogPost {
  createBlogPost(
    parentLocationId: 2,
    input: {
      title: "The blog post's title",
      author: [
        {name: "John Doe", email: "johndoe@unknown.net"}
      ],
      body: {
        format: "html",
        input: "<h1>title</h1><p>A paragraph</p><p>Another <b>paragraph</b></p>"
      }
    }
  ) {
    _info { id mainLocationId }
    title
    body { html5 }
  }
}
```
Drafted multi-upload of files into a container
```
mutation BunchOfImages($files: [ImageUpload]!) {
  uploadFiles(locationId: 51, files: $files) {
    files {
      ... on ImageContent {
        name
        image {
          uri
        }
      }
    }
    warnings
  }
}
```

```
curl -v -X POST \
  http://localhost:8000/graphql \
  -H 'Cookie: eZSESSID98defd6ee70dfb1dea416cecdf391f58=1ei7ecn4vu4afdk9hk0k67kme2' \
  -F 'operations={"query":"mutation BunchOfImages($files: [ImageUpload]!) { uploadFiles( locationId: 51, files: $files ) { files { ... on ImageContent { name image { uri } } } warnings } }","variables":{"files": [null, null, null]}}' \
  -F 'map={"0":["variables.files.0"], "1":["variables.files.1"], "2":["variables.files.2"]}' \
  -F "0"=@/Users/bdunogier/Desktop/screenshot.png \
  -F "1"=@/Users/bdunogier/Downloads/Arya.jpg \
  -F "2"=@/Users/bdunogier/Downloads/20181003_182928.jpg
```

@bdunogier bdunogier added this to the 0.5 milestone Nov 14, 2018

@bdunogier

This comment has been minimized.

Copy link
Owner Author

bdunogier commented Jan 24, 2019

@bdunogier bdunogier closed this Jan 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment