Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Cannot read property 'toString' of undefined #1860

Closed
lastmjs opened this issue Aug 12, 2020 · 6 comments · Fixed by #1861
Closed

Cannot read property 'toString' of undefined #1860

lastmjs opened this issue Aug 12, 2020 · 6 comments · Fixed by #1861
Assignees
Labels
bug Something isn't working

Comments

@lastmjs
Copy link

lastmjs commented Aug 12, 2020

This query fails:

query {
  findCalls(filter: {
    id: {
      eq: 150
    }
  }) {
    items {
      id
      company {
        id
        name
        users {
          user {
            email
            is_active
          }
        }
      }
    }
  }
}

Here is the result:

{
  "errors": [
    {
      "message": "Cannot read property 'toString' of undefined",
      "locations": [
        {
          "line": 9,
          "column": 11
        }
      ],
      "path": [
        "findCalls",
        "items",
        0,
        "company",
        "users",
        0,
        "user"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: Cannot read property 'toString' of undefined",
            "    at /var/task/node_modules/@graphback/codegen-schema/dist/SchemaCRUDPlugin.js:599:88",
            "    at Array.find (<anonymous>)",
            "    at /var/task/node_modules/@graphback/codegen-schema/dist/SchemaCRUDPlugin.js:599:46",
            "    at Array.map (<anonymous>)",
            "    at SchemaCRUDPlugin.<anonymous> (/var/task/node_modules/@graphback/codegen-schema/dist/SchemaCRUDPlugin.js:598:33)",
            "    at Generator.next (<anonymous>)",
            "    at fulfilled (/var/task/node_modules/tslib/tslib.js:112:62)",
            "    at processTicksAndRejections (internal/process/task_queues.js:97:5)"
          ]
        }
      }
    }
  ],
  "data": {
    "findCalls": {
      "items": [
        {
          "id": "150",
          "company": null
        }
      ]
    }
  }
}

When I add id to the selection set of users.user, the query succeeds:

query {
  findCalls(filter: {
    id: {
      eq: 150
    }
  }) {
    items {
      id
      company {
        id
        name
        users {
          user {
            id
            email
            is_active
          }
        }
      }
    }
  }
}

Companies and users have a many-to-many relationship, so there is a join table called Companies_users that looks like this:

type Companies_users {
    id: ID! # Note that this id exists in the schema because it is necessary, but my database actually does not have this field. Not usre if that matters in this case
    company: Companies!
    user: Users!
}
@machi1990
Copy link
Contributor

Automatically generated comment to notify maintainers
/cc @craicoverflow, @machi1990, @wtrocki

@machi1990
Copy link
Contributor

machi1990 commented Aug 12, 2020

This looks like it is related to #1752?

@machi1990
Copy link
Contributor

This looks like it is related to #1752?

This only happens in 0.16.0-alpha3 after #1834. #1861 should fix this issue!

machi1990 added a commit to machi1990/graphback that referenced this issue Aug 12, 2020
@machi1990 machi1990 self-assigned this Aug 12, 2020
machi1990 added a commit that referenced this issue Aug 12, 2020
@machi1990
Copy link
Contributor

@lastmjs we dropped 0.16.0-alpha4 to take care of this issue. Mind checking and see it fixes the issue for your. Feel free to re-open if it's not the case.

@lastmjs
Copy link
Author

lastmjs commented Aug 12, 2020

It works! Thanks a ton

@machi1990
Copy link
Contributor

Thanks for reporting back!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
2 participants