Skip to content
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

fix: Use cases for titling instead of strings to handle deprecation #457

Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
github.com/fatih/color v1.13.0
github.com/go-chi/chi/v5 v5.0.7
github.com/pkg/errors v0.9.1
golang.org/x/text v0.3.7
)

require (
Expand Down Expand Up @@ -211,7 +212,6 @@ require (
golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/genproto v0.0.0-20220204002441-d6cc3cc0770e // indirect
Expand Down
13 changes: 8 additions & 5 deletions query/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"context"
"errors"
"fmt"
"strings"

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/logging"
"github.com/sourcenetwork/defradb/query/graphql/parser"
"github.com/sourcenetwork/defradb/query/graphql/schema/types"
"golang.org/x/text/cases"
"golang.org/x/text/language"

gql "github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/language/ast"
Expand Down Expand Up @@ -552,15 +553,15 @@ func (g *Generator) genAggregateFields(ctx context.Context) error {

func (g *Generator) genCountFieldConfig(obj *gql.Object) (gql.Field, error) {
childTypesByFieldName := map[string]*gql.InputObject{}
caser := cases.Title(language.Und)

for _, field := range obj.Fields() {
// Only lists can be counted
if _, isList := field.Type.(*gql.List); !isList {
continue
}

countableObject := gql.NewInputObject(gql.InputObjectConfig{
Name: fmt.Sprintf("%s%s%s", obj.Name(), strings.Title(field.Name), "CountInputObj"),
Name: fmt.Sprintf("%s%s%s", obj.Name(), caser.String(field.Name), "CountInputObj"),
Fields: gql.InputObjectConfigFieldMap{
"_": &gql.InputObjectFieldConfig{
Type: gql.Int,
Expand Down Expand Up @@ -669,6 +670,7 @@ func (g *Generator) genAverageFieldConfig(obj *gql.Object, numBaseArgs map[strin

func (g *Generator) genNumericInlineArraySelectorObject(obj *gql.Object) []*gql.InputObject {
objects := []*gql.InputObject{}
caser := cases.Title(language.Und)
for _, field := range obj.Fields() {
// we can only act on list items
listType, isList := field.Type.(*gql.List)
Expand All @@ -680,7 +682,7 @@ func (g *Generator) genNumericInlineArraySelectorObject(obj *gql.Object) []*gql.
// If it is an inline scalar array then we require an empty
// object as an argument due to the lack of union input types
selectorObject := gql.NewInputObject(gql.InputObjectConfig{
Name: genNumericInlineArraySelectorName(obj.Name(), strings.Title(field.Name)),
Name: genNumericInlineArraySelectorName(obj.Name(), caser.String(field.Name)),
Fields: gql.InputObjectConfigFieldMap{
"_": &gql.InputObjectFieldConfig{
Type: gql.Int,
Expand All @@ -696,7 +698,8 @@ func (g *Generator) genNumericInlineArraySelectorObject(obj *gql.Object) []*gql.
}

func genNumericInlineArraySelectorName(hostName string, fieldName string) string {
return fmt.Sprintf("%s%s%s", hostName, strings.Title(fieldName), "NumericInlineArraySelector")
caser := cases.Title(language.Und)
return fmt.Sprintf("%s%s%s", hostName, caser.String(fieldName), "NumericInlineArraySelector")
}

// Generates the base (numeric-only) aggregate input object-type for the give gql object,
Expand Down