GraphQL using a field as argument in the same query - graphql

I have constructed the following query in Gitlab's GraphQL Explorer to show my question:
https://gitlab.com/-/graphql-explorer
{
project(fullPath: "gitlab-org/gitlab") {
name
repository {
rootRef
}
mergeRequests(state: merged, targetBranches: "master") {
nodes {
sourceBranch
targetBranch
}
}
}
}
What I would like to achieve is using the value of repository { rootRef } as the argument for targetBranches.
Something like this:
mergeRequests(state: merged, targetBranches: repository { rootRef }) {
Can it be done?
Thank you!

Related

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

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

GraphQL query filtering multiple relations

(From Strapi) I am trying to get all "acts" with a certain age (can return multiple) and with a certain place (can return multiple). I can't figure out how to filter that.
This is what I am trying in GraphQL-playground (works without the variables), but it says "Unknown argument "age" on field "Act.ages"." (and "place" respectively).
query GetActs ($age:Int, $place:String) {
acts {
data {
id
attributes {
Title
ages (age: $age) {
data {
id
attributes {
age
}
}
}
places (place: $place) {
data {
id
attributes {
place
}
}
}
}
}
}
}
I just ran into this same issue. I can't make out the error you're reporting, but here is what worked for me.
You can use filter at the collection level to drill down to nested fields for the corresponding attributes. This follows the GraphQL example at the bottom of this Strapi resource on filtering nested fields.
Solution
query GetActs ($age:Int, $place:String) {
acts (filters: {ages: {age: {eq: $age}}, places: {place: {eq: $place}}}) {
data {
id
attributes {
Title
ages {
data {
id
attributes {
age
}
}
}
places {
data {
id
attributes {
place
}
}
}
}
}
}
}

get rawTextBlob from all repository files matching path glob pattern

GraphQL beginner here. I am looking out for something like a SQL join so that I may feed the list of repository files from one query as criteria for another query.
I can get a nice result if I know the file path from each project like this:
{
group(fullPath: "group/path") {
projects {
nodes {
name
repository {
blobs(paths: ["global.tfvars"]) {
nodes {
rawTextBlob
}
}
}
}
}
}
}
But what if I don't know the exact file paths up front, e.g I need all the files matching environments/*/local.tfvars
If specifying a glob pattern is not an option, then I would think that need some kind of join with something like this:
{
group(fullPath: "group/path") {
id
name
projects {
nodes {
name
repository {
paginatedTree(path: "environments", recursive: true) {
nodes {
blobs {
nodes {
path
}
}
}
}
}
}
}
}
}

graphQL : Use variable in string

I'm using strapi V4 plugin system and I want to query all comments relative to a specific post.
The default graphql request look like that :
query () {
findAllFlat (relation: "api::post.post:77") {
data {
...
}
}
}
But I need to add a variable instead of 77, ideally I would like to do something like this :
query ($postId:ID!) {
findAllFlat (relation: "api::post.post:${postId}") {
data {
...
}
}
}
But of course, string template doesn't work with graphQL. Is there another way ?

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