drizzle-graphql icon indicating copy to clipboard operation
drizzle-graphql copied to clipboard

Duplicate Schema Name Error

Open anthtoonaing opened this issue 10 months ago • 2 comments

I have this schema.

export const FoodItemVariation = pgTable(
  "food_item_variations",
  {
    id: text().primaryKey().$defaultFn(() => createId()),
    name: varchar({ length: 256 }).notNull(),
    price: integer().default(0).notNull(),
    groupId: varchar({ length: 32 })
      .notNull()
      .references(() => FoodItemVariationGroup.id, { onDelete: "restrict", onUpdate: "cascade" }),
  }
);

export const FoodItemVariationGroup = pgTable(
  "food_item_variation_groups",
  {
    id: text().primaryKey().$defaultFn(() => createId()),
    name: varchar({ length: 256 }).notNull(),
    type: foodItemVariationGroupType().default(FoodItemVariationGroupType.SINGLE).notNull(),
    placeId: varchar({ length: 32 })
      .notNull()
      .references(() => Place.id, { onDelete: "restrict", onUpdate: "cascade" }),
  }
);

In this line const { schema: drizzleSchema } = buildDrizzleSchema(db); I got this error.

$ bun run --watch src/index.ts
214 |           false,
215 |           'One of the provided types for building the Schema is missing a name.',
216 |         );
217 | 
218 |       if (this._typeMap[typeName] !== undefined) {
219 |         throw new Error(
                    ^
error: Schema must contain uniquely named types but contains multiple types named "FoodItemVariationGroupIdFilters".
      at new GraphQLSchema (/Users/anthtoonaing/projs5/dishanddine/apps/core-api/node_modules/graphql/type/schema.js:219:15)
      at buildSchema (/Users/anthtoonaing/projs5/dishanddine/apps/core-api/node_modules/drizzle-graphql/index.js:1897:24)
      at /Users/anthtoonaing/projs5/dishanddine/apps/core-api/src/db/index.ts:22:35

The issue is FoodItemVariationGroupIdFilters is generated twice because I have FoodItemVariation.GroupId and FoodItemVariationGroup.Id.

It is better to have namingStrategy as in configuration or better fix in code to avoid such as case. Because of this issue, we have to rename our column names or use another lib to generate graphql schema. Thanks

anthtoonaing avatar Mar 20 '25 10:03 anthtoonaing

I'm facing the same issue :(

darvesh avatar Jun 25 '25 19:06 darvesh

Yeah, having this issue as well.

dmythro avatar Aug 22 '25 23:08 dmythro