Drizzle GraphQL bug with SQLite JSON (Turso)

Hey, just found that it doesn't "decode/extract" the JSON when we have text({ mode: 'json' }).$type<{ [key: 0x${string}]: number }>().default({}) I'm using GraphQL Yoga to check the seeded data, and it shows that column as plain string, not extracted json. Probably bug in your graphql resolvers. Or this is intentional? I don't see why would it tho.
No description
No description
3 Replies
WGW ☂ calldata.space
The royalties field is "json type" in the schema. Here's the full schema:
export const collections = sq.sqliteTable('collections', {
id: sq.text().primaryKey().$defaultFn(createCuidV2),
supply: sq.integer().notNull(),
slug: sq.text().notNull(),
name: sq.text().notNull(),
description: sq.text().notNull(),
logo: sq.text().default('https://example.com/logo.png'),
banner: sq.text().default('https://example.com/banner.png'),
links: sq.text({ mode: 'json' }).$type<`https://${string}`[]>().default([]),
team: sq.text({ mode: 'json' }).$type<(`0x${string}` | string)[]>().default([]),
royalties: sq.text({ mode: 'json' }).$type<{ [key: `0x${string}`]: number }>().default({}),
verified: sq.integer({ mode: 'boolean' }).default(false),
});
export const collections = sq.sqliteTable('collections', {
id: sq.text().primaryKey().$defaultFn(createCuidV2),
supply: sq.integer().notNull(),
slug: sq.text().notNull(),
name: sq.text().notNull(),
description: sq.text().notNull(),
logo: sq.text().default('https://example.com/logo.png'),
banner: sq.text().default('https://example.com/banner.png'),
links: sq.text({ mode: 'json' }).$type<`https://${string}`[]>().default([]),
team: sq.text({ mode: 'json' }).$type<(`0x${string}` | string)[]>().default([]),
royalties: sq.text({ mode: 'json' }).$type<{ [key: `0x${string}`]: number }>().default({}),
verified: sq.integer({ mode: 'boolean' }).default(false),
});
When i try to read team or links it throws error too. Oh, just seen i've got errors on the terminal:
^
GraphQLError: String cannot represent value: ["https://tall-loyalty.name/", "https://warm-permafrost.org", "https://lavish-mentor.net/", "https://productive-cleaner.org", "https://wasteful-wallaby.biz"]
at completeLeafValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:612:23)
at executeField (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:387:15)
at executeFields (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:285:16)
at collectAndExecuteSubfields (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:996:32)
at completeValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:572:29)
at completeListItemValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:832:33)
at completeListValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:808:14)
at completeValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:572:29)
at processTicksAndRejections (native:7:39)
^
GraphQLError: String cannot represent value: ["https://tall-loyalty.name/", "https://warm-permafrost.org", "https://lavish-mentor.net/", "https://productive-cleaner.org", "https://wasteful-wallaby.biz"]
at completeLeafValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:612:23)
at executeField (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:387:15)
at executeFields (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:285:16)
at collectAndExecuteSubfields (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:996:32)
at completeValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:572:29)
at completeListItemValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:832:33)
at completeListValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:808:14)
at completeValue (/home/charlike/code/next15-rsc-drizzle-turso-app/node_modules/@graphql-tools/executor/esm/execution/execute.js:572:29)
at processTicksAndRejections (native:7:39)
I'm guessing that's the value from the database but it cannot read it properly from text(mode: json) I'm also having similar error when read timestamps
created_at: sq.integer().notNull().default(sql`(unixepoch())`),
created_at: sq.integer().notNull().default(sql`(unixepoch())`),
neither integer({ mode: timestamp }), nor with .defaultNow It works when it's passed as orderBy: { created_at: {direction: asc } }, but know when i ask for the field oh wait, that last thing worked, okay. I was setting created_at: Date.now() when inserting. The OP is still valid problem tho.
scape
scape2w ago
Hi! I think it's because the actual mapping between parsed / stringified json is made by the orm, meaning, if you do the query via:
db.select({links: collections.links}) .from(collections).orderBy(desc(collections.id))
db.select({links: collections.links}) .from(collections).orderBy(desc(collections.id))
you will get the parsed variant in the result. Since you are making the query in GraphQL Yoga, it returns the real value, just as it is stored in your sqlite database - as a text
WGW ☂ calldata.space
Yeah, on orm query it works, but not on the graphql frontend. That's the thing if it was returning it like stringified json array it would still be okay, like it does for royalties which it returns like stringified object. But instead it throws errors for that links case. I'm not doing anything for the graphql, it's drizzle-graphql and it should handle sqlite json fields properly.
Want results from more Discord servers?
Add your server