Repository navigation
fix(generator): driver-aware Atlas HCL, GraphQL-style REST bodies, invalid ids - #15
Merged
Merged
Conversation
…valid ids - table.hcl.tmpl renders MySQL, Postgres or SQLite types and uses the schema declared in db/atlas/schema/schema.hcl (falling back to public / the app database / main). make:migration writes it again; it was a silent no-op. - REST create/update bodies no longer use validate:"required": a non-null field is required as a key but accepts 0/false/"", and nullable fields are optional (required:"false"), matching the GraphQL input. - Values the database can't parse (orm.ErrInvalidInput, e.g. a malformed uuid on Postgres) are 404 for path ids and 422 for body values in REST; null/false or BAD_USER_INPUT in GraphQL, instead of 500.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes three of the framework bugs the D3 worker left out of scope in #14.
Depends on togo-framework/togo#1 and togo-framework/orm#2; pairs with togo-framework/create-togo-app#8.
Atlas
table.hcl.tmplis driver-awaresql("char(36)")+(uuid()),datetime(6)+CURRENT_TIMESTAMP(6).text,lower(hex(randomblob(16))),datetime('now').db/atlas/schema/schema.hcl. If there isn't one it falls back topublic, the app database, ormain. The create-togo-app PR makes that file per driver.make:migrationwrites the HCL again; since edd8532 it had been a silent no-op.togo migratedoesn't depend on it.REST bodies match GraphQL
validate:"required"is dropped from create/update bodies, so 0, false and "" are accepted. A non-null field is still required as a key (Huma's default).required:"false", so the key can be omitted.Invalid input isn't a 500
Handlers map
orm.ErrInvalidInput(orm PR) to:null/falseBAD_USER_INPUTAll use Huma's standard problem+json envelope.
Tests
table.hclon sqlite/postgres/mysql.TestAtlasTableHasNoPostgresSyntax,TestAtlasSchema,TestRestHandlerBodyTags,TestResolverMapsInvalidInput.\r, so it passes on CRLF checkouts too.Verified for real
On Docker Postgres 16, MySQL 8.4 and SQLite, using a CLI built from this branch with local togo/orm, I ran
togo new→make:resourcewith every field type →make:migration→generate→go build→migrate→ REST + GraphQL CRUD.0/false/""and the nullable keys omitted works on every driver.BAD_USER_INPUTfor a body value.atlas schema apply --dry-runshows no drift for the generated table on all three drivers.Notes
orm.ErrInvalidInput, so cli must not ship before that orm release. Bump the create-togo-app pin after its PR is released.atlas.hclreadsDATABASE_URL. For MySQL and SQLite that is a Go DSN, not an Atlas URL, so pass--urluntil that is aligned. Not changed here.int32?field doesn't compile on SQLite: sqlc gives*int64, the transform expects*int32.rolesand a TEXT key onscope.true.