Skip to content

Duplicate Schema Name Error #35

Description

@anthtoonaing

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions