Prisma 1 Forum

You provided an invalid argument for the where selector on Hotel

query {
    refreshToken {
        createdAt
    }
}  

Datamodel GraphQL:

type Hotel {
    id: ID! @id
    name: String!
    email: String! @unique
    phone: String! @unique
    createdAt: DateTime! @createdAt
    password: String!
    rooms: [Room!]! @relation(name: "RoomToHotel", onDelete: CASCADE)
    bookings: [Booking!]! @relation(name: "BookingToHotel", onDelete: CASCADE)
    guests: [Guest!]! @relation(name: "GuestToHotel", onDelete: CASCADE)
}

These are schemas.

type Query {
    refreshToken: Hotel!
}

type Hotel {
    id: ID!
    name: String!
    email: String!
    phone: String!
    createdAt: String!
    rooms: [Room!]!
    bookings: [Booking!]!
    guests: [Guest!]!
}

Resolver that gets hotel ID from JWT token and queries token by ID, but Prisma says that is wrong argument.

import getHotelId from '../../utils/getHotelId'
import generateToken from '../../utils/generateToken'
import setCookie from '../../utils/setCookie'

export default async function refreshToken(
    parent,
    args,
    { req, res, prisma },
    info,
) {
    const hotelId = getHotelId({ req })

    const hotel = await prisma.query.hotel(
        {
            where: { id: hotelId },
        },
        info,
    )

    const token = generateToken(hotelId)
    setCookie({ res }, token)

    return hotel
}

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.