Nested queries that touch to different objects

community-help

#1

Hello,

Basically, I’m trying to get all the repositories with primaryLanguage=javascript and belong to users in a particular area. Then, I’ll loop through the repositories and filter out some data such as if they are forked or not.

If I need to do this with v3, I first need to call /search/users?q=location:somewhere then, loop them and call /search/repositories?q=user:username language:javascript. As you can imagine, this gets really inefficient in a large user set and there’s a rate limiter.

So, I tried to get the same data with v4 and here’s my query:

// { "queryString": "location:izmir" }

query Search($queryString: String!) {
  search(query: $queryString, type: USER, first: 100) {
    userCount
    edges {
      cursor
      node {
        ... on User {
          login
          repositories(first: 100, orderBy: {field: CREATED_AT, direction: ASC}) {
            totalCount
            edges {
              cursor
              node {
                ... on Repository {
                  primaryLanguage {
                    name
                  }
                  isFork
                }
              }
            }
          }
        }
      }
    }
  }
}

As you can see, I can get all the users in the area and list their repositories, and also find if the repository is a fork or not. But I can’t filter the repositories according to a programming language.

An example result that I get is something like this:

{
  "data": {
    "search": {
      "userCount": 978,
      "edges": [
        {
          "cursor": "Y3Vyc29yOjE=",
          "node": {
            "login": "dnomak",
            "repositories": {
              "totalCount": 12,
              "edges": [
                {
                  "cursor": "Y3Vyc29yOnYyOpK5MjAxNC0wNy0yOFQwMTozNjoyNCswMzowMM4BVKP1",
                  "node": {
                    "primaryLanguage": {
                      "name": "CSS"
                    },
                    "isFork": false
                  }
                },
                {
                  "cursor": "Y3Vyc29yOnYyOpK5MjAxNS0wMS0xMlQxMjowNTowNyswMjowMM4BvHtm",
                  "node": {
                    "primaryLanguage": {
                      "name": "CSS"
                    },
                    "isFork": false
                  }
                },
                ...
              ]
            }
          }
        },
        ...
      ]
    }
  }
}

Hopefully, it’s clear to you to understand at which point I stuck. And looking forward to hear from you.

Thanks!


#2

Hey @gokaygurcan!

As you can see, I can get all the users in the area and list their repositories, and also find if the repository is a fork or not. But I can’t filter the repositories according to a programming language.

It isn’t currently possible to filter the repositories for a programming language. From the way you’ve structured your query, I think you’re on the right track! Once you’ve obtained the list of repositories, you could write a program that would filter the results for a primaryLanguage whose name is JavaScript (or some other language). I see how it would be helpful to have such a filter and I’ve let the team know about this internally so they can consider this in the future.

Hope that helps, but let me know if you have any other questions about this!


#3

Hi @francisfuzz

Thanks for your reply. It would be a really nice feature to have, so thanks for backing me and let you team know about this.

I’ll write something to filter them on my end as you told, it seems the best solution for now.

Cheers!