Git-point: GraphQL

Created on 21 Jul 2017  路  10Comments  路  Source: gitpoint/git-point

We should start moving gradually towards GraphQL, it will save us a TON of requests. AFAIK GraphQL doesn't have available the same exact endpoints as Github V3 Rest API so we should have a mix between both.

assigned enhancement hacktoberfest

Most helpful comment

While it's fresh on my mind, here's how we'd fetch an issue (query score: 3, i.e. is 3/5000 of our hourly limit):

{
  repository(owner: "gitpoint", name: "git-point") {
    issue(number: 2) {
      title
      body
      participants(first: 100) {
        edges {
          node {
            avatarUrl
            login
          }
        }
      }
      author {
        avatarUrl
        login
      }
      labels(first: 5) {
        edges {
          node {
            name
            color
          }
        }
      }
      comments(first: 100) {
        edges {
          node {
            body
            author {
              avatarUrl
              login
            }
          }
        }
      }
    }
  }
}

All 10 comments

While it's fresh on my mind, here's how we'd fetch an issue (query score: 3, i.e. is 3/5000 of our hourly limit):

{
  repository(owner: "gitpoint", name: "git-point") {
    issue(number: 2) {
      title
      body
      participants(first: 100) {
        edges {
          node {
            avatarUrl
            login
          }
        }
      }
      author {
        avatarUrl
        login
      }
      labels(first: 5) {
        edges {
          node {
            name
            color
          }
        }
      }
      comments(first: 100) {
        edges {
          node {
            body
            author {
              avatarUrl
              login
            }
          }
        }
      }
    }
  }
}

And fetch a repository (query score: 5):

{
  repository(owner: "gitpoint", name: "git-point") {
    description
    primaryLanguage {
      name
      color
    }
    owner {
      avatarUrl
      login
    }
    releases {
      totalCount
    }
    stargazers {
      totalCount
    }
    forks {
      totalCount
    }
    # Contributors:
    mentionableUsers(first: 100) {
      edges {
        node {
          avatarUrl
          login
        }
      }
    }
    openIssues: issues(first: 3, states: OPEN) {
      totalCount
      edges {
        node {
          title
        }
      }
    }
    closedIssues: issues(first: 3, states: CLOSED) {
      totalCount
      edges {
        node {
          title
        }
      }
    }
    openPullRequests: pullRequests(first: 3, states: OPEN) {
      totalCount
      edges {
        node {
          title
        }
      }
    }
    closedPullRequests: pullRequests(first: 3, states: [CLOSED, MERGED]) {
      totalCount
      edges {
        node {
          title
        }
      }
    }
  }
}

Fetching a user (query score: 1):

{
  user(login: "andrewda") {
    name
    bio
    email
    location
    company
    websiteUrl
    viewerIsFollowing
    followers {
      totalCount
    }
    following {
      totalCount
    }
    repositories {
      totalCount
    }
    organizations(first: 100) {
      edges {
        node {
          avatarUrl
          login
        }
      }
    }
  }
}

you can also use viewer nodes for current logged in user

{
  viewer {
    name
    bio
    email
    location
    company
    websiteUrl
    viewerIsFollowing
    followers {
      totalCount
    }
    following {
      totalCount
    }
    repositories {
      totalCount
    }
    organizations(first: 100) {
      edges {
        node {
          avatarUrl
          login
        }
      }
    }
  }
}

Just waiting for GitHub to get back to me now on why the Organization queries are lacking some fundamental information (description, website and email at least). Then I can continue work on this.

Also, there's no user events on Graphql nodes. I've asked Github regarding this issue, still no answer

Here's how to get the README.md file for a repo. If it doesn't exist, readme will be null:

{
  repository(owner: "gitpoint", name: "git-point") {
    readme: object(expression: "master:README.md") {
      ... on Blob {
        text
      }
    }
  }
}

I'd like to work on this!

Absolutely @cheshire137! Thank you :)

@lex111 started integrating endpoints with organization requests at #347. Please feel free to put up PRs for certain portions incrementally if you prefer.

CC @andrewda (in case you've looked into adding any GraphQL endpoints) and @machour (who's working on normalizing our data store at the moment)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TautFlorian picture TautFlorian  路  4Comments

randy3k picture randy3k  路  5Comments

TautFlorian picture TautFlorian  路  5Comments

cheshire137 picture cheshire137  路  3Comments

housseindjirdeh picture housseindjirdeh  路  3Comments