Query organization using "id"? And permanence of "id" value?

schema-request

#1

Since “login” is changeable, I’d much prefer to query organizations (and users) by “id”. (I’ve actually had an org rename itself, and cause much confusion to all come billing time.)

v3 allows such a query (perhaps unintentionally) – to get summary of org (or user) “X” I use a “since” parameter of “X-1”. E.g. to lookup org id 1066228, I use:

https://api.github.com/organizations?since=1066227&per_page=1

Similarly for users (e.g. me):

https://api.github.com/users?since=132411&per_page=1

The above assumes that the “id” field is intended to be a unique id for an org or user account.

Questions:

  1. Is the “id” field intended to be a unique id for org & user accounts? If not, which field is?

  2. Is there a v4 way to query using that unique id?

  3. Is there a supported way to convert from a v3 id to a v4 id?

Thanks!


#2

Hi @hwine!

You’re going to want to start using the “Global Relay ID” which is what can be found for an object as the id field in the v4 API and can be found as node_id in the REST API with the appropriate preview header passed in (mentioned in the linked doc).

The id fields you’re currently using in the v3 can be found in the v4 API for some objects as databaseId (e.g. for organization ). However, we are deprecating this field in favor of the global Relay IDs - the deprecation note says the databaseId field will be removed on July 1.

An example query showing these two ids for your example org is

{
  organization(login: "mozilla-services") {
    id
    databaseId
  }
}

and the response

{
  "data": {
    "organization": {
      "id": "MDEyOk9yZ2FuaXphdGlvbjEwNjYyMjg=",
      "databaseId": 1066228
    }
  }
}

You can then use that id to do a query for that organization:

{
  node(id: "MDEyOk9yZ2FuaXphdGlvbjEwNjYyMjg=") {
    ... on Organization {
      login
    }
  }
}

Hope that helps!


#3

@rlinehan Thanks so much! I’d seen mention of the databaseId field, but didn’t understand that was the v3 id field. (When there was little activity on this question, I figured I was missing something fairly basic. /o\)

Related to the second part of my question – is GitHub supporting any mapping between databaseId & Global Relay ID? I don’t see that topic covered in the migration notes. That is, can I store only the Global Relay ID and then derive the v3 id as needed for not-yet-ported v3 queries?


#4

Related to the second part of my question – is GitHub supporting any mapping between databaseId & Global Relay ID? I don’t see that topic covered in the migration notes2. That is, can I store only the Global Relay ID and then derive the v3 id as needed for not-yet-ported v3 queries?

I’m not completely sure if this is what you’re asking for, but say you have stored the Global Relay ID from our previous example (“MDEyOk9yZ2FuaXphdGlvbjEwNjYyMjg=”), you can use it to get the databaseId (the v3 id) like so:

{
  node(id: "MDEyOk9yZ2FuaXphdGlvbjEwNjYyMjg=") {
    ... on Organization {
      databaseId
    }
  }
}

Does that answer your question? Sorry if I’ve misunderstood.