Github GraphQL Repository Query, using two objects - graphql

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}}
}
}

Related

GitHub GraphQL API Read custom field in Project V2

We are using Github Projects V2. I have created a custom field say 'MyCustomField'.
I want to read the value of custom field MyCustomField using Github GraphQL API.
I am following Gtihub GraphQL API Docs
So far I have got till reading a few predefined fields on Gtihub Issues like title, url, assignees and labels. I am using Windows PowerShell:
$project_id="MyProjectIDFetchedUsingDifferentQuery"
gh api graphql -f query='
query($project_id: ID!){
node(id: $project_id) {
... on ProjectV2 {
items(last: 20) {
nodes{
id
content{
...on Issue {
title
url
assignees(first: 10) {
nodes{
login
}
}
labels(first:5) {
edges {
node {
name
}
}
}
}
}
}
}
}
}
}' -f project_id=$project_id
I am not able to find a way to get the custom field MyCustomField.
I am expecting to write some query like below:
$project_id="MyProjectIDFetchedUsingDifferentQuery"
gh api graphql -f query='
query($project_id: ID!){
node(id: $project_id) {
... on ProjectV2 {
items(last: 20) {
nodes{
id
content{
...on Issue {
title
url
assignees(first: 10) {
nodes{
login
}
}
labels(first:5) {
edges {
node {
name
}
}
}
customFields(first:5) {
nodes {
name
}
}
}
}
}
}
}
}
}' -f project_id=$project_id
I came up with this which I think should get the custom fields on your board:
query {
node(id: "(my project id)") {
... on ProjectV2 {
items(last: 20) {
nodes {
id
content {
... on Issue {
title
url
state
assignees(first: 10) {
nodes {
login
}
}
}
}
fieldValues(first: 20) {
nodes {
... on ProjectV2ItemFieldSingleSelectValue {
field {
... on ProjectV2SingleSelectField {
name
}
}
name
id
}
... on ProjectV2ItemFieldLabelValue {
labels(first: 20) {
nodes {
id
name
}
}
}
... on ProjectV2ItemFieldTextValue {
text
id
updatedAt
creator {
url
}
}
... on ProjectV2ItemFieldMilestoneValue {
milestone {
id
}
}
... on ProjectV2ItemFieldRepositoryValue {
repository {
id
url
}
}
}
}
}
}
}
}
}
Credit should go to https://stackoverflow.com/users/2312060/rich-kuzsma for posting https://gist.github.com/richkuz/e8842fce354edbd4e12dcbfa9ca40ff6
This had the basic format for querying ProjectV2 fields, and I added the
ProjectV2SingleSelectField bit to include both the field name and its value in the response.

Github GraphQL API Get all commits of a User

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

graphql get query shows this error "variables are not allowed in scalars"

query describeNotesByNameSpaace($id:bigint!) {
notes(where: {object_meta: {_contains: {owner_references: [{uid:$id}]}}}) {
id
}
}
Use below code
query describeNotesByNameSpace($jsonFilter: jsonb) {
notes(where: {object_meta: {_contains: $jsonFilter}}) {
id
}
}
And query variable is
{
"jsonFilter": {
"owner_references": [
{
"uid": "1719430910876008448"
}
]
}
}

Drupal GraphQL - Query Single Entity from URL

Is it possible to get an article(single entity) using the Url Alias (entityUrl.path)?
I am using https://github.com/drupal-graphql/graphql
I can do a bulk query for all the articles, do I then filter those results?
Thanks
query GetArticles {
nodeQuery(filter: {conditions: [{field: "type", value: "article"}]}) {
Articles: entities {
entityId
entityLabel
entityUrl {
path
routed
}
}
}
}
Figured it out
query ($path: String!) {
route:route(path: $path) {
... on EntityCanonicalUrl {
entity {
... on Node {
nid
entityLabel
body{
value
}
}
}
}
}
}

Github v4 GraphQL API. Get commits by date

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.

Resources