schema

package
v0.0.0-...-f1e9990 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 12 Imported by: 0

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

View Source
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 */

)
View Source
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

func DownloadAndCompressSchema(outputPath string) error

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

func DownloadAndCompressToWriter(w io.Writer) error

DownloadAndCompressToWriter downloads introspection schema with native compression and writes to writer

func DownloadIntrospectionSchema

func DownloadIntrospectionSchema(outputPath string) error

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

func DownloadIntrospectionToWriter(w io.Writer) error

DownloadIntrospectionToWriter downloads introspection schema and writes to writer

func DownloadSchema

func DownloadSchema(outputPath string) error

DownloadSchema downloads the schema using GitHub GraphQL API introspection. This is an alias for DownloadIntrospectionSchema for backward compatibility.

func DownloadToWriter

func DownloadToWriter(w io.Writer) error

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 New

func New() (*Schema, error)

New creates a Schema instance using the embedded schema

func NewWithData

func NewWithData(data []byte) (*Schema, error)

NewWithData creates a Schema instance from raw JSON data

func NewWithFile

func NewWithFile(path string) (*Schema, error)

NewWithFile creates a Schema instance from a file

func (*Schema) Mutation

func (s *Schema) Mutation(mutationName string) (map[string]interface{}, error)

Mutation queries information about a GraphQL mutation

func (*Schema) Query

func (s *Schema) Query(jqQuery string, variables map[string]interface{}) (interface{}, error)

Query runs a custom jq query on the schema

func (*Schema) Search

func (s *Schema) Search(pattern string) (map[string]interface{}, error)

Search searches for types matching a pattern

func (*Schema) Type

func (s *Schema) Type(typeName string) (map[string]interface{}, error)

Type queries information about a GraphQL type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL