Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Error When Extending GraphQL Types with drizzleEntities(entities) #20

Open
jacksonkasi1 opened this issue Aug 17, 2024 · 3 comments
Assignees

Comments

@jacksonkasi1
Copy link

jacksonkasi1 commented Aug 17, 2024

Description:

When attempting to extend a GraphQLObjectType using fields from drizzleEntities.types.UsersItem.getFields() in drizzle-graphql, the following error occurs:

Unhandled exception in handler 'server'.
✖ ExtendedUsersItem.id args must be an object with argument names as keys.
Error: ExtendedUsersItem.id args must be an object with argument names as keys.
    at devAssert (path-to-project/node_modules/.pnpm/[email protected]/node_modules/graphql/jsutils/devAssert.js:12:11)
    at path-to-project/node_modules/.pnpm/[email protected]/node_modules/graphql/type/definition.js:793:32
    at mapValue (path-to-project/node_modules/.pnpm/[email protected]/node_modules/graphql/jsutils/mapValue.js:16:19)
    at defineFieldMap (path-to-project/node_modules/.pnpm/[email protected]/node_modules/graphql/type/definition.js:772:33)
    at GraphQLObjectType._fields (path-to-project/node_modules/.pnpm/[email protected]/node_modules/graphql/type/definition.js:691:26)
    at GraphQLObjectType.getFields (path-to-project/node_modules/.pnpm/[email protected]/node_modules/graphql/type/definition.js:710:27)
    at collectReferencedTypes (path-to-project/node_modules/.pnpm/[email protected]/node_modules/graphql/type/schema.js:387:51)
    at new GraphQLSchema (path-to-project/node_modules/.pnpm/[email protected]/node_modules/graphql/type/schema.js:179:7)
    at <anonymous> (path-to-project/src/schema.ts:28:16)
✖ ExtendedUsersItem.id args must be an object with argument names as keys.

This issue appears when trying to spread the fields from drizzleEntities.types.UsersItem.getFields() into a new GraphQLObjectType to extend it.

Steps to Reproduce:

  1. Set up a basic GraphQL schema using drizzle-graphql.
  2. Attempt to extend an existing type using drizzleEntities.types.UsersItem.getFields() as follows:
import { env } from "@/env";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import { buildSchema } from "drizzle-graphql";

import * as schema from "./schema";

const client = postgres(env.DATABASE_URL);
export const db = drizzle(client, { schema, logger: true });

const { entities } = buildSchema(db);

export const drizzleEntities = entities;
import { GraphQLObjectType, GraphQLInt, GraphQLString } from "graphql";
import { drizzleEntities } from "@/db";

const ExtendedUsersItem = new GraphQLObjectType({
  name: "ExtendedUsersItem",
  fields: {
    ...drizzleEntities.types.UsersItem.getFields(), // Include all default fields

    // Add custom fields
    totalPoints: {
      type: GraphQLInt,
      resolve: (user) => user.totalPoints || 0,
    },
  },
});

export { ExtendedUsersItem };
  1. Start the GraphQL server and observe the error.

Expected Behavior:

The ExtendedUsersItem type should be successfully created by extending the fields from UsersItem and adding custom fields like totalPoints without causing any errors.

Actual Behavior:

The server throws an error indicating that the id field (or other fields) "must be an object with argument names as keys." This suggests that getFields() may not be handling or returning the fields in a way that is compatible with the expected GraphQLFieldConfigMap.

Environment:

  • drizzle-graphql version: ^0.8.4
  • drizzle-orm version: ^0.33.0
  • GraphQL version: ^16.9.0
  • Node.js version: v20.16.0
  • Operating System: Win 11

Additional Context:

  • The error seems related to how the fields are being spread into the ExtendedUsersItem type.
  • When manually specifying the fields, the issue does not occur, which suggests there may be an issue with how getFields() interacts with drizzle-graphql.

Temporary Workaround:

Manually adding the fields from UsersItem instead of using getFields() works without errors, but this is not ideal for maintaining the schema as it requires manual updates when fields change.

Request:

Please investigate whether there is a compatibility issue with getFields() when using drizzle-graphql, or if there are specific steps that should be taken to avoid this error.

@jacksonkasi1 jacksonkasi1 changed the title Issue: Error When Extending GraphQL Types with drizzleEntities Issue: Error When Extending GraphQL Types with drizzleEntities(entities) Aug 17, 2024
@jacksonkasi1
Copy link
Author

Please check this to reproduce the issue: https://github.com/jacksonkasi1/drizzle-graphql-lambda

@Sukairo-02 Sukairo-02 self-assigned this Aug 17, 2024
@Sukairo-02
Copy link
Collaborator

Seems like it's not the intended way to use .getFields() in the first place, but I'll investigate if there's something I can do about it from my side, sure.

@jacksonkasi1
Copy link
Author

Thanks for looking into it, @Sukairo-02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants