drizzle-team / drizzle-graphql

Automatically generate GraphQL schema or customizable schema config fields from Drizzle ORM schema
https://www.npmjs.com/package/drizzle-graphql
Apache License 2.0
34 stars 1 forks source link

relation breaks #10

Closed azamaulanaaa closed 1 month ago

azamaulanaaa commented 1 month ago

package

    "drizzle-graphql": "^0.7.0",
    "drizzle-orm": "^0.30.10",

query

query ($entity_id: Int!, $date: String!) {
  entitiesSingle(where: { id: { eq: $entity_id } }) {
    financeSalaries(where: { activatedAt: { lte: $date } }) {
      value
      activatedAt
    }
  }
}

response

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field EntitiesSelectItem.financeSalaries.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "entitiesSingle",
        "financeSalaries"
      ]
    }
  ],
  "data": {
    "entitiesSingle": null
  }
}

Note:

in version 0.6, everything works just fine. Updating to 0.7 got the problem. thanks

Sukairo-02 commented 1 month ago

What's your drizzle schema? Can't replicate this using any of mine including the test ones.

azamaulanaaa commented 1 month ago

this is my schema hope it helps

export const entities = pgTable("entities", {
  id: serial("id").primaryKey().notNull(),
  createdAt: timestamp("created_at").defaultNow().notNull(),
  name: text("name").notNull(),
});

export const entitiesRelations = relations(entities, ({ many }) => ({
  financeSalaries: many(financeSalaries),
}));

export const financeSalaries = pgTable(
  "finance_salaries",
  {
    id: serial("id").primaryKey().notNull(),
    createdAt: timestamp("created_at").defaultNow().notNull(),
    activatedAt: timestamp("activated_at").defaultNow().notNull(),
    value: jsonb("value").notNull(),
    entityId: integer("entity_id")
      .notNull()
      .references(() => entities.id, {
        onDelete: "restrict",
        onUpdate: "cascade",
      }),
  },
  (table) => ({
    activatedAtIndex: index().on(table.activatedAt),
    entityIdIndex: index().on(table.entityId),
    entityIdValueUnique: unique().on(table.entityId, table.value),
  }),
);

export const financeSalariesRelations = relations(
  financeSalaries,
  ({ one }) => ({
    entity: one(entities, {
      fields: [financeSalaries.entityId],
      references: [entities.id],
    }),
  }),
);
Edsol commented 1 month ago

same problem but on mysql database, so it does not depend on dbms

Sukairo-02 commented 1 month ago

Fixed - v0.7.2