Playground的“查询变量”部分似乎需要JSON对象作为查询参数。使用Postgres,我们不能对字符串使用双引号,它必须是单引号。 Playground正在JSON中发送双引号。结果是错误和空响应。解决方法是什么?我已经尝试过像这样转义单引号,但是它不起作用,查询中的/显示:
{
"user_name": "/'sjohns/'"
}
我的整数var查询有效。
查询:
query ($user_name: String!) {
checkUserName(user_name: $user_name) {
user_name
}
}
查询变量:
{
"user_name": "sjohns"
}
从登录终端:
user_name in resolver: sjohns
user_name in service: sjohns
query: SELECT "Members"."member_id" AS ... other properties ...
FROM "members" "Members" WHERE "Members"."user_name" = $1
-- PARAMETERS: ["sjohns"]
编辑:
模式:
type Query {
getMembers: [Member]
getMember(member_id: Int!): Member!
checkUserName(user_name: String!): Member!
解析器:
async checkUserName(@Args('user_name') user_name: string) {
console.log('user_name in resolver: ', user_name); // Shown above.
return await this.membersService.checkUserName(user_name);
}
来自实体:
@Column({ length: 50 })
user_name: string;
错误,此用户名与我尝试过的其他用户一样在db中存在。 它与REST一起使用。
{
"errors": [
{
"message": "Cannot return null for non-nullable field Member.user_name.",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"checkUserName",
"user_name"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Cannot return null for non-nullable field Member.user_name.", ...
"data": {
"checkUserName": null
}