GoLang GraphQL无法区分nil指针和nil文字

GoLang GraphQL无法区分nil指针和nil文字,go,graphql,Go,Graphql,在我的GoLang GraphQL查询中,我有以下方法(获取用户id并返回配置文件数据): 当用户id无效时,db.GetUserProfile返回nil指针u和nil错误err,但GraphQL响应如下: { "data": { "userProfile": null }, "errors": [ { "message": "runtime error: invalid memory address or nil pointer dereference"

在我的GoLang GraphQL查询中,我有以下方法(获取用户id并返回配置文件数据):

当用户id无效时,
db.GetUserProfile
返回nil指针
u
和nil错误
err
,但GraphQL响应如下:

{
"data": { "userProfile": null },
"errors": [
        {
            "message": "runtime error: invalid memory address or nil pointer dereference",
            "locations": []
        }
    ]
}
尽管当我像这样修改GraphQL代码时(显式nil检查并返回literal):

一切正常,GraphQL返回以下结果:

{
    "data": {
        "userProfile": null
    }
}

如何在不显式检查nil的情况下进行管理,并教GraphQL区分nil指针和nil文字

在围棋中,这似乎不是固定不变的:
...
u, err := db.GetUserProfile(p.Context.Value(handler.CtxId("currentUser")).(int), uid)
if u == nil {
    return nil, err
}
return u, err
{
    "data": {
        "userProfile": null
    }
}