Skip to content

Instantly share code, notes, and snippets.

@kkeeth
Last active February 22, 2020 23:52
Show Gist options
  • Save kkeeth/5756d61139501dff117ffade9e103858 to your computer and use it in GitHub Desktop.
Save kkeeth/5756d61139501dff117ffade9e103858 to your computer and use it in GitHub Desktop.
GraphQL queries and mutations on GitHub API v4 explorer
# get repository information
query GetRep {
repository(name: "riot", owner: "riot") {
id
name
url
}
}
# get user information
query GetUser {
viewer {
login
}
user(login: "kkeeth") {
id
name
bio
avatarUrl
}
}
# search repositories with keyword "riot"
query Search {
search(first: 3, type: USER, query: "riot") {
nodes {
... on User {
id
name
url
}
... on Organization {
id
name
url
projectsUrl
}
}
}
}
# get repository with __typename field and keyword "riot"
query SearchWithTypeName {
search(first: 3, type: USER, query: "riot") {
nodes {
__typename
... on User {
id
name
url
}
... on Organization {
id
name
url
projectsUrl
}
}
}
}
# search repositories with pageinformation
query SearchRepositories($first: Int, $after: String, $last: Int, $before: String, $query: String!) {
search(first: $first, after: $after, last: $last, before: $before, query: $query, type: REPOSITORY) {
repositoryCount
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
edges {
cursor
node {
... on Repository {
id
name
url
}
}
}
}
}
# add star to specified repository
mutation addStar {
addStar(input: {
starrableId: "MDEwOlJlcG9zaXRvcnkxNDU3ODA0Nzc="
}) {
starrable {
id
viewerHasStarred
}
}
}
# remove star to specified repository
mutation removeStar {
removeStar(input: {
starrableId: "MDEwOlJlcG9zaXRvcnkxNDU3ODA0Nzc="
}) {
starrable {
id
viewerHasStarred
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment