Shopify / shopify-app-js

MIT License
281 stars 111 forks source link

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

Open davide2894 opened 1 week ago

davide2894 commented 1 week ago

Issue summary

Before opening this issue, I have:

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 commented 1 week ago

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.