Facing an issue with nestjs graphql schema first app.
Error: "Query.realEstateById" was defined in resolvers, but not in schema. If you use the @Query() decorator with the code first approach enabled, remember to explicitly provide a return type function, e.g. @Query(returns => Author).
my schema looks like:
# graphql
# Root types
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key"]
)
type Query {
"Retrieve a Real Estate by ID"
realEstateById(id: ID!): RealEstate
"Retrieve Real Estate by User Id"
realEstatesByUserId(userId: ID!): RealEstatesPayload # Use Connector
}
## Complex and Value Types
type RealEstate implements Id @key(fields: "id"){
id: ID!
userId: ID
realEstateName: String!
realEstateType: RealEstateTypeEnum
purchasedOn: Timestamp!
purchasePrice: Float!
hasDebt: Boolean
debtAmount: Float
paymentRealEstateId: ID
user: User
}
## Interfaces
interface Id {
"enforces the usage of a global identifier which helps with other features"
id: ID!
}
## Enums
enum RealEstateTypeEnum {
RESIDENTIAL
COMMERCIAL
}
## Entities
type User implements Id @key(fields: "id"){
id: ID!
}
resolver ---->
@Query()
async realEstateById(
@Args('id', { type: () => ID }) id: string,
): Promise<RealEstate> {
try {
const realEstate = await this.realEstateService.getRealEstateByID(id);
if (!realEstate) {
throw new Error('Real estate not found.');
}
return realEstate;
} catch (error) {
throw new Error(`Failed to get real estate by ID: ${error.message}`);
}
}
Not able to get by facing this issue, things i have tried:
- copyfiles - > in package.json "build": "nest build && copyfiles src/**/*.graphql dist/"