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

Field defined in resolvers, but not in schema when using class as return value #3031

Closed
2 of 4 tasks
zuffik opened this issue Oct 21, 2023 · 1 comment
Closed
2 of 4 tasks

Comments

@zuffik
Copy link

zuffik commented Oct 21, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Given this code and assuming everything else is set up correctly (I can provide Graphql module config if necessary)

import {
  Field,
  Int,
  ObjectType,
  Query,
  ResolveField,
  Resolver,
} from '@nestjs/graphql';

const getDto = () => {
  @ObjectType({ isAbstract: true })
  abstract class Dto {
    @Field(() => Int)
    id: number = 1;
  }
  return Dto;
};

@ObjectType()
export class Child extends getDto() {}

const getDynamicResolver = () => {
  @Resolver(getDto(), { isAbstract: true })
  abstract class DynamicResolver {
    @Query(() => Child)
    dto() {
      return new Child();
    }
    @Query(() => Child)
    setDto() {
      return new Child();
    }

    //@ResolveField(() => String)
    //helloWorld() {
    //  return 'foo';
    // }
  }

  return DynamicResolver;
};

@Resolver(Child)
export class DynamicResolver extends getDynamicResolver() {}

I get this error: Error: Child.helloWorld defined in resolvers, but not in schema. Everything else works fine (queries and mutations are executed as expected) and everything is present in schema.

Workaround

One of the options is to set @Field to entity that is defined in @Resolver argument but in this way I'm not able to use @Args.

Minimum reproduction code

https://github.com/zuffik/nestjs-schema-problem-repo/tree/main/src

Steps to reproduce

  1. install dependencies (yarn)
  2. start project (yarn start:dev)

Expected behavior

I expect the application is able to recognize fields in any context.

Package version

12.0.9

Graphql version

graphql: 16.8.1
@nestjs/apollo: 12.0.9

NestJS version

10.2.7

Node.js version

20.8.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

@nestjs nestjs locked and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants