How to make efficient query for multiple legislators


#1

Hi, I’m trying to update some data I have with API V2 ids instead of the deprecated V1 ones.

This is more of a graphql fundamentals question so feel free to close if off topic! Also obligatory “thank you so much for working on this amazing resource” that I’m sure you hear a lot.

I am trying to map through legislator names and create a single query for all legislators instead of making individual queries for each names (which works without a problem). I thought I could use graphql “aliases” to do so but so far no dice.

Here’s an abbreviated version of my query so far, I know if must have incorrect syntax because it causes errors (won’t even let me copy paste in the graphiql editor):

query getLegislatorId($organization: String ) {
Barrett_Michael : people(name: "Barrett, Michael ", everMemberOf: $organization, first: 1) {
    edges {
      node {
        id
        name
      }
    }
  } Boncore_Joseph: people(name: "Boncore, Joseph", everMemberOf: $organization, first: 1) {
    edges {
      node {
        id
        name
      }
    }
  } 
}

Thank you!


#3

When I paste your query into graphiql and provide an organization, it works “fine”, but gets back no results - the edges arrays are empty. Take a look at the result of this variant:

 query getLegislatorId($organization: String) {
  Barrett_Michael: people(name: "Michael J. Barrett", everMemberOf: $organization, first: 1) {
    edges {
      node {
        id
        name
      }
    }
  }
  Boncore_Joseph: people(everMemberOf: $organization, first: 100) {
    edges {
      node {
        id
        name
      }
    }
  }
}

used with variable

{ "organization": "ocd-organization/1a75ab3a-669b-43fe-ac8d-31a2d6923d9a" }

From this I infer that name matching must be exact or at least different from what you provided (Michael J. Barrett" vs “Barrett, Michael”, and that for some reason Joseph Boncore is missing.


#4

Thank you!! By looking at what you posted I realized the 1) organization id was wrong in that sample query and 2) I could use what you posted to double check my query creation. This code ended up working:

    const makeQuery = names => `
   query getLegislatorIds($organization: String ) {
    ${names.map((name, index) => {
      return `
        _${index} : people(name: "${getNormalizedLastName(
        name
      )}", everMemberOf: $organization, first: 1) {
          edges {
            node {
              id
              name
            }
          }
        }
        `
      })}
    }
  `

Thanks again!