How can I get the project name for a timelog issue entry using the project ID from a Gitlab GraphQL query - graphql

I'm using the graphql explorer for gitlab and I'm trying to get timelog entries for a given user (as below).
The response gives me a projectId which I assume I'd have to use in a subsequent query (I don't believe I can get it in the same query?), but the project object doesn't let me find the project by ID, only fullpath.
Am I correct in understanding that I would need to use the projects query and provide the id there? In trying that (query below), I just get the error 12345678 is not a valid GitLab ID. (obviously I'm using a real ID given previously).
So, two points/questions I guess:
The timelog entry provides a projectId which I can't use in either the project or projects query to get the project name?
I can't just return the project name directly in the same query as the original user timelog one?
Any thoughts greatly appreciated.
{
users(usernames: ["user1"]) {
nodes {
id
username
timelogs(startDate: "2022-05-03T09:00:00") {
nodes {
issue {
projectId
}
timeSpent
}
}
}
}
}
{
projects(ids:[12345678]) {
nodes {
name
}
}
}

I don't know if this helps, but I use:
{
group(fullPath: "groupname") {
name
timelogs(startTime: "2022-04-01", endTime: "2022-04-30", username: "roberto") {
pageInfo {
hasNextPage
endCursor
}
nodes {
user {
username
}
issue {
iid
webUrl
state
projectId
title
}
spentAt
timeSpent
summary
note {
body
url
}
}
}
}
}

Related

Performing A GraphQL Selection On A Union for shopify SellingPlanPricingPolicy

I am trying to get union data using the Graphql APIfor Shopify and am unable to find any documentation on selecting data in unions.
Here is my current query:
query subscriptionPlans {
sellingPlanGroup(id: 1234) {
id
name
sellingPlans(first: 1) {
edges {
node {
id
billingPolicy {
... on SellingPlanRecurringBillingPolicy {
interval
intervalCount
}
}
pricingPolicies {
on
SellingPlanRecurringPricingPolicy {
afterCycle
adjustmentType
adjustmentValue {
on
SellingPlanPricingPolicyPercentageValue {
percentage
}
on
MoneyV2 {
amount
currencyCode
}
}
}
}
}
}
}
}
}
I am able to retrieve the sellingPlans in this scenario. When I get to the SellingPlanPricingPolicy portion I run into issues. I am receiving the error:
Selections can't be made directly on unions (see selections on SellingPlanPricingPolicy)
However, I am unable to find any documentation on making selections using the documentation at: https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/sellingplanpricingpoli...
Any help with this would be appreciated. I just need an example of how to select this information.
Found the answer in https://graphql.org/learn/queries/#meta-fields. In case of sponsorEntity it looks like this:
sponsorEntity {
... on User {
name
}
}
The solution is to select the attributes on the respective sub-type of the union.

Graphql, return result only if record not null

Totally new in Gatsby (my app is build in here). Also new in Graphql but I go this project from a colleague and now I need to find a way to sort it out.
I have a query in graphql that looks as follow:
query MediasQuery {
allStrapiMedias(sort: { fields: [date], order: DESC }) {
edges {
node {
id
name
description
date(formatString: "Do MMMM, YYYY")
link
poster {
childImageSharp {
fluid {
src
}
}
}
file {
url
}
}
}
}
}
The issue I am facing is that the file record can exist or not, to be more accurate, if link record is empty, then I should find a file (this is how it's been build in Strapi).
If I have at least one record with file then the query run normally, but as soon as I deleted this record from database all the app crash.
How can I make that query to only return file if url is empty or null?
You are querying an object that will have one property (file) filled or not with an url. You just need to add that logic to your JavaScript and React code. When you will print the file, add the new logic, something like:
if (data.allStrapiMedias.edges.node.file) return <ComponentA/>
else return <ComponentB/>
I think that what you are looking for is something that the previous snippet. However, answering your question, you achieve it by adding filters to your query:
query MediasQuery {
allStrapiMedias(
sort: { fields: [date], order: DESC }
filter: { file: {url: {ne: null }}}
) {
edges {
node {
id
name
description
date(formatString: "Do MMMM, YYYY")
link
poster {
childImageSharp {
fluid {
src
}
}
}
file {
url
}
}
}
}
}
More details in GraphQL Query Options Reference.

How can I filter by uid of a linked document / relationship using the prismic graphql api?

I am trying to list a set of articles by their categories, by uid, and I'm assuming that I would have to use the where query, but I'm not able to get that to worked on linked documents.
The issue seems to be that where only accepts a string on a field, but in the case of a linked document you would need to dig down to the uid field.
I'm not sure if I'm using the wrong query, but struggling to find anything in the documentation to help me out.
I tried digging into the category object:
{
allDirectoryServices(
where: { category: { _meta: { uid: "developers" } } }
) {
edges {
node {
name
city
region
country
category {
...on DirectoryTaxonomy {
_meta {
uid
}
name
}
}
}
}
}
}
But that returns an error that it's expecting a string:
"message": "Expected type String, found {_meta: {uid: \"developers\"}}.",
{
allDirectoryServices(
where: { category: "developers"}
) {
edges {
node {
name
city
region
country
category {
...on DirectoryTaxonomy {
_meta {
uid
}
name
}
}
}
}
}
}
This returns no results, obviously.
I asked this question on the Prismic Slack group too, and got the answer from them:
In order to query by a Content Relationship / Link field like this, you need to use the document ID.
where: { category: "WBsLfioAABNUo9Kk" }
Unfortunately it isn’t possible to query by the UID (or any other field).
I imagine they will be updating their documentation soonish, as this isn't covered by it.
Thanks to the Prismic guys!

How to get variant by variant Id from product object using by graphql Shopify

Query so far
{
product1: product(id: "gid://shopify/Product/777854222396") {
title
totalVariants
variants(first:99) {
.....
}
hasOutOfStockVariants
}
product2: product(id: "gid://shopify/Product/511571296316") {
title
}
}
What can be done to fetch variant based on id
I have found ProductVariant on their GraphQL Admin API reference docs, you can take reference from their else I didn't find any ProductVariant Schema open at QueryRoot as defined here in the open graphQL admin panel although they have mentioned an example.
query {
productVariant(id: "gid://shopify/ProductVariant/10782354800682") {
inventoryItem {
inventoryLevels (first:10) {
edges {
node {
location {
name
}
available
}
}
}
}
}
}

How do I query the GitHub v4 API for directory contents at a certain tag?

How do I query the GitHub API v4 for the contents of a certain directory of a repository at a certain tag?
This is the best I've come up with so far:
query {
repository(owner:"example", name:"example") {
refs(refPrefix: "tags") {
}
}
}
From this post, you can get the GitObject with object to filter on branch:/path/folder and print the Tree. The following will get the tree from gson folder from tag gson-2.4 and print name, type and mode :
query {
repository(owner:"google", name:"gson") {
object(expression: "gson-2.4:gson") {
... on Tree{
entries{
name
type
mode
}
}
}
}
}

Resources