joshblack / build-a-graphql-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query videos by it's IDs

dusi opened this issue · comments

Hey @joshblack

I was following the egghead tutorial: https://egghead.io/courses/build-a-graphql-server to build a GraphQL server. I've noticed that querying videos by it's IDs doesn't currently work and was wondering if you'd know what's the issue? I'd tried fixing it but couldn't figure out the right approach.

Querying nodes by it's ID works correctly.

Looking up all videos like this:

query Videos {
  videos {
    edges {
      node {
        id
        title
      }
    }
  }
}

gives us the following result

{
  "data": {
    "videos": {
      "edges": [
        {
          "node": {
            "id": "VmlkZW86YQ==",
            "title": "Create a GraphQL Schema"
          }
        },
        {
          "node": {
            "id": "VmlkZW86Yg==",
            "title": "Ember.js CLI"
          }
        }
      ]
    }
  }
}

If we query nodes for the following ID: VmlkZW86Yg==

query NodeById {
  node(id: "VmlkZW86YQ==") {
    ... on Video {
      title
    }
  }
}

everything seems OK and we get

{
  "data": {
    "node": {
      "title": "Create a GraphQL Schema"
    }
  }
}

but trying the same for videos doesn't return the correct video

query VideoById {
  video(id: "VmlkZW86YQ==") {
    title
  }
}

returns

{
  "data": {
    "video": null
  }
}

I believe it's got something to do with translating global ID, but I can't figure it out.

ps: Thanks for such a great tutorial, me and my team have really enjoyed it!

Good catch! Thanks so much for creating the issue. Will try and add, like you said, formatting the incoming globalID using fromGlobalId.

Thanks again!