diff --git a/graphql/keyspace_schema.go b/graphql/keyspace_schema.go index c75901b..9ddadbe 100644 --- a/graphql/keyspace_schema.go +++ b/graphql/keyspace_schema.go @@ -2,6 +2,7 @@ package graphql import ( "fmt" + "regexp" "github.com/gocql/gocql" "github.com/graphql-go/graphql" @@ -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: @@ -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 { @@ -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,