Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to github graphql api #8

Open
cg-cnu opened this issue Sep 5, 2017 · 2 comments
Open

move to github graphql api #8

cg-cnu opened this issue Sep 5, 2017 · 2 comments

Comments

@cg-cnu
Copy link

cg-cnu commented Sep 5, 2017

Hey @musically-ut,

I am reading about the github api to work on #7. I realized github has a fantastic graphql api. Did a quick implementation and it allows us to get all the data we need in one go. Here is an example if you want to try out. Use graphql explorer to run this...

query queryIssue($labelName: String!) {
    search(query: $labelName, type: ISSUE, last: 20) {
        edges {
            node {
                ...on Issue {
                    title
                    url
                    labels(first: 10) {
                        edges {
                            node {
                                name
                            }
                        }
                    }
                    repository {
                        name
                        primaryLanguage {
                            name
                        }
                    }
                }
            }
        }
    }
}

and this in the query variables...

{
  "labelName": "label:first-timers-only updated:>2017-04-30T00:00:00Z"
}

which will return a bunch of these....


{
  "data": {
    "search": {
      "edges": [
        {
          "node": {
            "title": "Math Module",
            "url": "https://github.com/publiclab/image-sequencer/issues/108",
            "labels": {
              "edges": [
                {
                  "node": {
                    "name": "first-timers-only"
                  }
                },
                {
                  "node": {
                    "name": "help wanted"
                  }
                }
              ]
            },
            "repository": {
              "name": "image-sequencer",
              "primaryLanguage": {
                "name": "JavaScript"
              }
            }
          }
        },

Its cool, isn't 😎
I think we can completely skip #7 and #4 and implement them in one go using graphql. I know its a lot of rewrite, but let me know your comments 😄

@musically-ut
Copy link
Owner

This looks very cool indeed: GraphQL wasn't available when I had initially written the bot. :)

I don't see a rewrite being a problem at all. Also, a cursory glance suggests that the GraphQL query would still require making n queries for n labels (i.e. no out-of-box support for logical operators like OR/AND). We will be able to avoid the extra call to get the primary languages though.

Also, with GraphQL, having an OAuth token would be a necessary.

Is there anything else I'm missing here?

@cg-cnu
Copy link
Author

cg-cnu commented Sep 5, 2017

Happy to hear that you are ok with the rewrite 😄

Yes, you are right about n queries. Am trying to figure out if there is a better way of doing it. I posted the question on github forum but haven't got any reply so far. 🙁 Doing n queries with graphql is going to be pain because we need to remove the duplicates from the returned objects because of multiple tags. I am trying my best to avoid it 🙂

True, we can avoid multiple calls for languages and we can directly ask for the primary language 😍

While I wait for the github guys to get back to me, I will try to implement the alternate approach over the weekend and see how it goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants