Help Needed: Error with Arguments in GraphQL Resolver Using Drizzle ORM, Serverless, and TypeScript

Hi Drizzle Community, I'm running into an issue with GraphQL and Drizzle ORM while working on a serverless project using TypeScript. I've set up my environment with the following key components: - Environment: Serverless Framework - Language: TypeScript - ORM: Drizzle ORM - GraphQL: Apollo Server with @apollo/server - Database: PostgreSQL (using drizzle-orm/postgres-js) Problem Description I'm encountering the following error when trying to run my serverless application:
✖ Unhandled exception in handler 'server'.
✖ Query.userProfile args must be an object with argument names as keys.
Error: Query.userProfile args must be an object with argument names as keys.
at devAssert (...\graphql\jsutils\devAssert.js:12:11)
at ...\graphql\type\definition.js:793:32
...
✖ Unhandled exception in handler 'server'.
✖ Query.userProfile args must be an object with argument names as keys.
Error: Query.userProfile args must be an object with argument names as keys.
at devAssert (...\graphql\jsutils\devAssert.js:12:11)
at ...\graphql\type\definition.js:793:32
...
Context Here’s a simplified version of my code setup: user.schema.ts:
import { GraphQLObjectType, GraphQLNonNull, GraphQLString } from "graphql";
import { drizzleEntities } from "@/db";
import { getUserProfile } from "./services/getUserProfile.service";

const userQuery = new GraphQLObjectType({
name: "UserQuery",
fields: {
userProfile: {
type: drizzleEntities.types.UsersItem,
args: {
authUserId: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: async (_, args) => {
console.log(args);
const { authUserId } = args;
return getUserProfile(authUserId);
},
},
},
});

export { userQuery };
import { GraphQLObjectType, GraphQLNonNull, GraphQLString } from "graphql";
import { drizzleEntities } from "@/db";
import { getUserProfile } from "./services/getUserProfile.service";

const userQuery = new GraphQLObjectType({
name: "UserQuery",
fields: {
userProfile: {
type: drizzleEntities.types.UsersItem,
args: {
authUserId: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: async (_, args) => {
console.log(args);
const { authUserId } = args;
return getUserProfile(authUserId);
},
},
},
});

export { userQuery };
2 Replies
Jackson Kasi
Jackson KasiOP5mo ago
schema.ts:
import { GraphQLSchema, GraphQLObjectType } from "graphql";
import { userQuery } from "./modules/user/user.schema";
import { drizzleEntities } from "./db";

const query = new GraphQLObjectType({
name: "Query",
fields: {
...drizzleEntities.queries,
...userQuery.getFields(),
},
});

const mutation = new GraphQLObjectType({
name: "Mutation",
fields: {
...drizzleEntities.mutations,
},
});

export const schema = new GraphQLSchema({
query,
mutation,
types: [
...Object.values(drizzleEntities.types),
...Object.values(drizzleEntities.inputs),
],
});
import { GraphQLSchema, GraphQLObjectType } from "graphql";
import { userQuery } from "./modules/user/user.schema";
import { drizzleEntities } from "./db";

const query = new GraphQLObjectType({
name: "Query",
fields: {
...drizzleEntities.queries,
...userQuery.getFields(),
},
});

const mutation = new GraphQLObjectType({
name: "Mutation",
fields: {
...drizzleEntities.mutations,
},
});

export const schema = new GraphQLSchema({
query,
mutation,
types: [
...Object.values(drizzleEntities.types),
...Object.values(drizzleEntities.inputs),
],
});
What I’ve Tried - Logging args: I added console.log(args) inside the resolver, but it doesn’t seem to be logging anything before the error occurs. - Hardcoding authUserId: Even when I hardcode authUserId, I still receive the same error about arguments. tsconfig.json Here is my tsconfig.json for context:
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"target": "ES6",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/db/*": ["./src/db/*"],
"@/lib/*": ["./src/lib/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "src/**/*.spec.ts", "src/**/*.spec.js"]
}
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"target": "ES6",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/db/*": ["./src/db/*"],
"@/lib/*": ["./src/lib/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "src/**/*.spec.ts", "src/**/*.spec.js"]
}
Request Has anyone encountered this issue before or knows what might be causing it? Any help would be greatly appreciated! Thank you! Guys if need i will share code repo, i need help plz 🙏 Hey guys, has anyone tried drizzle-graphql with custom queries? I need help or suggestions.
Jackson Kasi
Jackson KasiOP5mo ago
Please check this to reproduce the issue: https://github.com/jacksonkasi1/drizzle-graphql-lambda
GitHub
GitHub - jacksonkasi1/drizzle-graphql-lambda
Contribute to jacksonkasi1/drizzle-graphql-lambda development by creating an account on GitHub.
Want results from more Discord servers?
Add your server