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

Mutation for `Date` type throw GraphQLError #8

Closed joeprabawa closed 1 month ago

joeprabawa commented 1 month ago

First of all, pardon if i'm doing wrong how to raise an issue. At the moment, i'm learning graphql and took interest using this library. Step to reproduce:

I'm using these dependencies such as below :

"drizzle-graphql": "^0.4.0",
"drizzle-orm": "^0.30.10",
"drizzle-kit": "^0.21.2",
"pg": "^8.11.5"

And I have db schema like below:

const travels = pgTable(
  "travels",
  {
    id: uuid("id").defaultRandom().primaryKey(),
    isPublic: boolean("is_public").notNull(),
    slug: varchar("slug", { length: 255 }).notNull(),
    name: varchar("travel_name", { length: 255 }).notNull(),
    description: text("description"),
    numberOfDays: integer("number_of_days").notNull(),
    createdAt: date("created_at").defaultNow(),
    updatedAt: date("updated_at").defaultNow(),
  },
  (t) => ({
    nameUnique: unique("name_unique").on(t.name),
  })
);

and i've checked the schema already reflect on the db:

laratour=# select * from travels;
 id | is_public | slug | travel_name | description | number_of_days | created_at | updated_at 
----+-----------+------+-------------+-------------+----------------+------------+------------
(0 rows)

laratour=# 

but when i try create a mutation for insertIntoTravelsSingle with payload like below:

{
  "values": {
    "name": "Travel To Bali",
    "description": "Explore Bali for 5 Days",
    "isPublic": true,
    "numberOfDays": 5,
    "slug": "explore-bali-5-days"
  }
}

it throws an error with message:

{
  "errors": [
    {
      "message": "column \"created_at\" of relation \"travels\" does not exist",
      "locations": [
        {
          "line": 13,
          "column": 3
        }
      ],
      "path": [
        "insertIntoTravelsSingle"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "GraphQLError: column \"created_at\" of relation \"travels\" does not exist",
          "    at resolver (/Users/indraprabawa/learn-gqldzl/node_modules/src/util/builders/pg.ts:234:12)",
          "    at processTicksAndRejections (node:internal/process/task_queues:95:5)"
        ]
      }
    }
  ],
  "data": {
    "insertIntoTravelsSingle": null
  }
}

Need help is it me doing something wrong or maybe there's an actual issue happening. Thankyou in advance! 🙏

Sukairo-02 commented 1 month ago

Interesting, seems to be some either database-side, or driver-side issue, can't reproduce it locally with 0.30.10 version of drizzle-orm and drizzle-graphql v0.5.0, and although versions of drizzle-graphql mismatch, in 0.5.0 I didn't do anything to fix such a bug had there been one to begin with. Try using pnpm add postgres as your database driver, as well as latest as of now version of drizzle-graphql, which is 0.5.0.

Sukairo-02 commented 1 month ago

Your payload seems odd to me as well, since with GraphQL syntax it should be like

{
  values: {
    name: "Travel To Bali",
    description: "Explore Bali for 5 Days",
    isPublic: true,
    numberOfDays: 5,
    slug: "explore-bali-5-days"
  }
}

instead of what you've posted, but since that didn't throw a syntax error, I assume that the one you've used in a query was correct. If not - please, try fixing your query and see whether that helps.

joeprabawa commented 1 month ago

Your payload seems odd to me as well, since with GraphQL syntax it should be like

{
  values: {
    name: "Travel To Bali",
    description: "Explore Bali for 5 Days",
    isPublic: true,
    numberOfDays: 5,
    slug: "explore-bali-5-days"
  }
}

instead of what you've posted, but since that didn't throw a syntax error, I assume that the one you've used in a query was correct. If not - please, try fixing your query and see whether that helps.

Screenshot 2024-05-17 at 19 05 08

Yes, at the moment i'm using apollo server, and it seems the editor not complaining. Answering from your previous answer above, i've already tried to update the drizzle-grapql to latest, and run thepnpm add postgres but the issue still occuring. Just now I've tried to remove the created_at & updated_at field, and run db migration again

Screenshot 2024-05-17 at 19 09 47

and the mutation works

Screenshot 2024-05-17 at 19 13 10

at the moment i'll close this issue, let me investigate my environment first. Anyway thankyou so much for the guides & helps 🙏