Mongoose not able to create a schema

Mongoose not able to create a schema


0

Everything loaded fine before I had added a new schema.

This is the resolver:

import { Arg, Mutation, Query, Resolver } from "type-graphql";

import { Order } from "./order.schema";
import OrderService from "./order.service";

@Resolver()
export default class OrderResolver {
    constructor(private orderService: OrderService) {
        this.orderService = new OrderService();
    }

    @Mutation(() => Order)
    createOrder(@Arg("input") input: any) {
        return this.orderService.createOrder(input);
    }

    @Query(() => [Order])
    getRestaurantOrders(@Arg("input") input: any) {
        return this.orderService.getRestaurantOrders(input);
    }
}

This is the schema:

import {
    getModelForClass,
    prop,
    ReturnModelType,
    queryMethod,
} from "@typegoose/typegoose";
import { AsQueryMethod } from "@typegoose/typegoose/lib/types";
import { Field, InputType, ObjectType } from "type-graphql";
import GraphQLJSON from 'graphql-type-json';

import { Restaurant } from "main/restaurant/restaurant.schema";

function findByRestaurant(
    this: ReturnModelType<typeof Order, QueryHelpers>,
    restaurantName: string,
) {
    return this.find({ "restaurant.name": restaurantName });
}

interface QueryHelpers {
    findByRestaurant: AsQueryMethod<typeof findByRestaurant>;
}

// @queryMethod(findByRestaurant)
@ObjectType()
export class Order {
    @Field()
    @prop({ required: false })
    restaurant: Restaurant;

    @Field(() => String)
    @prop({ required: true })
    table: string;

    @Field(() => GraphQLJSON, { nullable: true })
    @prop({ type: Object, required: false })
    items: Record<string, number>;
}


@InputType()
export class CreateOrderInput {
    @Field(() => String)
    restaurantName: string;

    @Field(() => String)
    table: string;

    @Field({ nullable: true })
    items?: Record<string, number>;
}

export const OrderModel = getModelForClass(Order);

I’m using typegoose, type-graphql and made it run with Next.js with an sdk.

Everything works fine and the database gets connected if I remove the OrderResolver from the resolvers array.

Share


Load 6 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *