The error message (node:18560) UnhandledPromiseRejectionWarning is telling us that there is a TypeError because it cannot read the property 'typeFn' of

When attempting to resolve a field called blocks using the @ResolveField() decorator, I encounter an error.

page.resolver.ts

import {
  Resolver,
  Query,
  Mutation,
  Args,
  ResolveField,
  Parent,
} from '@nestjs/graphql';
import { PageService } from './page.service';
import { PageType } from './type/page.type';
import { CreatePageInput } from './input/create-page.input';
import { BlockService } from '../block/block.service';
import { Page } from './page.interface';

@Resolver('Page')
export class PageResolver {
  constructor(
    private readonly pageService: PageService,
    private readonly blockService: BlockService,
  ) {}

  @Query(() => [PageType])
  pages() {
    return this.pageService.getAllPages();
  }

  @Query(() => [PageType])
  async page(@Args('id') id: string) {
    return this.pageService.getPage(id);
  }

  @Mutation(() => PageType)
  createPage(@Args('createPageInput') createPageInput: CreatePageInput) {
    return this.pageService.createPage(createPageInput);
  }

  @ResolveField()
  blocks(@Parent() page: Page) {
    return this.blockService.getManyBlocks(page.blockIds);
  }
}

page.interface.ts

import { Document } from 'mongoose';

export interface Page extends Document {
  readonly id: string;
  readonly name: string;
  readonly createdAt: Date;
  readonly updatedAt: Date;
  readonly createdBy: string;
  readonly updatedBy: string;
  readonly blockIds: string[];
}

Answer №1

The issue was resolved by implementing the function () => PageType within the @Resolver() decorator.

@Resolver(() => PageType)

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

What could be causing the issue with these overload calls?

Hey there, I've encountered an issue while using createStore. Can someone please guide me on what I might be doing incorrectly? TypeScript error in /workspace/weatherAppTypescript/App/appfrontend/src/redux/store/index.ts(7,31): No overload matches th ...

Tips on converting Nextjs generated Prisma types case from snake_case to camelCase

I have a full-stack application built with Next.js and Prisma ORM "next": "12.3.0" "prisma": "^4.5.0" Essentially, I am looking to convert the case of my types from snake_case to camelCase to align with the front-en ...

Error: The schema for model "products" has not been properly registered

A Schema has not been registered for the "products" model, resulting in a MissingSchemaError. To resolve this issue, use mongoose.model(name, schema) function as shown below: Cart // Define cart schema const mongoose = require('mongoose'); const ...

Reactjs may have an undefined value for Object

I have already searched for the solution to this question on stackoverflow, but I am still confused. I tried using the same answer they provided but I am still getting an error. Can someone please help me resolve this issue? Thank you. const typeValue = [ ...

Is it time to launch your React TypeScript application on AWS S3?

I need help transitioning my deployment from AWS S3 using JavaScript to TypeScript. What specific code should I incorporate in TypeScript to facilitate this transition? 1) I have downloaded files with a .ts extension. https://i.sstatic.net/He49G.jpg 2) H ...

Mongoose makes sure that duplicate rows are not repeated in the database

I'm working with a basic mongoose schema definition below: const mongoose = require('mongoose'); const followSchema = new mongoose.Schema({ follower: { type: mongoose.Schema.Types.ObjectId, ref: 'User', ...

"Navigating through events with confidence: the power of event

Imagine I am developing an event manager for a chat application. Having had success with event maps in the past, I have decided to use them again. This is the structure of the event map: interface ChatEventMap { incomingMessage: string; newUser: { ...

Is there a way to incorporate my getter into a computed property?

My Vuex Store is built using Vuex module decorators and I am facing an issue with using a getter for a computed property. Here is my code: @Module export default class WorkoutModule extends VuexModule { _workout: Workout; @Mutation startWork ...

Error message: The property .match cannot be read as it is undefined (AWS Amplify Build Error)

I'm facing an issue when trying to deploy my React/Typescript app using Amazon's AWS Amplify. The build process keeps failing and the error message says: "Cannot read property .match of undefined". I've gone through numerous discussions, bu ...

Encountering the ObjectUnsubscribedErrorImpl while utilizing angular datatable with angular version 7

I am encountering an issue when trying to display a DataTable in a modal window. Initially, everything works as expected and I can see the screen perfectly. However, after closing the modal window and opening it again, the DataTable no longer shows the sea ...

What is the process for creating a Deep Copy of an object in Angular?

I have a specific entity class defined as follows: export class Contact { id: number; firstName: string; lastName: string; constructor(id?, firstName?, lastName?) { this.id = id; this.firstName = firstName; this.lastName = lastName; ...

JavaScript now has Type Inference assistance

When attempting to utilize the Compiler API for processing JavaScript code and implementing Type inference to predict types of 'object' in a 'object.property' PropertyAccessExpression node, I encountered some issues. Some simple example ...

Implementing nested $elemMatch Query in C# with MongoDB

I currently have a collection in MongoDB with the structure below. { "_id" : ObjectId("56c6f03ffd07dc1de805e84f"), "Details" : { "a" : [ [ { "DeviceID" : "log0", "DeviceName" : "Dev0" }, ...

Can you tell me the standard write concern utilized by the PyMongo driver by default?

I'm experimenting with implementing the "ack" write concern for certain writes. However, I can't seem to find any information in the Pymongo documentation about configuring this write concern. Is it possibly enforced by a specific setting on the ...

The absence of a base path in NestJs swagger configuration

Everything was running smoothly on my local machine. However, I encountered a problem after deploying the application. After deployment, /querybuilder gets added to the base URL. Therefore, http://localhost:80/helloworld turns into http://52.xxx.xxx.139/q ...

Using Omit<T,K> with enums does not yield the expected result in Typescript

The setup includes an enum and interface as shown below: enum MyEnum { ALL, OTHER } interface Props { sources: Omit<MyEnum, MyEnum.ALL> } const test: Props = { sources: MyEnum.ALL } // triggering a complaint intentionally I am perplexed b ...

Missing "this" after initialization? (typescript/node/express)

I am currently working on creating a basic http application using node-express. One issue I encountered is that when setting up routes, the constructor of the MyRouter class has access to this, but it seems to be lost within the getRoutes() function. cla ...

Executing a MongoDB query can only be successful by utilizing the copy and paste method

Recently, I encountered an unusual issue with MongoDB while attempting to query the database. Specifically, when running a query like db.departments.find({"key": "MEL 301"}), it returned no results. The MongoDB database is hosted on mLab, allowing me to v ...

Express Server Providers for Angular 17's Server-Side Rendering

I attempted to share my request and response object with the Angular application by defining Providers in the "server.ts" file. However, when injecting them into app.component, they always appear undefined regardless of whether I am in the server or clie ...

Bringing PNGs and SVGs into React - Error TS2307: Module not found

While attempting to import PNGs/SVGs (or any other image format) into my React project, TypeScript presents the following error: TS2307: Cannot find module '../assets/images/homeHeroImage.svg' or its corresponding type declarations. The frontend ...