Sourcegraph GraphQL API examples
This page demonstrates a few example GraphQL queries for the Sourcegraph GraphQL API.
GraphQL query | Description | Example use case |
---|---|---|
Get the contents of a file on the default branch | Returns the file contents. | Quickly fetch file contents without cloning a repository or hitting your code host API (which is usually slower or more rate-limited than Sourcegraph). |
Perform a search query and get results |
Returns the search result metadata (whether or not the search result limit was hit, if the search timed out, etc.) and the actual results of the search query, which can be one of three types: Repository , FileMatch , or CommitSearchResult .
|
Search for a new framework or API that you are using (or have deprecated) and determine all of the repositories that haven't yet been migrated. |
Compare 2 commits | Returns a list of changes between 2 commits. | Scan diffs between the old and new versions of a deployed service for changes that might indicate an incompatibility (e.g., in a service discovery manifest). |
List the first 1,000 repositories | Returns the name, description, and URL of the first 1,000 repositories on the Sourcegraph server (in order of their creation date). | |
List all files in a repository | Returns every file in the repository, its path (relative to the repository root), whether or not it is a directory or plain file, and what the URL path to the file is. | List all of the files in each repository of your organization (when combined with the "List the first 1000 repositories" example above) to determine which of your repositories are missing important files like READMEs, LICENSEs, and Dockerfiles. |
List the languages used in a repository | Returns the primary language of the repository as well as a list of all the languages used in the repository. | List all of the languages in each repository of your organization (when combined with the "List the first 1000 repositories" example above) to determine how many repos use each language across your entire organization. |