Skip to content

{cmd}: Adds working examples for single & multiple models. #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# Compatibility Base

### Use Cases

Validation compatibility base library for GraphQL implementations.

Currently used by the following libraries:

- https://github.com/graphql-go/compatibility-unit-tests
- https://github.com/graphql-go/compatibility-standard-definitions
- https://github.com/graphql-go/compatibility-user-acceptance

### Getting Started

Running single model example:
```
./bin/dev.sh single
```

Running multiple model example:
```
./bin/dev.sh multiple
```
6 changes: 5 additions & 1 deletion bin/dev.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/bin/bash

go run main.go
if [[ "$@" == "single" ]]; then
go run cmd/internal/single_model.go
elif [[ "$@" == "multiple" ]]; then
go run cmd/internal/multiple_model.go
fi
93 changes: 93 additions & 0 deletions cmd/internal/multiple_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package main

import (
"fmt"
"log"

"github.com/graphql-go/compatibility-base/bubbletea"
"github.com/graphql-go/compatibility-base/cmd"
"github.com/graphql-go/compatibility-base/config"
"github.com/graphql-go/compatibility-base/implementation"
)

func main() {
handleErr := func(err error) {
log.Fatal(err)
}

cfg := config.New()
defaultSpecTableHeader := fmt.Sprintf("Ref: %s", cfg.GraphqlJSImplementation.Repo.URL)
defaultImplTableHeader := "Impl: https://github.com/graphql-go/graphql"
choicesModelUIHeader := cfg.GraphqlJSImplementation.Repo.String(implementation.RefImplementationPrefix)

cmdParams := cmd.NewParams{
Bubbletea: bubbletea.New(&bubbletea.Params{
Models: bubbletea.Models{
bubbletea.NewChoicesModel(&bubbletea.ChoicesModelParams{
Order: 1,
Choices: cfg.AvailableImplementations,
UI: bubbletea.ChoicesModelUIParams{
Header: choicesModelUIHeader,
},
}),
newTableModel(defaultSpecTableHeader, defaultImplTableHeader),
},
BaseStyle: bubbletea.NewBaseStyle(),
}),
}
cli := cmd.New(&cmdParams)

resultCallback := func(result *bubbletea.BubbleTeaResult) error {
implementationHeader := result.ChoicesModelResult.Choice
tableModel := newTableModel(defaultSpecTableHeader, implementationHeader)

if err := cli.UpdateModel(tableModel); err != nil {
log.Printf("failed to update table model: %v", err)
return err
}

return nil
}

runParams := &cmd.RunParams{
ResultCallback: resultCallback,
}

if _, err := cli.Run(runParams); err != nil {
handleErr(err)
}
}

// `newTableModel` creates and returns a pointer to `bubbletea.TableModel`.
func newTableModel(specificationHeader string, implementationHeader string) *bubbletea.TableModel {
headerWidth := uint(16)

return bubbletea.NewTableModel(&bubbletea.TableModelParams{
Order: 2,
Headers: []bubbletea.TableHeader{
{Title: "Metric", Width: 35},
{Title: specificationHeader, Width: headerWidth},
{Title: implementationHeader, Width: headerWidth},
{Title: "Diff Ratio", Width: headerWidth},
{Title: "Max Diff", Width: headerWidth},
{Title: "Result", Width: headerWidth},
},
Rows: [][]string{
{"GitHub:", "", "", "", "", ""},
{"License", "MIT", "MIT", "0%", "0%", "✅"},
{"Number Of Stars", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"Number Of Issues Open", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"Number Of Issues Closed", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"Number Of Pull Requests Open", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"Number Of Pull Requests Closed", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"Number Of Forks", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"Last Commit Date", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"Number Of Contributors", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"GraphQL Compatibility Keywords:", "", "", "", "", ""},
{"Number Of Comments Open", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"Number Of Comments Closed", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
{"GraphQL:", "", "", "", "", ""},
{"Specification Version", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..."},
},
})
}
44 changes: 44 additions & 0 deletions cmd/internal/single_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"log"

"github.com/graphql-go/compatibility-base/bubbletea"
"github.com/graphql-go/compatibility-base/cmd"
"github.com/graphql-go/compatibility-base/config"
"github.com/graphql-go/compatibility-base/implementation"
)

func main() {
handleErr := func(err error) {
log.Fatal(err)
}

cfg := config.New()
choicesModelUIHeader := cfg.GraphqlJSImplementation.Repo.String(implementation.RefImplementationPrefix)

cmdParams := cmd.NewParams{
Bubbletea: bubbletea.New(&bubbletea.Params{
Models: bubbletea.Models{
bubbletea.NewChoicesModel(&bubbletea.ChoicesModelParams{
Order: 1,
Choices: cfg.AvailableImplementations,
UI: bubbletea.ChoicesModelUIParams{
Header: choicesModelUIHeader,
},
}),
},
BaseStyle: bubbletea.NewBaseStyle(),
}),
}
cli := cmd.New(&cmdParams)

runParams := &cmd.RunParams{
ResultCallback: nil,
}

if _, err := cli.Run(runParams); err != nil {
handleErr(err)
}
}