hasura / go-graphql-client

Package graphql provides a GraphQL client implementation.
MIT License
405 stars 94 forks source link

Mutation query issues #72

Closed sridharchary closed 1 year ago

sridharchary commented 1 year ago

mutation query in graphql working fine mutation createQuestion($data:QuestionInput!) { createQuestion(data: $data) { data{ id attributes{ title description question_id } } } } mutation query in golang client var respData struct { CreateQuestion struct { Data []struct { ID graphql.ID Attributes struct { Question_id graphql.String Title graphql.String Description graphql.String } } } } passing data Like this variables := map[string]interface{}{ "data": map[string]interface{}{ "title": "My testFirst FbPost", "description": "dfsdf is the body of my first post.", "question_id": "35005", }, }

It's gives Error when passing to server Strapi CMS server

GRAPHQL_PARSE_FAILED Syntax Error: Expected Name, found

hgiasac commented 1 year ago

Please take a look at the documentation here You need to define the input type so the GraphQL client can use reflection to infer it.


type QuestionInput map[string]interface{} 
variables := map[string]interface{}{ 
  "data": QuestionInput { 
    "title":       "My testFirst FbPost", 
    "description": "dfsdf is the body of my first post.", 
    "question_id": "35005",   
  }, 
}
sridharchary commented 1 year ago

Thanks a lot @hgiasac I am able to solve the issue now.