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

Usage in the browser #250

Closed
dandv opened this issue May 8, 2020 · 2 comments
Closed

Usage in the browser #250

dandv opened this issue May 8, 2020 · 2 comments
Labels
question Qustions about how to use stuff

Comments

@dandv
Copy link
Contributor

dandv commented May 8, 2020

I'm trying to use the isDocument type guard in React code that fetches a Post object via GraphQL. I need only the Post class, and no model capabilities, since I'm not using mongoose on the frontend only on the backend, powering the GraphQL server). Is there a proper way to do this?

I installed @typegoose/typegoose and mongoose in my Gatsby/React project and tried,

import { isDocument } from `@typegoose/typegoose`;
...
if (!isDocument(post.author)) throw ...

but I get this error:

image

Versions

  • typegoose: 7.0.0
  • mongoose: 5.9.12
@dandv dandv added the question Qustions about how to use stuff label May 8, 2020
@hasezoey
Copy link
Member

hasezoey commented May 8, 2020

even if typegoose was made compatible with the browser, you couldnt use typeguards, because they depend on the data using mongoose model/documents, and in the checks it uses mongoose too - so they will never work in an browser

otherwise this might be an duplicate of #33
-> and as i said in there, im willing to look into prs for this if any get made

@hasezoey
Copy link
Member

Duplicate of #33

@hasezoey hasezoey marked this as a duplicate of #33 Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Qustions about how to use stuff
Projects
None yet
Development

No branches or pull requests

2 participants