Skip to content

Use the keyspace schema to define the graphql names beforehand #33

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 6 commits into from
Apr 6, 2020

Conversation

jorgebay
Copy link
Contributor

@jorgebay jorgebay commented Apr 3, 2020

Generates all the table->entity names beforehand to make the naming conversion operations reversible and avoids name collisions with built-in types.

Fixes #27 and #31 .

I didn't make the code reorg as part of this patch to isolate the changes and make it easier to review.

Also note that this doesn't include the changes discussed in #32 .

@jorgebay jorgebay requested a review from mpenick April 3, 2020 10:17
@jorgebay jorgebay linked an issue Apr 3, 2020 that may be closed by this pull request
@jorgebay
Copy link
Contributor Author

jorgebay commented Apr 3, 2020

Rebased against master.

keyspaceSchema := &KeyspaceGraphQLSchema{
ignoredTables: make(map[string]bool),
schemaGen: sg,
naming: sg.namingFn(ksNaming),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so cool! Naming gets updated properly with the latest version of the schema.

Copy link
Contributor

@mpenick mpenick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Maybe a couple things, but ignorable.

config/naming.go Outdated
func (n *defaultNaming) ToGraphQLOperation(prefix string, name string) string {
func (n *snakeCaseToCamelNaming) ToCQLTable(name string) string {
// lookup table name by entity name
tableName := n.tablesByEntities[name]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Use the tableName, found := n.tablesByEntities[name] syntax? Same in couple other places. If you disagree I really don't mind at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, I'll change it

tableName := n.tablesByEntities[name]
if tableName == "" {
// Default to snake_case for tables that doesn't exist yet (DDL)
return strcase.ToSnake(name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use use solution A) from issue #32 then this is an error case, and shouldn't ever happen right? Same applies to ToCQLColumn(), ToGraphQLType(), etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct!

db/db.go Outdated
// KeyspaceNamingInfo Retrieves the keyspace naming information
func (db *Db) KeyspaceNamingInfo(ks *gocql.KeyspaceMetadata) config.KeyspaceNamingInfo {
result := keyspaceNamingInfo{
tables: make(map[string][]string, 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Reserve capacity (len(ks.Tables)) like for the column below.

@@ -472,7 +481,11 @@ func (sg *SchemaGenerator) mutationFieldResolver(keyspace *gocql.KeyspaceMetadat
}
}

func (sg *SchemaGenerator) getModificationResult(rs db.ResultSet, err error) (*types.ModificationResult, error) {
func (s *KeyspaceGraphQLSchema) getModificationResult(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These func (s *KeyspaceGraphQLSchema) methods eventually going to be moved to keyspace_schema.go?

If so, thanks for making the commit diff look nice. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it will be moved :)

@jorgebay
Copy link
Contributor Author

jorgebay commented Apr 6, 2020

I've addressed the suggestions from the review.

@jorgebay jorgebay merged commit e97cc70 into master Apr 6, 2020
@jorgebay jorgebay deleted the naming2 branch April 6, 2020 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid GraphQL type name collisions Make naming convention a reversible operation by default
2 participants