I use the GitHub GraphQL API to search for files / code containing a specific word. A simple (far-fetched) search example, which in this case should find the term “beef” in the files located in the “recipes” (repo) for “someuser” (owner for the repo), is shown below:
{ search(query: "beef repo:someuser/recipes", type: REPOSITORY, first: 10) { repositoryCount edges { node { ... on Repository { name } } } } }
I tried this in the GitHub GraphQL Explorer ( https://developer.github.com/v4/explorer/ ) and got zero search results, which is incorrect as I can confirm that the word ("beef" in the example above) is in files in the repo:
{ "data": { "search": { "repositoryCount": 0, "edges": [] } } }
When I try to use this with the GitHub REST API (v3) via curl, I definitely get the results:
curl --header 'Accept: application/vnd.github.v3.raw' https://api.github.com/search/code?q=beef+repo:someuser/recipes
... Therefore, I know that the request (REST v3 API) is valid, and I understand that the query string in the GraphQL API (v4) is identical to the string for the REST API (v3).
My questions:
- Am I using the GitHub GraphQL API (v4) incorrectly or setting the query string incorrectly, or am I trying to use functionality that is not yet supported?
- Is there an example of how to do this so that someone can provide (or a link) that illustrates the code search for specific words?
github github-api graphql
Eric broda
source share