0

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
  }
Preston
  • 3,260
  • 4
  • 37
  • 51
  • Thank you @DanielRearden! Notice that in the terminal the param shows as "sjohns". If that is going to Postgres then it will fail. I added the schema and resolver. I'm using a TypeORM repository which is working for the other queries. – Preston Jun 19 '19 at 19:02
  • @DanielRearden I've added the error message. TypeORM isn't stringifying integers. Interesting. I had everything working with REST but then decided to try GraphQL. Entity should be fine because it is working with other queries and worked with REST. – Preston Jun 19 '19 at 19:52
  • @DanielRearden The getMembers and getMember queries work fine. I'm trying to check the db to see if a user name on an add member form is already taken. – Preston Jun 19 '19 at 19:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195217/discussion-between-daniel-rearden-and-preston). – Daniel Rearden Jun 19 '19 at 20:07

0 Answers0