Graphql查询错误与'未知类型Int'使用Apollo Client和graphql-go

时间:2018-05-06 21:28:52

标签: go graphql apollo

我已经使用graphql-go实现了一个graphql服务器,并且我在前端使用了Apollo。没有参数的简单查询和使用输入对象类型的突变工作正常,但由于某种原因,在查询中传递标量类型参数会返回错误:

[{"message":"Unknown type \"Int\".","locations":[{"line":1,"column":19}]}]

我的使用不可能更简单;在客户端,我的查询是:

export const GET_CLIENT = gql`
  query client($id: Int) {
  client(id: $id) {
    id
    name
  }
}`

用于像这样的组件:

<Query
  query={GET_CLIENT}
  variables={{
    id: 1
  }} />

在后端解析为此字段:

// ClientQuery takes an ID and returns one client or nil
var ClientQuery = &graphql.Field{
Type: ClientType,
Args: graphql.FieldConfigArgument{
    "id": &graphql.ArgumentConfig{
        Type: graphql.Int,
    },
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
    return p.Context.Value("service").(*model.Service).FindClientByID(id)
},
}

我尝试过传递输入对象,字符串等,但似​​乎后端没有满足查询参数,标量或其他内容。我已经尝试了graphql-go的master和v0.7.5。我错过了什么吗?非常感谢,对于这样一个基本成为如此巨大阻碍的东西感到奇怪。

2 个答案:

答案 0 :(得分:0)

我通过将ID的变量类型从 mysql_connect("localhost", "root", "password") or die(mysql_error()); mysql_select_db("information_schema") or die(mysql_error()); $query1 = "SELECT 'UPDATE_TIME' FROM 'TABLES' WHERE 'TABLE_SCHEMA' LIKE 'demo' AND 'TABLE_NAME' LIKE 'usc'"; $result1 = mysql_query($query1) or die(mysql_error()); while($row = mysql_fetch_array($result1)) { echo "<font color='red'>&nbsp; (Last update : ".$row['UPDATE_TIME'].")</font>"; 更改为Int

来解决了这个问题

答案 1 :(得分:0)

正如另一篇提到必须从 int 转为 float 的帖子,发生此错误是因为在您的 graphQL 架构中设置的类型与您在查询时尝试使用的类型相冲突。

它的意思是:'Unknown type Int'

但它真正的意思是:'预期类型为 Float 但得到 Int' 然后你会在错误的地方更改它。