Issue with @Arg Type Error arising while utilizing a GraphQL class imported from a local Package in TypeGraphQL

I have developed a local package containing various objects. The main purpose of this package is to be installed via npm in other programs so that they can utilize a common library of objects. One of the objects I created is a simple class for setting up an AppoloServer, which is intended to work with TypeGraphQL entities, types, and resolvers:

export class ClsApolloGraphQlServer {
    private _resolvers: any[];
    private _connection: Connection;

    constructor(
        resolvers: any[],
        connection: Connection,
    ) {
        this._resolvers = resolvers;
        this._connection = connection;
    }

    public async initApolloServer(
        app: express.Application,
        corsOpt: cors.CorsOptions
    ): Promise<ApolloServer> {
            const {
                typeDefs,
                resolvers,
            } = await buildTypeDefsAndResolvers({
                resolvers: this._resolvers,
            });

            const schema = makeExecutableSchema({
                typeDefs,
                resolvers,
            });

            addSchemaLevelResolveFunction(
                schema,
                (_, __, context) =>
                    !!getSession(context, this._SESSION_TYPE)
            );

            const apolloServer: ApolloServer = new ApolloServer({
                schema,
                context: ({
                    req,
                    res,
                }: {
                    req: Request;
                    res: Response;
                }): IGlobalContext => {
                    return {
                        req,
                        res,
                        dbConnection: this._connection,
                    };
                },
                formatError: (err: GraphQLError) =>
                    FormatErrorMessageGraphQlServer(err),
            });

            apolloServer.applyMiddleware({ app, cors: corsOpt });

            return apolloServer;

    }
}

Copying this code into one of the final programs and importing the class from there works perfectly fine.

However, when importing the class in the final program after installing the common library, TypeGraphQL encounters an error "

Cannot determine GraphQL input type for start
".

Below is an example of the failing resolver and the type definition for Arg, as 'start' is an argument used in resolvers for pagination purposes.

I'm not sure what the issue might be. Just want to mention that I am importing 'reflect-metadata' in the class Definition file within the library, as well as at the beginning of the final program.

Resolver

@Query(() => [objectTypeCls], { name: `getAll${suffix}` })
        async getAll(
            @Ctx() context: IGlobalContext,
            @Args() { start, nbRecords }: PaginationArgs
        ): Promise<TExposeApi[]> {

            if (context.dbConnection && context.dbConnection.isConnected) {
                const resu: TExposeApi[] = await context.dbConnection
                    .getRepository<TExposeApi>(objectTypeCls)
                    .createQueryBuilder(suffix)
                    .skip(start)
                    .take(nbRecords)
                    .getMany();
                return resu;
            } else return [];
        }

ArgType

@ArgsType()
export class PaginationArgs {
    @Field(() => Int)
    start: number;

    @Field(() => Int)
    nbRecords: number;
}

Answer №1

To avoid conflicts between packages, it is necessary to either utilize a package repository for bundled artifacts or implement a lerna monorepo with dependencies hoisting. In this particular scenario, the issue arises from linking separate packages that each contain their own graphql package within their node_modules directory. This results in a conflict where Int !== Int when comparing different instances of the graphql package.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The inability to access a route with an authentication guard in the app controller is causing the validate function in the local strategy file to not run

