Documentation
¶
Overview ¶
Package schema provides methods to query GitHub GraphQL schema offline.
The embedded schema is obtained via GitHub GraphQL API introspection and stored in the standard GraphQL introspection format. This allows querying GitHub's GraphQL type system without making API calls.
Basic usage:
// Use embedded schema
s, err := schema.New()
if err != nil {
log.Fatal(err)
}
// Query type information
result, err := s.Type("Repository")
The schema can be updated using go:generate or the CLI tool:
go generate ./schema # or github-schema download --compress -o schema/schema.json.gz
Custom schemas can be loaded from files:
s, err := schema.NewWithFile("custom-schema.json")
The schema file must be in GraphQL introspection format with the standard structure: {"data": {"__schema": {...}}}
Index ¶
- Constants
- func DownloadAndCompressSchema(outputPath string) error
- func DownloadAndCompressToWriter(w io.Writer) error
- func DownloadIntrospectionSchema(outputPath string) error
- func DownloadIntrospectionToWriter(w io.Writer) error
- func DownloadSchema(outputPath string) error
- func DownloadToWriter(w io.Writer) error
- type Schema
- func (s *Schema) Mutation(mutationName string) (map[string]interface{}, error)
- func (s *Schema) Query(jqQuery string, variables map[string]interface{}) (interface{}, error)
- func (s *Schema) Search(pattern string) (map[string]interface{}, error)
- func (s *Schema) Type(typeName string) (map[string]interface{}, error)
Constants ¶
const ( // GitHubAPIURL is the GitHub GraphQL API endpoint GitHubAPIURL = "https://api.github.com/graphql" // IntrospectionQuery is the GraphQL introspection query IntrospectionQuery = `` /* 1335-byte string literal not displayed */ )
const ( // ListMutationsQuery lists all available mutations ListMutationsQuery = `.data.__schema.types[] | select(.name == "Mutation") | .fields[] | .name` // ListTypesQuery lists all type names ListTypesQuery = `.data.__schema.types[] | .name` // ListObjectTypesQuery lists only object types ListObjectTypesQuery = `.data.__schema.types[] | select(.kind == "OBJECT") | .name` // ListInputTypesQuery lists only input types ListInputTypesQuery = `.data.__schema.types[] | select(.kind == "INPUT_OBJECT") | .name` )
Variables ¶
This section is empty.
Functions ¶
func DownloadAndCompressSchema ¶
DownloadAndCompressSchema downloads the schema with gzip compression. When possible, it uses GitHub API's native gzip compression to reduce bandwidth usage. The compressed data is saved directly without re-compression.
func DownloadAndCompressToWriter ¶
DownloadAndCompressToWriter downloads introspection schema with native compression and writes to writer
func DownloadIntrospectionSchema ¶
DownloadIntrospectionSchema downloads the GitHub GraphQL schema using the standard introspection query. The schema is saved in the GraphQL introspection format, which includes the data wrapper: {"data": {"__schema": {...}}}. Requires GitHub authentication via 'gh auth login'.
func DownloadIntrospectionToWriter ¶
DownloadIntrospectionToWriter downloads introspection schema and writes to writer
func DownloadSchema ¶
DownloadSchema downloads the schema using GitHub GraphQL API introspection. This is an alias for DownloadIntrospectionSchema for backward compatibility.
func DownloadToWriter ¶
DownloadToWriter downloads introspection schema and writes to writer
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema provides methods to query GitHub GraphQL schema
func NewWithData ¶
NewWithData creates a Schema instance from raw JSON data
func NewWithFile ¶
NewWithFile creates a Schema instance from a file