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

Invalid module name in augmentation, module '@shopify/admin-api-client' cannot be found.ts(2664) #1628 #1629

Open
davide2894 opened this issue Oct 12, 2024 · 1 comment

Comments

@davide2894
Copy link

Issue summary

Before opening this issue, I have:

  • [ x] Upgraded to the latest version of the relevant packages
    • @shopify/* package and version:
    • Node version:
    • Operating system:
  • [x ] Set { logger: { level: LogSeverity.Debug } } in my configuration, when applicable
  • [x ] Found a reliable way to reproduce the problem that indicates it's a problem with the package
  • [ x] Looked for similar issues in this repository
  • [ x] Checked that this isn't an issue with a Shopify API

Hello everyone,

I am using the GraphQL Codegen to automatically generate TypeScript types for my Shopify queries.
I am using the declarations: false option.

This is my codegen.ts file where I use your package:

// <root>/codegen.ts

import type {CodegenConfig} from '@graphql-codegen/cli';
import {preset, pluckConfig, schema} from '@shopify/hydrogen-codegen';
import {ApiType, shopifyApiTypes} from '@shopify/api-codegen-preset';

export default <CodegenConfig>{
  overwrite: true,
  pluckConfig,
  generates: {
    ['storefrontapi.d.ts']: {
      schema,
      preset,
      documents: [
        'app/root.tsx',
        'app/**/*.{ts,tsx}',
        'server.ts',
        '!app/graphql/admin',
      ],
    },
    ...shopifyApiTypes({
      apiType: ApiType.Admin,
      apiVersion: '2023-10',
      documents: [
        'app/graphql/admin/operations/**/*.ts',
        '!app/graphql/admin/generated',
      ],
      outputDir: 'app/graphql/admin/generated',
      declarations: false,
    }),
  },
};

Expected behavior

The Shopify Hydrogen build should work as expected, even when I run @shopify/api-codegen-preset with the declarations: false` option.

Actual behavior

Inside the admin.generated.ts this part

declare module '@shopify/admin-api-client' {
  type InputMaybe<T> = AdminTypes.InputMaybe<T>;
  interface AdminQueries extends GeneratedQueryTypes {}
  interface AdminMutations extends GeneratedMutationTypes {}
}

which is linted with the following error:
Invalid module name in augmentation, module '@shopify/admin-api-client' cannot be found.ts(2664)

which is breaking Shopify Hydrogen builds so it's difficult to start my project locally or building it in general

Steps to reproduce the problem

Attempt to use a scalar property (eg. Product['createdAt']).

  1. Set up a typescript project using the Admin GraphQL API and codegen as per these instructions.

  2. Startup a basic Shopify Hydrogen project by following the official guidelines

  3. Setup the Admin GraphQL API and codegen as per the codegen.ts file shared above

  4. Run the command npx shopify hydrogen codegen to generate the admin.generated.ts file

  5. Check the file and see if there is the error linted there

  6. Run the command npm run dev

Debug logs

Invalid module name in augmentation, module '@shopify/admin-api-client' cannot be found.

app/graphql/admin/generated/admin.generated.ts:19:16

@lizkenyon
Copy link
Contributor

Hi there 👋

A couple of things!

The team was wondering if we could learn a bit more about your use case for using the Admin API in a Hydrogen project, as while there are some valid use cases for this this is not something commonly done. And the Hydrogen team is always interested in better understanding these use cases.

Are you using the @shopify/admin-api-client package for your interactions with the Admin API? If not what are you using?

Debugging might be easier if you are able to provide a simplified repository that can reproduce this error.

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

No branches or pull requests

2 participants