The Query Variables section of Playground seems to require a JSON object for the query argument. With Postgres we can't use double quotes for a string, it must be single quotes. Playground is sending double quotes in the JSON. The results is an error and null response. What is the work around? I've tried escaping single quotes like so but it didn't work, the / shows in the query:
{
"user_name": "/'sjohns/'"
}
My query with an integer var works.
Query:
query ($user_name: String!) {
checkUserName(user_name: $user_name) {
user_name
}
}
Query Variables:
{
"user_name": "sjohns"
}
From the log in terminal:
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"]
Edit:
Schema:
type Query {
getMembers: [Member]
getMember(member_id: Int!): Member!
checkUserName(user_name: String!): Member!
Resolver:
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);
}
From the entity:
@Column({ length: 50 })
user_name: string;
The error, and this user name exists in the db as do others I've tried. It worked with 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
}