Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kevinmichaelchen/graphql-schema-picker

GraphQL CLI to prune, filter, pick, select, and distill a sub-schema when given a Schema Definition Language (SDL) file. 🪛
https://github.com/kevinmichaelchen/graphql-schema-picker

Last synced: about 1 month ago
JSON representation

GraphQL CLI to prune, filter, pick, select, and distill a sub-schema when given a Schema Definition Language (SDL) file. 🪛

Awesome Lists containing this project

README

        

# graphql-schema-picker

[![GoReportCard example](https://goreportcard.com/badge/github.com/kevinmichaelchen/graphql-schema-picker)](https://goreportcard.com/report/github.com/kevinmichaelchen/graphql-schema-picker)
[![version](https://img.shields.io/github/v/release/kevinmichaelchen/graphql-schema-picker?include_prereleases&label=latest&logo=ferrari)](https://github.com/kevinmichaelchen/graphql-schema-picker/releases/latest)
[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/kevinmichaelchen/graphql-schema-picker)](https://codeclimate.com/github/kevinmichaelchen/graphql-schema-picker)

A CLI for selectively pruning your GraphQL schemas.

The CLI accepts a Schema Definition Language file, and then selectively picks
(or filters out) certain elements.

## Motivation

This tool was born out of a desire to reuse Hasura's schema in upstream
microservices. In my case, it meant discarding the tens of thousands of lines
in the schema that was introspected from Hasura, and really only paying
attention to the few types I cared about.

## Example

For a realistic example of what a Hasura GraphQL schema looks like, check out
our example [**SDL file**][sdl-file] (Schema Definition Language).

[sdl-file]: ./examples/hasura.sdl.graphqls

## Getting Started

### Installing

Eventually, I may package this up in Tea and maybe even Homebrew (via
[Goreleaser][goreleaser-brew]).

[goreleaser-brew]: https://goreleaser.com/customization/homebrew/

#### With `go install`

```shell
go install github.com/kevinmichaelchen/graphql-schema-picker@latest
```

#### With Docker

```shell
docker pull ghcr.io/kevinmichaelchen/graphql-schema-picker
docker run --rm ghcr.io/kevinmichaelchen/graphql-schema-picker --help

docker run --rm \
-v $(pwd)/examples:/examples \
ghcr.io/kevinmichaelchen/graphql-schema-picker \
--debug \
pick \
--output /examples/pruned.sdl.graphqls \
--sdl-file /examples/hasura.sdl.graphqls \
--definitions Aircrafts
```

## Similar Tools

- https://github.com/n1ru4l/graphql-public-schema-filter
- https://github.com/kesne/graphql-schema-subset
- https://github.com/xometry/graphql-code-generator-subset-plugin
- https://the-guild.dev/graphql/tools/docs/api/classes/wrap_src.pruneschema
- https://pothos-graphql.dev/docs/plugins/sub-graph

## Contributing

### Building

```shell
go run cmd/graphql-schema-picker/main.go \
--debug \
pick \
--output examples/pruned.sdl.graphqls \
--sdl-file examples/hasura.sdl.graphqls \
--definitions Aircrafts
```

### Releasing

Create tags with `xc tag` and push them with `git push --tags`.

## Tasks

### build

Builds the Go program into a local binary.

```shell
goreleaser build --clean --single-target
```

### tag

Create a new Git tag

```shell
sh <(curl https://tea.xyz) +github.com/caarlos0/svu \
git tag -a $(svu next) -m "$(svu next)"
```