Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rchernobelskiy committed Jun 18, 2020
1 parent dabefa2 commit e2feeaa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions graphql/keyspace_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package graphql

import (
"fmt"
"regexp"

"github.com/gocql/gocql"
"github.com/graphql-go/graphql"
Expand Down Expand Up @@ -102,6 +103,8 @@ var serialConsistencyEnum = graphql.NewEnum(graphql.EnumConfig{
},
})

var validName = regexp.MustCompile(`^[_a-zA-Z][_a-zA-Z0-9]*$`)

func (s *KeyspaceGraphQLSchema) buildType(typeInfo gocql.TypeInfo, isInput bool) (graphql.Output, error) {
switch typeInfo.Type() {
case gocql.TypeInt, gocql.TypeTinyInt, gocql.TypeSmallInt:
Expand Down Expand Up @@ -279,6 +282,10 @@ func (s *KeyspaceGraphQLSchema) buildTableTypes(keyspace *gocql.KeyspaceMetadata
for name, column := range table.Columns {
var fieldType graphql.Output
var inputFieldType graphql.Output
if !validName.MatchString(table.Name) || !validName.MatchString(name) {
err = fmt.Errorf("table or column %s didn't match regex %s", name, validName.String())
break
}
fieldName := s.naming.ToGraphQLField(table.Name, name)
fieldType, err = s.buildType(column.Type, false)
if err != nil {
Expand Down Expand Up @@ -309,6 +316,10 @@ func (s *KeyspaceGraphQLSchema) buildTableTypes(keyspace *gocql.KeyspaceMetadata
}
}

if err == nil && (len(inputOperatorFields) == 0 || len(inputFields) == 0 || len(fields) == 0) {
err = fmt.Errorf("value, scalar, or input array empty - perhaps a table with one unfilterable column?")
}

if err != nil {
s.schemaGen.logger.Info("ignoring table",
"tableName", table.Name,
Expand Down

0 comments on commit e2feeaa

Please sign in to comment.