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

UnknownExportException for GraphQLClientInject in GraphqlSdkModule for @golevelup/nestjs-graphql-request TypeSafeGqlSdk #955

Open
Adrianjs42 opened this issue Jan 28, 2025 · 2 comments

Comments

@Adrianjs42
Copy link

Adrianjs42 commented Jan 28, 2025

I tried to update "@golevelup/nestjs-graphql-request": "^0.2.2" to the latest "0.2.4" version (besides an update to nest.js 11) but I'm getting now several errors:

Expected 1 arguments, but got 2.ts(2554)

The Implementation of the src/graphql-sdk/graphql-sdk.module.ts before the update:

import {
  GraphQLRequestModule,
  GraphQLClientInject,
} from '@golevelup/nestjs-graphql-request';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { GraphQLClient } from 'graphql-request/build/entrypoints/main';
import { getSdk } from 'src/common/gql/graphql';
import { KeycloakModule } from 'src/keycloak/keycloak.module';
import { KeycloakService } from 'src/keycloak/keycloak.service';

@Module({
  imports: [
    GraphQLRequestModule.forRootAsync(GraphQLRequestModule, {
      imports: [ConfigModule, KeycloakModule],
      inject: [ConfigService, KeycloakService],
      useFactory: async (
        configService: ConfigService,
        keycloakService: KeycloakService,
      ) => {
        return {
          endpoint:
            configService.get<string>('API_BASE_URL') ||
            'https://test.test.de/graphql',
          options: {
            requestMiddleware: async (request) => {
              const token = await keycloakService.getToken();
              request.headers['authorization'] = `Bearer ${token}`;
              request.headers['apollographql-client-name'] = 'XXXX';
              request.headers['apollographql-client-version'] = '4.0.1';
              return request;
            },
          },
        };
      },
    }),
  ],
  providers: [
    {
      provide: 'TypeSafeGqlSdk',
      inject: [GraphQLClientInject],
      useFactory: (client: GraphQLClient) => getSdk(client),
    },
  ],
  exports: ['TypeSafeGqlSdk'],
})
export class GraphqlSdkModule {}

When I remove the GraphQLRequestModule argument

...
@Module({
  imports: [
    GraphQLRequestModule.forRootAsync({
      imports: [ConfigModule, KeycloakModule],
...

Then I get the error:

ERROR [ExceptionHandler] UnknownDependenciesException [Error]: Nest can't resolve dependencies of the TypeSafeGqlSdk (?). Please make sure that the argument Symbol(GraphQLClientInject) at index [0] is available in the GraphqlSdkModule context.

Potential solutions:
- Is GraphqlSdkModule a valid NestJS module?
- If Symbol(GraphQLClientInject) is a provider, is it part of the current GraphqlSdkModule?
- If Symbol(GraphQLClientInject) is exported from a separate @Module, is that module imported within GraphqlSdkModule?
  @Module({
    imports: [ /* the Module containing Symbol(GraphQLClientInject) */ ]
  })

    at Injector.lookupComponentInParentModules (/Users/test/Developer/Business/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_refl_f2mlliwbhlpz75orla5kuwqswe/node_modules/@nestjs/core/injector/injector.js:262:19)
    at async Injector.resolveComponentInstance (/Users/test/Developer/Business/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_refl_f2mlliwbhlpz75orla5kuwqswe/node_modules/@nestjs/core/injector/injector.js:215:33)
    at async resolveParam (/Users/test/Developer/Business/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_refl_f2mlliwbhlpz75orla5kuwqswe/node_modules/@nestjs/core/injector/injector.js:129:38)
    at async Promise.all (index 0)
    at async Injector.resolveConstructorParams (/Users/test/Developer/Business/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_refl_f2mlliwbhlpz75orla5kuwqswe/node_modules/@nestjs/core/injector/injector.js:144:27)
    at async Injector.loadInstance (/Users/test/Developer/Business/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_refl_f2mlliwbhlpz75orla5kuwqswe/node_modules/@nestjs/core/injector/injector.js:70:13)
    at async Injector.loadProvider (/Users/test/Developer/Business/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_refl_f2mlliwbhlpz75orla5kuwqswe/node_modules/@nestjs/core/injector/injector.js:98:9)
    at async /Users/test/Developer/Business/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_refl_f2mlliwbhlpz75orla5kuwqswe/node_modules/@nestjs/core/injector/instance-loader.js:56:13
    at async Promise.all (index 3)
    at async InstanceLoader.createInstancesOfProviders (/Users/test/Developer/Business/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_refl_f2mlliwbhlpz75orla5kuwqswe/node_modules/@nestjs/core/injector/instance-loader.js:55:9) {
  type: 'TypeSafeGqlSdk',
  context: {
    index: 0,
    dependencies: [
      Symbol(GraphQLClientInject)
    ],
    name: Symbol(GraphQLClientInject)
  },
  metadata: {
    id: 'xxx'
  },
  moduleRef: {
    id: 'xxx'
  }
}
@cstrnt
Copy link

cstrnt commented Jan 29, 2025

We just had a similar issue. It seems like version 5.7.0 had some breaking changes (even though it's a minor in semver) that breaks compatibility with nest v10. Make sure to update your package.json to 5.6.1. (without ^) to fix the version. It should work again :)

@underfisk
Copy link
Contributor

@Adrianjs42 Documentation was updated that we no longer need the module as the first argument for forRoot or forRootAsync
https://golevelup.github.io/nestjs/graphql-request.html

I'm not the one that manages the versioning but I highlighted that it should have been a major due to this API breaking change, please let me know if this works out for you

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

3 participants