How to search code using GraphQL?

schema-request

#1

I want to port a search call from v3 to the shinny new v4. The call search for files with a given name in the specified repository. This is my search term I’m using for v3: q=${target}+in:path+filename:${target}+repo:${user}/${repo}.

Unfortunately there is no searchType CODE available. Are you planning to implement or is there another workaround how I can achieve this in GraphQL?

Cheers


#2

+1 This question - I’d love to know if GitHub plans to implement a CODE search for the GraphQL API.


#3

Edit: Actually, just realized they have the Blob object which serves this function. Disregard -


Additionally, they’d have to implement some sort of Code or File object, such that a query similar to the following is valid:

query {
  search(type:CODE, query:"filename:makefile" first:3) {
    codeCount
    edges {
      node {
	    ... on File {
          name
          contents
        }
      }
    }
  }
}

As that is how it works with the web interface :wink:


#4

Can you post the resultant query using the Blob object? I’d like to query the contents of all files that have a certain query string, and so far, have not been able to come up with a working query!


#5

Was there any news regarding the possibility to get type:CODE?

I’d like to be able to query something like

{
  search(query: "drake language:r", type: CODE, first: 100) {
    edges {
      node {
        ... on Repository {
          name
          owner {
            login
          }
          description
          url
        }
      }
    }
  }
}

#6

any update on this? I’d also like to use this as well… the disparity between graphql and rest is a bit frustrating. please tell me this is coming soon. :frowning:


#7

Hello!

I’ve added this to our internal list of feature requests. I can’t give a great ETA for this feature, but we’ll be sure to post here once it’s shipped.