#GraphQLError Type TYPE must define one or more fields

3 messages · Page 1 of 1 (latest)

undone crane
#

I have documented my issue on this Stack Overflow question: https://stackoverflow.com/questions/74790587/graphqlerror-type-type-must-define-one-or-more-fields

In short

I am using the Code First approach and defining my model, annotating it with @Directive('@key(fields: "id")')

But it then says I am not defining any fields, however, I look the schema and it it's there?

#

Schema:

# ------------------------------------------------------
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------

directive @key(fields: String!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE

directive @extends on OBJECT | INTERFACE

directive @external on OBJECT | FIELD_DEFINITION

directive @requires(fields: String!) on FIELD_DEFINITION

directive @provides(fields: String!) on FIELD_DEFINITION

directive @shareable on FIELD_DEFINITION | OBJECT

directive @link(url: String!, import: [link__Import]) on SCHEMA

directive @tag(name: String!) repeatable on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

directive @override(from: String!) on FIELD_DEFINITION

type Address {
  addressLineOne: String!
  addressLineTwo: String!
  addressLineThree: String!
  postcode: String!
}

type Property {
  id: ID!
  owner: String!
  propertyUPRN: String!
  address: Address!
}

type Query {
  findAllProperties: [Property!]!
}

scalar link__Import
#

Resolver:

import { Query, Resolver, ResolveReference } from "@nestjs/graphql";
import { Property } from "./models/property.model";
import { PropertiesService } from "./properties.service";

@Resolver((of) => Property)
export class PropertiesResolver {
  constructor(private readonly propertiesService: PropertiesService) {}

  @Query((returns) => [Property])
  public async findAllProperties(): Promise<Property[]> {
    return this.propertiesService.findAll();
  }

  @ResolveReference()
  public async resolveReference(ref: { __typename: string; id: string }): Promise<Property> {
    return await this.propertiesService.findOneById(ref.id);
  }
}