requarks / wiki

Wiki.js | A modern and powerful wiki app built on Node.js
https://js.wiki
GNU Affero General Public License v3.0
24.95k stars 2.76k forks source link

graphql update page mutation: Cannot read property 'map' of undefined #2702

Closed triffid closed 3 years ago

triffid commented 4 years ago

Describe the bug Getting " Cannot read property 'map' of undefined" for page update mutations

To Reproduce Feeding

mutation {
    pages {
        update (id:2, content:"This page edited via API") {
            responseResult {
                errorCode,
                message,
                succeeded,
                slug
            }
        }
    }
}

into https://my-wiki-host/graphql via web browser gives me

{
    "data": {
        "pages": {
            "update": {
                "responseResult": {
                    "errorCode": 1,
                    "message": "Cannot read property 'map' of undefined",
                    "succeeded": false,
                    "slug": "TypeError"
                }
            }
        }
    }
}

Which seems like either an internal error, or a message that's just as obtuse as the one that appears when I forget to put the authorization token into http headers.

Expected behavior Either page text gets changed, or receive a meaningful error message that suggests the proper way to do it.

Host Info (please complete the following information):

Additional context I'm having a terrible time trying to find any documentation for this API - seems like there's a machine-readable schema but no tutorials or examples anywhere, so I'm left stumbling about in the dark trying to guess what query format I need to do what I want.

NGPixel commented 4 years ago

The API is self-documented using GraphQL. You can go to /graphql on your installation to launch the GraphQL Playground. You can build queries from there and see the full documentation on the right.

triffid commented 4 years ago

A list of functions and parameters is hardly documentation, and it offers zero clue why I might be getting "Cannot read property 'map' of undefined" back from the server for what seems like a fairly simple query.

a-stoyanov commented 3 years ago

I've also ran across this issue and it seems to be a bug. It goes away when you declare the id argument as a Int! type variable and pass it to the mutation like so:

mutation Page(
  $id: Int!
  $content: String!
  $description: String!
  $tags: [String]!
  $title: String!
  $isPublished: Boolean!
) {
  pages {
    update(
      id: $id
      content: $content
      description: $description
      tags: $tags
      title: $title
      isPublished: $isPublished
    ) {
      responseResult {
        succeeded
        errorCode
        slug
        message
      }
      page {
        id
        path
        title
      }
    }
  }
}

VARS

{
"id": 21, 
"content": "HELLO WORLD!",
"title": "page title",
"description": "page description",
"tags": ["patching", "maintenance"],
"isPublished": true
}