Generating web types is broken after adding custom SDL and Service

I added this custom query to my sdl.ts file

accountByUserId(userId: String!): Account @requireAuth

With the following service

export const accountByUserId: QueryResolvers['accountByUserId'] = async ({
  userId,
}) => {
  const data = await db.account.findFirst({
    where: { userId },
  })

  return data
}

Then I have the following gql query

export const USER_ID_QUERY = gql`
  query FindAccountById($userId: String!) {
    accountByUserId(userId: $userId) {
      id
      createdAt
      updatedAt
      name
      userId
    }
  }
`

All this works, but when I run yarn rw g types the web side types break and don’t generate, with the following error:

Error: Could not generate GraphQL type definitions (web)
TypeError: plugin_helpers_1.DetailedError is not a constructor
    at /Users/anderskitson/manage_members/manage_members_app_old/node_modules/@graphql-codegen/core/cjs/codegen.js:209:19
    at Array.forEach (<anonymous>)
    at validateDuplicateDocuments (/Users/anderskitson/manage_members/manage_members_app_old/node_modules/@graphql-codegen/core/cjs/codegen.js:188:11)
    at /Users/anderskitson/manage_members/manage_members_app_old/node_modules/@graphql-codegen/core/cjs/codegen.js:16:40
    at /Users/anderskitson/manage_members/manage_members_app_old/node_modules/@graphql-codegen/plugin-helpers/cjs/profiler.js:7:49
    at async codegen (/Users/anderskitson/manage_members/manage_members_app_old/node_modules/@graphql-codegen/core/cjs/codegen.js:16:9)
    at async runCodegenGraphQL (/Users/anderskitson/manage_members/manage_members_app_old/node_modules/@redwoodjs/internal/dist/generate/graphqlCodeGen.js:123:18)

Any help would be great thanks.

2 Likes

Hi @anderskitson, this is probably because some of your (query/mutation) operation names are not unique.

If you comment out the added item in the sdl does everything work still?

EDIT: I figured out my issue.

There were duplicate query operations in some custom cells. Not sure why it didn’t give the explicit DetailedError like I saw in a different app, but glad I finally figured it out.


I’m getting the same error repeatedly, all of the SDL and services are all default after being generated.

I thought it may be due to a model that had several relations that was generated last and may be missing a relation in the types, because it kept displaying errors in VSCode and would throw an error that the type didn’t exist when trying to view a detail page for that entity (the GraphQL API retrieved the data with no issue). Here’s a translation/example of one of the errors in VSCode

i commented out that model and all relations, ran a migration, and then force generated all SDLs but the problem persists.

The API types generate and work as expected

Running RW Core v3.3.0 (also tried upgrading to 3.4.0)

You get a more descriptive error when you use duplicate query/mutation operations names:

Error: Could not generate GraphQL type definitions (web)
DetailedError: Not all operations have an unique name: FindJobs