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

DSG: @Transform decorators #1291

Closed
EndersDev opened this issue Mar 22, 2021 · 3 comments
Closed

DSG: @Transform decorators #1291

EndersDev opened this issue Mar 22, 2021 · 3 comments
Labels
type: bug Something isn't working

Comments

@EndersDev
Copy link

Describing the bug

  1. On the "WhereInput.ts" files the decorator @Transform(JSON.parse) does not work.

  2. On "schema.prisma", the decorator @reference need an property that it does not have, references, with its id.

Fixing

  1. Considering that it is a function that needs an non-string type and the inside of @Transform needs to be a function I was able
    to make it work replacing that statement with @Transform(field => JSON.parse(field.value))

  2. So I was able to substitute @relation(fields: [sellerId]) by @relation(fields: [sellerId], references: [id]).

Context

  1. When relation 2 or more entities.
    The properties of field variable are [value, obj, key, type], I'm new to back-end programming so I yet don't know which one to use, there for, I'll use "value" and then if I find any errors on the application I'll try the others (by the name I guess that the only other possible is obj).
  2. Binding a user (seller) in the client entity.
@EndersDev EndersDev added the type: bug Something isn't working label Mar 22, 2021
@yuval-hazaz
Copy link
Member

@EndersDev thanks for reporting
for the second one, I just pushed a fix on this one yesterday. It will be part of the next release. have a look at this #1287

I will look into the first one.

@yuval-hazaz yuval-hazaz changed the title [Server/Client/Data Service Generator]: [@Transform and @reference decorators] DSG: @Transformdecorators Mar 29, 2021
@yuval-hazaz yuval-hazaz changed the title DSG: @Transformdecorators DSG: @Transform decorators Mar 29, 2021
@yuval-hazaz
Copy link
Member

@EndersDev can you please share the error you receive regarding the @trasnform decorator?

By the reference of the decorator
image
the decorator expect as the first parameter a function transformFn that receive as the first parameter the value

using this code

@Transform(JSON.parse)

is just a shorthand of this

@Transform(value => JSON.parse(value))

which should work, as it is a function that gets the value as the first parameter and executes JSON.parse on the value

I also tested it and didn't get any errors.
(by the way, the property was missing the @field decorator and i opened a new issue about it #1298 )

@yuval-hazaz
Copy link
Member

This issue was closed because it has been inactive for more than 30 days

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

No branches or pull requests

2 participants