Issue with FieldResolver() in TypeORM version 0.3.12 not delivering correct results when used with a where statement

Upon updating TypeORM from version 0.2.37 to 0.3.12, I encountered an issue where the where statement stopped returning any answers' entity, even though there are relevant records in the database (the question is unable to find any answer). Reverting back to version 0.2.37 fixed the problem.

I am curious about what might be causing this behavior specifically in TypeORM version 0.3.12. Is there a way to address this issue while continuing to use the latest version of TypeORM?

Below is the code snippet for reference:

📁resolvers/📁types/📄question.ts

import {
  Ctx,
  FieldResolver,
  Resolver,
  ResolverInterface,
  Root,
} from "type-graphql";
import { Context } from "./../../index"
import { Answer } from "../../entities/answer";
import { Question } from "../../entities/question";
import { Posted_Answer } from "../../entities/posted_answer";

@Resolver((of) => Question)
export class Question_Resolver implements ResolverInterface<Question> {
  @FieldResolver()
  async answers(@Root() root: Question, @Ctx() context: Context) {
    const answers = await context.connection.manager.find(Answer, {
      // Removing the where statement allows question to resolve answers with TypeORM 0.3.12, but filtering is necessary.
      where: { question: root },
    });
    return answers;
  }
}

Answer №1

The reason why it was not working still eludes me, but by taking a different approach, I was able to get it functioning once again:

  @FieldResolver()
  async answers(@Root() root: Question, @Ctx() context: Context) {
    // const answers = await context.connection.manager.find(Answer, {
    //   where: { question: root },
    // });

    const query = createQueryBuilder(Answer, "answer")
      .leftJoinAndSelect("answer.question", "question")
      .where("question.uuid = :questionId", { questionId: root.uuid });

    const answers = await query.getMany();

    return answers;
  }

|------ UPDATE ------|

Solving the issue by only matching one property instead of the entire object!

const answers = await context.connection.manager.find(Answer, {
  where: { question: { uuid: root.uuid } },
});

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 entered type '{}' cannot be assigned to type 'Record<Key, Value>'

Here is my code snippet: const foo = <Key extends keyof any, Value>() { type Rec = Record<Key, Value> const a: Rec = {} } When I try to compile this code, TypeScript throws an error on the 3rd line stating that Type '{}' is not a ...

What is the best way to test an external Data Transfer Object (DTO

I am looking to test an external Data Transfer Object (DTO) that undergoes frequent changes. For example: Here is a sample JavaScript (JSON) file below: // JavaScript const type User = { id: Number, name: String } // JSON user: { id: Number, ...

Error: The specified property 'Body' is not found within the type '{}'

Looking for some assistance here. I've created an http.get method like this: return this.http .get(url) .map((response: Response) => { response = response.json(); // console.log('The http get response', respon ...

What is the correct way to invoke a function that accepts a combination of specific string values when all I have is a regular string?

Within the TypeScript function declaration provided below, the parameter type alignment consists of unioned literals. function printText(s: string, alignment: "left" | "right" | "center") { // ... } As per the documentation ...

AdalAngular6ServiceError - Managing Unauthorized Login Attempts

In my Angular 7 application, I am utilizing the ms-adal-angular6 library to handle authentication flow and I am trying to understand the sequence of events in my code. After successfully authenticating with Azure Active Directory (AAD) using a logged-in u ...

What could be causing my Angular project to not run properly without any changes made after creating a new component that I want to include in app.component.html?

Greetings, I am just starting out with Angular 17 and I am currently going through the Tour of Heroes course on the official website. Following the tutorial's instructions, I created a new component called 'heroes' after setting up my projec ...

What is the purpose of utilizing import and require() in Node.js programming?

Currently, I am analyzing the source code found at "Type definitions for Express 4.16" and stumbled upon this interesting line (#18): import serveStatic = require("serve-static"); I couldn't help but wonder why the above code is necessary or being u ...

Master the art of iterating through an Object in TypeScript

I need help with looping through an Object in TypeScript. While the following examples work in JavaScript, I understand why they pose a problem in TypeScript. Unfortunately, I am struggling to find the correct approach to solve this issue. Am I approaching ...

Encountered an issue while trying to assign a value to the 'value' property on an 'HTMLInputElement' within a reactive form

When I upload a picture as a data record, the image is sent to a server folder and its name is stored in the database. For this editing form, I retrieve the file name from the server and need to populate <input type="file"> in Angular 6 using reacti ...

Creating a carousel with material design aesthetics

I'm working on implementing a carousel in my setup using Angular CLI: 6.0.5, Node: 10.1.0, OS: win32 x64, and Angular: 6.0.3. However, I haven't been able to locate documentation for creating the carousel in Angular's Material Design framewo ...

Show the subjects' names and their scores once they have been added to a fresh array

Here is my unique code snippet: let fruits: string[] = ['Apple', 'Banana', 'Orange', 'Grapes', 'Mango']; function capitalize(fruit: string) { return fruit.toUpperCase(); } let uppercaseFruits = fruits ...

Creating a React FunctionalComponent in Typescript without explicitly assigning it as a function

In my recent exploration of code, I stumbled upon a segment where FormWithRedirect is defined as a FC(FunctionComponent): declare const FormWithRedirect: FC<FormWithRedirectProps>; export declare type FormWithRedirectProps = FormWithRedirectOwnProps ...

Tips for transferring request variables/data from a middleware to another function in typescript

I need to authenticate a user's jwt token using middleware. This is the middleware I have: const authorized = (req: Request, res: Response, next: NextFunction) => { const token = req.header("token") if(!token){ return res.send("N ...

Tips for enhancing code quality and minimizing redundancies

Below is the code snippet for different classes describing models and emitters: export class Findbyobjectidlatest { onChanged = new EventEmitter<Ifindbyobjectidlatest>(); model = <Ifindbyobjectidlatest>{ pagesize: 10 }; emit() { this ...

Looking to retrieve CloudWatch logs from multiple AWS accounts using Lambda and the AWS SDK

Seeking guidance on querying CloudWatch logs across accounts using lambda and AWS SDK Developing a lambda function in typescript Deploying lambda with CloudFormation, granting necessary roles for reading from two different AWS accounts Initial exe ...

Having trouble retrieving hidden values from a new Angular/JavaScript window

I have created a form inside a component HTML <button type="button" (click)="myForm(i)"> TypeScript myForm(i) { let form = document.createElement('form'); form.setAttribute('action', this.urlAddr); form.setAttribute ...

Error encountered while unit testing a class decorator with type mismatch

I have been tasked with implementing a class decorator that adds an "identify" class method, which returns a class name with the information passed in the decorator. For example : @identifier('example') class Test {} const test = n ...

Navigate to a new page on button click using Row with Tanstack / React-Table and Typescript (2339)

Encountering a linting error when attempting to navigate to a new route by clicking on a table row. The functionality is working but how can I resolve this issue? It's showing an error message stating "The property "id" for type TData does not exist." ...

How to use Typescript to find the length of an array consisting of either strings or

I am trying to determine the length of a string or array, stored in a variable with the data type var stepData : string | string[]. Sometimes I receive a single string value, and other times I may receive an array of strings. I need the length of the array ...

Unable to add elements to an array with a UnionType

I have been experimenting with UnionTypes in TypeScript and I had an idea for a scenario where they could be useful. However, I am puzzled by the error message that keeps popping up: Argument of type '{ name: string; }' is not assignable to par ...