Skip to content

Commit

Permalink
Return json array as string instead of array
Browse files Browse the repository at this point in the history
  • Loading branch information
AneeshBhatnagar committed Jan 10, 2025
1 parent c558249 commit f15868c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "drizzle-graphql",
"type": "module",
"author": "Drizzle Team",
"version": "0.8.5",
"version": "0.8.6",
"description": "Automatically generate GraphQL schema or customizable schema config fields from Drizzle ORM schema",
"scripts": {
"build": "pnpm tsx scripts/build.ts",
Expand Down
1 change: 1 addition & 0 deletions src/util/data-mappers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const remapToGraphQLCore = (
);
}
if (column.columnType === 'PgGeometry' || column.columnType === 'PgVector') return value;
if (column.columnType === 'PgJson' || column.columnType === 'PgJsonb') return JSON.stringify(value);

return value.map((arrVal) => remapToGraphQLCore(key, arrVal, tableName, column, relationMap));
}
Expand Down
7 changes: 6 additions & 1 deletion tests/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ beforeEach(async () => {
await ctx.db.execute(sql`CREATE TABLE IF NOT EXISTS "posts" (
"id" serial PRIMARY KEY NOT NULL,
"content" text,
"author_id" integer
"author_id" integer,
"post_config" jsonb
);`);

await ctx.db.execute(sql`CREATE TABLE IF NOT EXISTS "users" (
Expand Down Expand Up @@ -217,11 +218,13 @@ beforeEach(async () => {
id: 1,
authorId: 1,
content: '1MESSAGE',
postConfig: ["config1", {"configName": "hello", "configValue": 123}]
},
{
id: 2,
authorId: 1,
content: '2MESSAGE',
postConfig: ["config2", {"configName": "hello", "configValue": 123}]
},
{
id: 3,
Expand Down Expand Up @@ -299,6 +302,7 @@ describe.sequential('Query tests', async () => {
id
authorId
content
postConfig
}
}
`);
Expand Down Expand Up @@ -330,6 +334,7 @@ describe.sequential('Query tests', async () => {
id: 1,
authorId: 1,
content: '1MESSAGE',
postConfig: "[\"config1\",{\"configName\":\"hello\",\"configValue\":123}]"
},
},
});
Expand Down
2 changes: 2 additions & 0 deletions tests/schema/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
char,
date,
geometry,
jsonb,
integer,
pgEnum,
pgTable,
Expand Down Expand Up @@ -53,6 +54,7 @@ export const Posts = pgTable('posts', {
id: serial('id').primaryKey(),
content: text('content'),
authorId: integer('author_id'),
postConfig: jsonb('post_config'),
});

export const usersRelations = relations(Users, ({ one, many }) => ({
Expand Down

0 comments on commit f15868c

Please sign in to comment.