Querying legislators by state and name


#1

I’m trying to recreate the results of the old endpoint https://openstates.org/api/v1/legislators/?state=XX&name=YY in the new v2 paradigm.

I’ve figured out the two queries I need to run, but am having some trouble chaining them together. Should I just send the first query with the state definition, parse out the organization ID, and then send it with the second? Trying to avoid spamming the system with multiple requests, and I though GraphQL was meant to do nested things like this more easily…

query getOrganizationID($stateOCD:String, $chamber:String) {
  jurisdiction(id: $stateOCD) {
    name
    organizations(classification: [$chamber], first: 3) {
      edges {
        node {
          id
          name
          classification
        }
      }
    }
  }
}

query getLegislatorContact($name: String, $organizationID: String, $chamber: String) {
  people(name: $name, memberOf: $organizationID, first: 5) {
    edges {
      node {
        currentMemberships(classification: [$chamber]) {
          id
        }
        id
        name
        contactDetails {
          type
          value
          note
          label
        }
      }
    }
  }
}

#2

Yes, use two queries. It’s not ideal.


#3

Thanks Ed, I guess I’ll just hit it twice. I may also cache the organization IDs for each legislative body, since those should never change…