Differentiating issues from PRs


I’m trying to come up with an efficient way to differentiate PRs from issues in an autolinking mechanism, and I was wondering if there was a way to compress this into a single network request for performance. Of course, I can do this across multiple requests, but it’s obviously not ideal:

function identifyLinkTypes(links) {
    return Promise.all(_.flatten(links.map(({user, repo, ids}) =>
        ids.map(id => fetch("https://api.github.com/graphql", {
            method: "POST",
            body: JSON.stringify({
                query: `
                query ($o: String!, $r: String!, $i: Int!) {
                    repository(owner: $o, name: $r) {
                        issueOrPullRequest(number: $i) {
                            ... on Issue { number }
                            ... on PullRequest { number }
                variables: {o: user, r: repo, i: id},

Is there any way to compress this to a single call, so I’m only making one network request while auto-linking everything, instead of potentially tens for each pass? (It’d be way faster and easier.)


My understanding is that GraphQL doesn’t works this way. It would be nice if variables could be an array of input structures which would then get you multiple results, one for each input object in the array.

This would be an extension to the GraphQL spec however and is likely best communicated to its upstream.

Some interesting issues:

Well, I thought there’d be more, but the GraphQL issue tracker is likely the place to go.


And done: https://github.com/facebook/graphql/issues/517