How to query data from GitHub Discussions using GitHub's GraphQL API - graphql

I want to query the data from https://github.com/prisma/prisma/discussions via GitHub's GraphQL API but I don't know how to access it.
GitHub Discussions are a beta feature that's currently available only on a few repos, prisma/prisma being one of them. I would have expected that I can query the data in a similar fashion to querying issues and pull requests of a repo:
{
repository(
owner: "prisma"
name: "prisma"
) {
pullRequests(first: 5 orderBy: {
field: CREATED_AT,
direction: DESC
}) {
edges {
node {
title
}
}
}
issues(first: 5 orderBy: {
field: CREATED_AT,
direction: DESC
}) {
edges {
node {
title
}
}
}
}
}
I'm basically looking for a query that would allow me to do this:
{
repository(
owner: "prisma"
name: "prisma"
) {
# this doesn't work
discussions(first: 5 orderBy: {
field: CREATED_AT,
direction: DESC
}) {
edges {
node {
title
}
}
}
}
}
But such a discussions property doesn't exist on the Repository type in the GitHub API.
EDIT (Dec 8, 2020): I learned from the GitHub team that the data is not yet available via the public GraphQL API but they're working on releasing it soon. I'll leave the question open until it's available.

Related

How do I filter issue comment authors using GraphQL

I'm trying to figure out how to get the list of comments on an issue using GraphQL. I'm able to get comments by everyone but not only by author.
My code:
query {
repository(name: "maintainer-bot", owner: "Xenfo") {
issue(number: 16) {
comments(first: 10) {
nodes {
author {
login
}
}
}
}
}
}
My question: How would I filter the comments returned so that only the user with the name Xenfo has his comments returned?

How to transform Markdown query to Strapi query on GraphiQL?

