Home > Enterprise >  Why does graphql not accept the parameters that I pass in the query?
Why does graphql not accept the parameters that I pass in the query?

Time:10-04

I'm doing a practice with this library enter image description here

mutation addPst($post: PostInput!){
    createPost(post: $post) {   
        title       
    }
}

Query variables:

{
    "post": {
    "id": "100",
        "title": "Curso de GraphQL",
        "views": 0,
        "user_id": 123  
    }
}

Example: https://stackblitz.com/edit/json-graphql-server-nmctdj

CodePudding user response:

Your mutation doesn't seem to be in line with the schema documentation you have posted.

The schema shows that the createPost mutation takes title, views and ID fields whereas you're passing in a "post" object.

Try rewriting the mutation as:

mutation addPst($title: String!, $views: Int!, $user_id: ID!){
    createPost(title: $title, views: $views, user_id: $user_id) {   
        title       
    }
}
  • Related