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

Can not pass Date values as query inputs #4193

Open
cesarve77 opened this issue Aug 8, 2023 · 2 comments
Open

Can not pass Date values as query inputs #4193

cesarve77 opened this issue Aug 8, 2023 · 2 comments
Labels
kind/bug Something isn't working status/triage

Comments

@cesarve77
Copy link

cesarve77 commented Aug 8, 2023

What is the problem?

I am trying to execute a simple query like:
client:

  const [users] = useQuery(getUsers, { createdAt: new Date() })

but the query run infinitily
I tried

  const input= useRef({ createdAt: new Date() }).current
  const [users,{refetch}] = useQuery(getUsers, input)

Same result!
I tried:

const input={ createdAt: new Date() }
const Users = () => {
  const [users,{refetch}] = useQuery(getUsers, input)
  return (
    <>
      {users?.map((user, i) => (
        <div key={i}>
          {user.name}
        </div>
      ))}
    </>
  )
}

and that works

It should works at least in the second scenario without problems

Paste all your error logs here:

image

Paste all relevant code snippets here:

client

import { Suspense, useRef, useState } from "react"
import Layout from "src/core/layouts/Layout"
import { useQuery } from "@blitzjs/rpc"
import { BlitzPage } from "@blitzjs/next"
import getUsers from "../users/queries/getUsers"

const input={ createdAt: new Date() }
const Users = () => {
  const input= useRef({ createdAt: new Date() }).current
  const [users,{refetch}] = useQuery(getUsers, input)
  return (
    <>
      <button onClick={() => refetch()}>Refetch</button>
      {users?.map((user, i) => (
        <div key={i}>
          {user.name}
        </div>
      ))}
    </>
  )
}

const Home: BlitzPage = () => {
  return (
    <Layout title="Home">
      <Suspense fallback="Loading...">
        <Users />
      </Suspense>
    </Layout>
  )
}

export default Home

server:

import { resolver } from "@blitzjs/rpc"
import db from "db"
import { z } from "zod"

const GetUsers = z.object({
  createdAt: z.date()
})

  export default resolver.pipe(
    resolver.zod(GetUsers),
    async ({ createdAt }) => {
      return await db.user.findMany({ where: { createdAt: { gte: createdAt } } })
    }
  )



### What are detailed steps to reproduce this?

git clone https://github.com/cesarve77/date-error-blitz.git
cd date-error-blitz
npm i
blitz dev


### Run `blitz -v` and paste the output here:

Blitz version: 2.0.0-beta.31 (global)
Blitz version: 2.0.0-beta.31 (local)
macOS Ventura | darwin-arm64 | Node: v18.15.0

Package manager: pnpm

System:
OS: macOS 13.4.1
CPU: (8) arm64 Apple M1
Memory: 122.16 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.15.0/bin/yarn
npm: 9.5.0 - ~/.nvm/versions/node/v18.15.0/bin/npm
npmPackages:
@blitzjs/auth: 2.0.0-beta.31 => 2.0.0-beta.31
@blitzjs/next: 2.0.0-beta.31 => 2.0.0-beta.31
@blitzjs/rpc: 2.0.0-beta.31 => 2.0.0-beta.31
@prisma/client: 4.6.1 => 4.6.1
blitz: 2.0.0-beta.31 => 2.0.0-beta.31
next: 13.4.5 => 13.4.5
prisma: 4.6.1 => 4.6.1
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
typescript: ^4.8.4 => 4.8.4 ```

Please include below any other applicable logs and screenshots that show your problem:

No response

@cesarve77 cesarve77 added kind/bug Something isn't working status/triage labels Aug 8, 2023
@siddhsuresh
Copy link
Member

@cesarve77 I would like a little bit more clarity on this issue, does this happen only you used dates or did you face an infinite loop regardless?

@cesarve77
Copy link
Author

cesarve77 commented Aug 14, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working status/triage
Projects
None yet
Development

No branches or pull requests

2 participants