New to graphql and the Github API. I'm trying to get a list of commits back, sorted by date. This is what I have so far:
{
repository(owner: "facebook", name: "create-react-app") {
ref(qualifiedName: "master") {
target {
... on Commit {
id
history(first: 20) {
pageInfo {
hasNextPage
}
edges {
node {
messageHeadline
oid
message
}
}
}
}
}
}
This just returns a flat list of the commit history. Is there another object or connection that I can use to group the results by date?
Thanks
There is no notion of "groupBy" or "GroupedBy" in the GraphQL API v4 reference.
All you have is an orderBy argument for repository.
You can see an example here
{
organization(login: "lvtech") {
repositories(first: 3, orderBy: {field: PUSHED_AT, direction: DESC}) {
edges {
node {
name
}
}
}
}
}
But again, that applies to repository attributes, not to commit attributes.
Related
I'm trying to use the GitHub GraphQL API to get all the additions made by a user (additions can be found from their commits). I've been able to get the additions from pull requests, but I haven't found a way to do the same for commits. How can I get all the commits from a user?
This is my query (I am new to GraphQL):
query AllAdditions($username: String!, $from: DateTime, $to: DateTime) {
user(login: $username) {
name
contributionsCollection(from: $from, to: $to) {
commitContributionsByRepository(maxRepositories: 100) {
repository {
nameWithOwner
}
contributions(first: 30) {
totalCount
# I'm trying to get additions like this, but there is no 'commit' field
# nodes {
# commit {
# additions
# }
# }
}
}
pullRequestContributionsByRepository(maxRepositories: 100) {
repository {
nameWithOwner
}
contributions(first: 30) {
nodes {
pullRequest {
additions
}
}
}
}
}
}
}
{
search(query: "org:test", type: REPOSITORY, last: 100) {
nodes {
... on Repository {
name
defaultBranchRef {
name
target {
... on Commit {
history(first: 100, since: "2013-07-11T00:00:00") {
totalCount
nodes {
... on Commit {
committedDate
additions
author {
name
email
}
}
}
}
}
}
}
}
}
}
}
As for getting all orgs, there isn’t currently a way to do that via the GraphQL API because the search connection requires something in the search query. There’s also no top-level connection that allows you to list all users, orgs, or repositories.
I hope that helps!
answer copied from this URL: GraphQL - Get all commits by all users
I need to get a query using graphql in strapi/gatsby where id is {id}.
According to the documentation found here you query all like so:
{
allStrapiArticle {
edges {
node {
id
title
content
}
}
}
}
This works and I'm able to query however I'd like to get only one Article where id is {id};
I have tried:
{
allStrapiArticle(id: "4") {
edges {
node {
id
title
content
}
}
}
}
And also:
{
allStrapiArticle {
edges {
node(id: "4") {
id
title
content
}
}
}
}
Both of the above give me an error. Any idea how I can achieve this?
Use:
{
allStrapiArticle(filter: {id: {eq: "4" }}) {
edges {
node {
id
title
content
}
}
}
}
elemMatch filter might be useful for your use case as well.
Check the localhost:8000/___graphql playground to test your queries and filters.
More references:
https://www.gatsbyjs.com/docs/query-filters/
https://www.gatsbyjs.com/docs/graphql-reference/
I am trying to run the following query on Githubs GraphQL api:
{
user(login: "davekaj") {
id
repositories(first: 10, orderBy: {field: NAME, direction: ASC}) {
nodes {
ref(qualifiedName: "master") {
target {
... on Commit {
history(first: 15, author: "WHAT DO I PUT HERE") {
totalCount
nodes {
additions
author {
name
user {
id
}
}
committedDate
deletions
}
}
}
}
}
}
}
}
}
It wants me to filter on a CommitAuthor for history(author: ). I tried passing my username, or my unique user ID, but it doesn't work. I am essentially passing it a string, but it wants the type CommitAuthor. How do I pass a CommitAuthor value?
It isn't clear to me, and I searched through the docs and the schema and I couldn't find anything.
Please help!
Ah, so the answer is actually very simple once I looked at the graphql documentation (rather than just the github documentation). CommitAuthor is an input type, which is described here https://graphql.org/graphql-js/mutations-and-input-types/.
The result is you pass an object of CommitAuthor. In this case I just have to pass the id, which looks like this: author: {id: "MDQ6VXNlcjIyNDE3Mzgy"}
See the completed code below.
{
user(login: "davekaj") {
id
repositories(first: 10, orderBy: {field: NAME, direction: ASC}) {
nodes {
ref(qualifiedName: "master") {
target {
... on Commit {
history(first: 15, author: {id: "MDQ6VXNlcjIyNDE3Mzgy"}) {
totalCount
nodes {
additions
author {
name
user {
id
}
}
committedDate
deletions
}
}
}
}
}
}
}
}
}
So I'm completely new to GraphQL, could anyone tell me how to change below code into retrieving only public repos from my account?
I tried to use "search" attribute but I can't get it working.
Thanks
const {
github: {
repositoryOwner: {
repositories: { edges },
},
},
} = useStaticQuery(graphql`
{
github {
repositoryOwner(login: "SzBor") {
repositories(first: 6, orderBy: { field: CREATED_AT, direction: ASC }) {
edges {
node {
id
name
url
description
}
}
}
}
}
}
`)
you can use the arguments privacy: PUBLICon repositories Ex:
const {
github: {
repositoryOwner: {
repositories: { edges },
},
},
} = useStaticQuery(graphql`
{
github {
repositoryOwner(login: "SzBor") {
repositories(first: 6, privacy: PUBLIC, orderBy: { field: CREATED_AT, direction: ASC }) {
edges {
node {
id
name
url
description
}
}
}
}
}
}
`)
The stranger is that the (API V4 document) is not updated with this information, but you can test on explorer :)
How to use more than one objects when querying Github GraphQL?
The following will break if the 2nd object is uncommented:
query {
repository(owner:"rails", name:"rails") {
object(expression:"master") {
... on Commit {
history {
totalCount
}
}
}
# object(expression: "master:README.md") {... on Blob {byteSize}}
}
}
How to make it working? Thx
Use alias:
query {
repository(owner:"rails", name:"rails") {
object(expression:"master") {
... on Commit {
history {
totalCount
}
}
},
second_object: object(expression: "master:README.md") {... on Blob {byteSize}}
}
}