Skip to content

Commit

Permalink
fix: Remove having gql types (#785)
Browse files Browse the repository at this point in the history
Is non functional and unimplemented and adds notable overhead for development
  • Loading branch information
AndrewSisley authored Sep 9, 2022
1 parent 9c04fee commit e96c1c9
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 81 deletions.
4 changes: 2 additions & 2 deletions query/graphql/schema/examples/example.schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ input AuthorOrderArg {
}

type Query {
books(filter: BookFilterArg, groupBy: [BookFields!], having: BookHavingArg, order: BookOrderArg, limit: Int, offset: Int) [Book]
authors(filter: AuthorFilterArg, groupBy: [AuthorFields!], having: AuthorHavingArg, order: AuthorOrderArg, limit: Int, offset: Int) [Author]
books(filter: BookFilterArg, groupBy: [BookFields!], order: BookOrderArg, limit: Int, offset: Int) [Book]
authors(filter: AuthorFilterArg, groupBy: [AuthorFields!], order: AuthorOrderArg, limit: Int, offset: Int) [Author]
}
1 change: 0 additions & 1 deletion query/graphql/schema/examples/root.schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ enum ValueOperatorInput {
input GenericQueryInput {
filter: GenericFilterArg
groupBy: [GenericGroupByArg]
having: GenericHavingArg
order: GenericOrderArg
limit: GenericLimitArg
offset: GenericOffsetArg
Expand Down
51 changes: 0 additions & 51 deletions query/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ func (g *Generator) createExpandedFieldList(
"groupBy": schemaTypes.NewArgConfig(
gql.NewList(gql.NewNonNull(g.manager.schema.TypeMap()[typeName+"Fields"])),
),
"having": schemaTypes.NewArgConfig(g.manager.schema.TypeMap()[typeName+"HavingArg"]),
"order": schemaTypes.NewArgConfig(g.manager.schema.TypeMap()[typeName+"OrderArg"]),
parserTypes.LimitClause: schemaTypes.NewArgConfig(gql.Int),
parserTypes.OffsetClause: schemaTypes.NewArgConfig(gql.Int),
Expand Down Expand Up @@ -978,7 +977,6 @@ func (g *Generator) GenerateQueryInputForGQLType(

// @todo: Don't add sub fields to filter/order for object list types
types.groupBy = g.genTypeFieldsEnum(obj)
types.having = g.genTypeHavingArgInput(obj)
types.order = g.genTypeOrderArgInput(obj)

queryField := g.genTypeQueryableFieldList(ctx, obj, types)
Expand Down Expand Up @@ -1199,44 +1197,6 @@ func (g *Generator) genLeafFilterArgInput(obj gql.Type) *gql.InputObject {
return selfRefType
}

// query spec - sec N
func (g *Generator) genTypeHavingArgInput(obj *gql.Object) *gql.InputObject {
inputCfg := gql.InputObjectConfig{
Name: genTypeName(obj, "HavingArg"),
}
fields := gql.InputObjectConfigFieldMap{}
havingBlock := g.genTypeHavingBlockInput(obj)

for _, field := range obj.Fields() {
if gql.IsLeafType(field.Type) { // only Scalars, and enums
fields[field.Name] = &gql.InputObjectFieldConfig{
Type: havingBlock,
}
}
}

inputCfg.Fields = fields
return gql.NewInputObject(inputCfg)
}

func (g *Generator) genTypeHavingBlockInput(obj *gql.Object) *gql.InputObject {
inputCfg := gql.InputObjectConfig{
Name: genTypeName(obj, "HavingBlock"),
}
fields := gql.InputObjectConfigFieldMap{}

for _, field := range obj.Fields() {
if gql.IsLeafType(field.Type) { // only Scalars, and enums
fields[field.Name] = &gql.InputObjectFieldConfig{
Type: g.manager.schema.TypeMap()["FloatOperatorBlock"],
}
}
}

inputCfg.Fields = fields
return gql.NewInputObject(inputCfg)
}

func (g *Generator) genTypeOrderArgInput(obj *gql.Object) *gql.InputObject {
inputCfg := gql.InputObjectConfig{
Name: genTypeName(obj, "OrderArg"),
Expand Down Expand Up @@ -1279,7 +1239,6 @@ func (g *Generator) genTypeOrderArgInput(obj *gql.Object) *gql.InputObject {
type queryInputTypeConfig struct {
filter *gql.InputObject
groupBy *gql.Enum
having *gql.InputObject
order *gql.InputObject
}

Expand Down Expand Up @@ -1309,15 +1268,6 @@ func (g *Generator) genTypeQueryableFieldList(
)
}

if err := g.manager.schema.AppendType(config.having); err != nil {
log.ErrorE(
ctx,
"Failed to append runtime schema with having",
err,
logging.NewKV("SchemaItem", config.having),
)
}

if err := g.manager.schema.AppendType(config.order); err != nil {
log.ErrorE(
ctx,
Expand All @@ -1337,7 +1287,6 @@ func (g *Generator) genTypeQueryableFieldList(
"cid": schemaTypes.NewArgConfig(gql.String),
"filter": schemaTypes.NewArgConfig(config.filter),
"groupBy": schemaTypes.NewArgConfig(gql.NewList(gql.NewNonNull(config.groupBy))),
"having": schemaTypes.NewArgConfig(config.having),
"order": schemaTypes.NewArgConfig(config.order),
parserTypes.LimitClause: schemaTypes.NewArgConfig(gql.Int),
parserTypes.OffsetClause: schemaTypes.NewArgConfig(gql.Int),
Expand Down
2 changes: 1 addition & 1 deletion query/graphql/schema/type.schema.gen.gql.template
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ input {TYPE_NAME}OrderArg {
}

extend type Query {
{collection_name}(filter: {TYPE_NAME}FilterArg, groupBy: [{TYPE_NAME}Fields!], having: {TYPE_NAME}HavingArg, order: {TYPE_NAME}OrderArg, limit: Int, offset: Int) [{TYPE_NAME}]
{collection_name}(filter: {TYPE_NAME}FilterArg, groupBy: [{TYPE_NAME}Fields!], order: {TYPE_NAME}OrderArg, limit: Int, offset: Int) [{TYPE_NAME}]
}
23 changes: 0 additions & 23 deletions tests/integration/schema/default_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,29 +165,6 @@ var offsetArg = field{
},
}

func buildHavingArg(objectName string, fields ...string) field {
havingBlockName := objectName + "HavingBlock"
inputFields := []any{
makeInputObject("_avg", havingBlockName, nil),
makeInputObject("_count", havingBlockName, nil),
makeInputObject("_key", havingBlockName, nil),
makeInputObject("_sum", havingBlockName, nil),
}

for _, field := range fields {
inputFields = append(inputFields, makeInputObject(field, havingBlockName, nil))
}

return field{
"name": "having",
"type": field{
"name": objectName + "HavingArg",
"ofType": nil,
"inputFields": inputFields,
},
}
}

type argDef struct {
fieldName string
typeName string
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/schema/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ var defaultUserArgsWithoutFilter = trimFields(
groupByArg,
limitArg,
offsetArg,
buildHavingArg("users", "name"),
buildOrderArg("users", []argDef{
{
fieldName: "name",
Expand Down Expand Up @@ -279,7 +278,6 @@ var defaultBookArgsWithoutFilter = trimFields(
groupByArg,
limitArg,
offsetArg,
buildHavingArg("book", "author_id", "name"),
buildOrderArg("book", []argDef{
{
fieldName: "author",
Expand Down
1 change: 0 additions & 1 deletion tests/integration/schema/input_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ var defaultGroupArgsWithoutOrder = trimFields(
},
}),
groupByArg,
buildHavingArg("author", "age", "name", "verified", "wrote_id"),
limitArg,
offsetArg,
},
Expand Down

0 comments on commit e96c1c9

Please sign in to comment.