为什么';当从GO触发时,我的GraphQL查询是否返回正确的结果?

为什么';当从GO触发时,我的GraphQL查询是否返回正确的结果?,go,graphql,hasura,graphql-go,Go,Graphql,Hasura,Graphql Go,我对Hasura/Graphql和GO都是新手。我已经成功地编写了几个Hasura操作,这些操作由GO服务器支持,GO服务器反过来调用Hasura服务器来运行查询。这两种方法都有效。由于某种原因,第三个没有,我不明白为什么。我的GO服务器没有任何错误。它不会返回与直接在Hasura GraphiQL中运行查询相同的结果,如果有人能提供帮助,我将不胜感激 我定义了一个动作,如下所示- type Query { lookupCostCentreLocalDB (arg1: InputCostCent

我对Hasura/Graphql和GO都是新手。我已经成功地编写了几个Hasura操作,这些操作由GO服务器支持,GO服务器反过来调用Hasura服务器来运行查询。这两种方法都有效。由于某种原因,第三个没有,我不明白为什么。我的GO服务器没有任何错误。它不会返回与直接在Hasura GraphiQL中运行查询相同的结果,如果有人能提供帮助,我将不胜感激

我定义了一个动作,如下所示-

type Query {
lookupCostCentreLocalDB (arg1: InputCostCentreAndId!): ValidCostCentreDtl
}
 
input InputCostCentreAndId {costCentre : String! altId : String!
}

type ValidCostCentreDtl {validCostCentre : String!
}
type QueryLookupGLWCostCentre struct {
     Data struct {
          GLWGLMAP []struct {
                     C3CostCentre string json:"C3_Cost_Centre"
          } json:"GLW_GL_MAP"
     } json:"data"
}
当我从Hasura GraphiQL运行以下查询时,它工作得很好

query {GLW_GL_MAP (where: {_and: [{C3_Cost_Centre: {_eq: "8106"}},{idAlt: {_eq: 2}}]}){C3_Cost_Centre}}
并返回一个成本中心

该操作触发MyGo服务器,该服务器构建相同的查询,插入参数并将其发送到Hasura URL

query lookingUpCCLocalDB_Test_True {
lookupCostCentreLocalDB (arg1: {costCentre: "8106" altId: "2"}) {ValidCostCentreDtl: validCostCentre}
}
但它返回一个不同的结果——在本例中,它不返回成本中心。对Hasura的调用如下所示

//Prepare the HTTP Request
url := "http://localhost:8080/v1/graphql"
respRqst, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonQueryStr))

if err != nil {
   fmt.Println("Error from http.NewRequest - err =", err)
   panic(err)
}

fmt.Println("jsonQueryStr=", jsonQueryStr)
fmt.Println("respRqst=", respRqst)

respRqst.Header.Set("Content-Type", "application/json")

//Action the HTTP Request
client := http.Client{}
resp, err := client.Do(respRqst)
if err != nil {
   fmt.Println("Error from client.Do - err =", err)
   panic(err)
}
 
fmt.Println("resp=", resp)

//Close the HTTP Request when this function returns to ensure that it is always closed
defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
   bodyBytes, err = ioutil.ReadAll(resp.Body)
   if err != nil {
      fmt.Println("Error ioutil.ReadAll(resp.Body)")
      panic(err)
   }
return bodyBytes, nil
}
Println语句的结果是(第一项是传递给http请求的[]字节变量的显示,是以[]字节为单位的查询)

以下是答复的细目

//Extract the data returned into the QueryResult data structure
var queryResult QueryLocalGLWCostCentre
err = json.Unmarshal(bodyBytes, &queryResult)
if err != nil {
   fmt.Println("Unmarshal queryResult failed")
   panic(err)
}

fmt.Println("bodyBytes =:", bodyBytes, "RESULT Length: ", len(queryResult.Data.GLWGLMAP), "queryResult=", queryResult, "queryResult.Data.GLWGLMAP=", queryResult.Data.GLWGLMAP)
以下是上述声明打印的内容

bodyBytes =: [123 34 101 114 114 111 114 115 34 58 91 123 34 101 120 116 101 110 115 105 111 110 115 34
58 123 34 112 97 116 104 34 58 34 36 34 44 34 99 111 100 101 34 58 34 105 110 118 97 108 105 100 45 106
115 111 110 34 125 44 34 109 101 115 115 97 103 101 34 58 34 69 114 114 111 114 32 105 110 32 36 58 32
70 97 105 108 101 100 32 114 101 97 100 105 110 103 58 32 115 97 116 105 115 102 121 46 32 69 120 112 
101 99 116 105 110 103 32 39 44 39 32 111 114 32 39 125 39 32 97 116 32 39 56 49 48 54 125 125 44 123 
105 100 65 108 116 58 123 95 101 113 58 50 125 125 93 125 41 123 67 51 95 67 111 115 116 95 67 101 110 
116 114 101 125 125 125 39 34 125 93 125] RESULT Length: 0 queryResult= {{[]}} 
queryResult.Data.GLWGLMAP= []
我的回答结构如下-

type Query {
lookupCostCentreLocalDB (arg1: InputCostCentreAndId!): ValidCostCentreDtl
}
 
input InputCostCentreAndId {costCentre : String! altId : String!
}

type ValidCostCentreDtl {validCostCentre : String!
}
type QueryLookupGLWCostCentre struct {
     Data struct {
          GLWGLMAP []struct {
                     C3CostCentre string json:"C3_Cost_Centre"
          } json:"GLW_GL_MAP"
     } json:"data"
}
有人能提供我问题的线索吗


关于

我通过使用以下过程为Hasura服务器构建所需的查询,成功地解决了我的问题

//Set up the query template to use
fullQueryOriginalTemplate := `{"query": "query C3MS_query {GLW_GL_MAP (where: {_and: [{C3_Cost_Centre: {_eq: \":1\"}},{id: {_eq: \":2\"}}]}){C3_Cost_Centre}}"}`

//Replace the parameters with the supplied values
fullQueryInterim := strings.Replace(fullQueryOriginalTemplate, ":1", costCentre, -1)
fullQuery := strings.Replace(fullQueryInterim, ":2", strconv.Itoa(id), -1)