jorisvddonk / WelcomeToTheFuture

Welcome to the future! Save humanity with GraphQL!
9 stars 0 forks source link

Alter story such that you make use of the `planets` query to search for correct planets. #15

Closed jorisvddonk closed 4 years ago

jorisvddonk commented 4 years ago

GraphQL exposes a graph of things in a nice, clear API. At the moment, within the story, when searching for habitable planets a query like this is used:

query {
  stars {
    entries {
      node {
          planets(type:"Water") {
             ...pinfo
          }
      }
    }
  }
}

fragment pinfo on Planet {
   name
   length_of_day
   hazards {
     ...hzd
   }
}

fragment hzd on Hazards {
  bio
  thermal
  weather
  tectonics
}

...and then we scroll in a huge list looking for something interesting... We also scroll past a lot of stars with no planets that are interesting (planets being an empty list).

Obviously, the answer here is to make a query like this, instead:

query {
  planets(type:"Water") {
    entries {
      node {
          ...pinfo
          star {
            name
            hyperspaceRange
          }
      }
    }
  }
}

(in other words, get all of the interesting planets, and for those planets that are interesting get their parent star so you know where to go and how far away it is)

(ideally also add a way to filter for hazards in the Planets query)

It'd be great to work this into the story somehow: make the user first do the dumb query, then tell them about the smart one. It'd be a great opportunity to learn.

(honestly, I feel kind of silly for not having thought about this before; I guess that in itself is a good demonstration of how thinking in graphs can still be a bit alien and is like a muscle that needs to be exercised)

jorisvddonk commented 4 years ago

Fixed in https://github.com/jorisvddonk/WelcomeToTheFuture/commit/4e4c196f4b509f4dcfe2c04961006a376bdccf5a