While trying to access my login route in the app.controller.ts of my rest api built with Nestjs and Prisma, I encountered a 401 error response. I have been closely following the official documentation provided by Nestjs on authentication (https://docs.nest ...

Null reference exception in Typescript + NextJS

I am facing an issue where the ref to a custom child component in my parent component is always null, preventing me from calling methods on it. Even though I believe I have implemented everything correctly, the ref (named CanvasUI) remains null and I can& ...

When using NextJS <Link, mobile users may need to tap twice to navigate

Whenever I use the NextJS <Link tag on my mobile device, I notice that I have to double-tap for the link to actually route to the desired page. Take a look at the code snippet below: <Link href="/methodology" passHref={true} ...

Monitor modifications to documents and their respective sub-collections in Firebase Cloud Functions

Is it possible to run a function when there is a change in either a document within the parent collection or a document within one of its subcollections? I have tried using the code provided in the Firebase documentation, but it only triggers when a docume ...

How to create a boolean observable that emits hot values with switchMap?

Looking to develop a method named isEmpty:Observable<boolean> that generates a hot Observable<boolean> by employing a switchMap. Here's what I have so far: /** * Notifies observers when the store is empty. */ protected notifyOnE ...

Assign a specific value to the sub-component within the grid using Angular 2+

Incorporating Angular 8 and TypeScript into my project, I have a grid that consists of various internal components, one being <ng-select/>. The data binding takes place in the child component during onInit. Upon loading and initialization of the dat ...

Steps to add annotations to a class descriptor:

Can you help me with the correct way to annotate this piece of code? export class TestCls { static SomeStaticFn(): TestCls { // Do some stuff... // Return the class descriptor for a "fluid usage" of SomeStaticFn return TestCls ...

Javascript's callback mechanism allows functions to be passed as arguments

I am currently delving into the intricacies of the callback mechanism in javascript, particularly typescript. If I have a function that expects a callback as an input argument, do I need to explicitly use a return statement to connect it with the actual ca ...

Why am I unable to access all elements within the map function?

Hey there, I have a function related query. Whenever I try to access my data, I can only reach the first index of each array. For instance, I have 5 different images of PlayStation, but on my webpage, I am only able to see one image. How can I resolve this ...

You cannot assign the type 'void' to the type 'ObservableInput<Action>'

I'm encountering a type error when I attempt to dispatch an observable of actions within my effect. The error message I'm receiving is as follows: @Effect() rideSummary$: Observable<Action> = this.actions$.pipe( ofType<GetRi ...

What are the reasons for the Apollo client network request being canceled twice?

My Apollo client's useQuery function seems to be loading twice, which is a common occurrence according to the normal flow. However, when I had my network tab open in dev tools, I noticed some unusual behavior. I found that there are 2 cancelled reque ...

Ways to access configuration settings from a config.ts file during program execution

The contents of my config.ts file are shown below: import someConfig from './someConfigModel'; const config = { token: process.env.API_TOKEN, projectId: 'sample', buildId: process.env.BUILD_ID, }; export default config as someCo ...

Tips on navigating an array to conceal specific items

In my HTML form, there is a functionality where users can click on a plus sign to reveal a list of items, and clicking on a minus sign will hide those items. The code structure is as follows: <div repeat.for="categoryGrouping of categoryDepartm ...

There was a problem with the module '@angular/material' as it was unable to export a certain member

In creating a custom Angular Material module, I have created a material.module.ts file and imported various Angular Material UI components as shown below: import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/commo ...

Incorrect types being identified

What is the reason behind the callback assuming the type string | number | boolean instead of determining the exact type based on the property passed as the first argument in the carWithListener.on function? const car = { paint: "red", ...

Angular and Bootstrap work hand in hand to provide a seamless user experience, especially

I have been exploring ways to easily close the modal that appears after clicking on an image. My setup involves using bootstrap in conjunction with Angular. <img id="1" data-toggle="modal" data-target="#myModal" src='assets/barrel.jpg' alt=&a ...

Issue with assigning Type (Date|number)[][] to Array<,Array<,string|number>> in Angular with typescript and google charts

Currently, I am utilizing Angular 8 along with the Google Charts module. My latest endeavor involved creating a Google Calendar Chart to complement some existing Google charts within my project. However, upon passing the data in my component.html file, I ...

Unusual class title following npm packaging

Currently, I am working on developing a Vue 3 library with TypeScript. We are using Rollup for bundling the library. Everything works as expected within the library itself. However, after packing and installing it in another application, we noticed that th ...

The error message "Declaration file for module 'mime' not found" was issued when trying to pnpm firebase app

Currently, I am in the process of transitioning from yarn to pnpm within my turborepo monorepo setup. However, I have run into an issue while executing lint or build commands: ../../node_modules/.pnpm/@<a href="/cdn-cgi/l/email-protection" class="__cf_e ...

Can Envs in Bit be linked together?

My React environment is set up at this link: . It is configured with the following dependencies: { /** * standardize your component dependencies. * @see https://bit.dev/docs/react-env/dependencies **/ "policy": { // peer and dev ...