I'm trying to get my hands on Gatsby + Strapi development (adding Material for styling), I'm new to both Gatsby and Strapi although I have some basic knowledge of React and it's making the way easier to follow.
I'm using this Gatsby Starter: https://www.gatsbyjs.org/starters/Vagr9K/gatsby-material-starter/ which includes the Material design I'm trying to achieve, but I'm having some trouble changing the Markdown queries to Strapi queries to avoid making a lot of code changes (posts are exactly the same but stored in Strapi). I have three Content Types in Strapi corresponding to the three different pages the original starter provides: Post, Category, and Tag.
This is the original MarkdownRemark graphQL query included in the post.jsx template:
query BlogPostBySlug($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
html
timeToRead
excerpt
frontmatter {
title
cover
date
category
tags
}
fields {
slug
date
}
}
}
How can I change it to retrieve the same info from Strapi?
I'm really new to this Strapi world so I'm having a lot of doubts with the GraphQL, as I can't follow the guide from the Markdown query because the Information displayed is not the same.
I'm also having trouble differentiating between allStrapiArticles and StrapiArticle, what's the main purpose of those?
EDIT: I've been testing the existing queries on GraphiQL to check what they are returning and this is what I'm seeing:
For the tag.jsx query:
query TagPage($tag: String) {
allMarkdownRemark(
limit: 1000
sort: { fields: [fields___date], order: DESC }
filter: { frontmatter: { tags: { in: [$tag] } } }
) {
totalCount
edges {
node {
fields {
slug
date
}
excerpt
timeToRead
frontmatter {
title
tags
cover
date
}
}
}
}
}
GraphiQL returns nothing:
{
"data": {
"allMarkdownRemark": {
"totalCount": 0,
"edges": []
}
}
}
For the category.jsx query:
query CategoryPage($category: String) {
allMarkdownRemark(
limit: 1000
sort: { fields: [fields___date], order: DESC }
filter: { frontmatter: { category: { eq: $category } } }
) {
totalCount
edges {
node {
fields {
slug
date
}
excerpt
timeToRead
frontmatter {
title
tags
cover
date
}
}
}
}
}
In this case, everything works fine and it retrieves article data.
And for the case of the query I've added as an example in this post (upper part of the question) I'm getting the following error:
"errors": [
{
"message": "Variable \"$slug\" of required type \"String!\" was not provided."
...
Make sure you are passing your variable in through Query Variables at the bottom of GraphiQL.
First, I would query AllMarkdownRemark to make sure you're getting the nodes from Gatsby. Something like:
query MyQuery {
allMarkdownRemark {
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
}
}
}
If the slug is showing up, then this should work:
Sometimes a slug is not being generated. Which should show up checking allMarkdownRemark.

Obtain GitHub issues in a specific milestone using GraphQL and IssueFilters

A similar question was previously asked but doesn't use IssueFilters which is what I want to use in this question.
Using GitHub's GraphQL Explorer, I am able to get issues of a repository using this query:
{
repository(owner: "neovim", name: "neovim") {
hasIssuesEnabled
issues(first: 20, orderBy: {field: CREATED_AT, direction: DESC}, filterBy: {milestone:"*"}) {
nodes {
... on Issue {
number
title
milestone {
number
id
url
title
}
}
}
}
}
}
The milestone is an issueFilter which, according to the documentation, allows you to:
List issues by given milestone argument. If a string representation of an integer is passed, it should refer to a milestone by its number field. Pass in null for issues with no milestone, and * for issues that are assigned to any milestone.
However, using a filter that is not a * but let's say filterBy: {milestone:"9"} (9 being a valid milestone number for the repository I am using), the query returns no nodes:
{
"data": {
"repository": {
"hasIssuesEnabled": true,
"issues": {
"nodes": []
}
}
}
}
I do not understand why this does not work from the documentation I read. Am I missing something regarding what means "it should refer to a milestone by its number field"?

using graphql github api to get commit information by Id

I would like to get commit details for a specific commit given that I already have the commit id
for example, if I know the commit id is
12762b76cba8ac4623a6c16e1fe60efafa3b7d1c and the repo is ruby/ruby
how do I get the committedDate and author email?
You can try using a cursor as an edge type, as in this thread:
{
repository(owner: "octocat", name: "Hello-World") {
first: object(expression: "master") {
... on Commit {
history(path: "README", last: 1, before: "762941318ee16e59dabbacb1b4049eec22f0d303 1") {
edges {
node {
committedDate
oid
author
{
email
}
}
}
}
}
}
}
}
you can test it using this explorer https://developer.github.com/v4/explorer/

Github GraphQl - How to get a list of commits between tags

With Github GraphQL I want to answer the question:
What commits have been merged into master between releases/tags?
The result should be similar to the results for this question Get commit list between tags in Git if I were to do it on the command line.
I'm using the developer explorer and wondering if I will be able to do this with a single query or if I will need several. I tried the following but it does not give me the commits between tags that have not been tagged, just the tagged commits.
{
repository(owner: "CoolCompany", name: "awesome-new-ui") {
refs(refPrefix: "refs/tags/", first: 2, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
edges {
node {
id
name
target {
oid
... on Commit {
author {
date
email
name
}
message
}
}
}
}
}
}
}
#lee-dohm from the Github GraphQL community helped me arrive at a solution which is posted here
I can paste my solution here as well. It seems this problem is not solve-able with a single query, but it can be done with 2 that work in conjunction with each other:
Step 1: Get the most recent release information. You could modify this for tags as well.
{
repository(owner: "CoolCompany", name: "awesome-ui") {
releases(last: 1) {
edges{
node{
tagName
createdAt
}
}
}
}
}
Step 2: Use the value from the createdAt (associated with the release or tag) and do this:
{
repository(owner: "CoolCompany", name: "awesome-ui") {
nameWithOwner
object(expression: "master") {
... on Commit {
oid
history(first: 100, since: "$createdAtDate") {
nodes {
oid
messageHeadline
author {
user {
login
}
}
committedDate
}
}
}
}
}
}

Resources