Replies: 6 comments 3 replies
-
hi @t0xa, thanks for the kind words. I don't have Pateron or Buy me a coffee which I think I should set up (I do have Github Sponsors but people tend to stay away from Monthly fee 😛). Thanks again for your support. As far as mapping with types/interfaces, there's @automapper/pojos but I am not too confident about it. If you could, please check out the POJOs plugin out and see if it works for you, what can be improved, what needs to be fixed etc... I'll gladly support and provide fixes. |
Beta Was this translation helpful? Give feedback.
-
Hi @nartc, thanks a lot for suggestion. Let's close this question for now. I will open another ticket in case of issues. May I suggest to enable Github Discussion feature so that such questions would be easier to navigate. Regarding the sponsoring, can you do something similar to what OctoPrint does on her main page? |
Beta Was this translation helpful? Give feedback.
-
I have just turned on Discussions. And I'll check out that OctoPrint. Thanks! |
Beta Was this translation helpful? Give feedback.
-
I just tested Prisma types with pojos plugin and it works perfect. |
Beta Was this translation helpful? Give feedback.
-
Thanks @notmedia. Out of curiosity, did you have any |
Beta Was this translation helpful? Give feedback.
-
Yes, in my case I have entity with JsonValue. The structure of JSON field depends on another field I need this for GraphQL, for automatic resolve type // This type generated by Prisma
type PrismaEntity = {
type: 'one' | 'two';
config: JsonValue,
}
@ObjectType()
class OneConfig {
constructor(config: { [K in keyof OneConfig]: OneConfig[K] }) {
this.test = config.test;
}
@Field({
description: 'Test value',
})
test: string;
}
@ObjectType()
class TwoConfig {
...
}
const ConfigUnion = createUnionType({
name: 'ConfigUnion',
types: () => [OneConfig, TwoConfig],
});
@ObjectType()
class Entity {
@Field(...)
type: 'one' | 'two';
@Field(...)
config: typeof ConfigUnion;
}
// Created for POJOs mapping from Prisma entity to backend entity
createMetadataMap<Entity>('Entity', {
type: String,
});
createMetadataMap<PrismaEntity>('PrismaEntity', 'Entity', {
type: String,
});
@Injectable()
class PrismaEntityProfile extends AutomapperProfile {
constructor(@InjectMapper('pojos') mapper: Mapper) {
super(mapper);
}
mapProfile() {
return (mapper: Mapper) => {
mapper.createMap<PrismaEntity, Entity>('PrismaEntity', 'Entity').forMember(
(destination) => destination.config,
mapFrom((source) => {
switch(source.type) {
case 'one': return new OneConfig(source.config as OneConfig)
...
}
})
);
};
}
} |
Beta Was this translation helpful? Give feedback.
-
Hello @nartc,
First of all, thank you for such incredible project. It helped me to build things much faster. Do you have a Patreon or Buy me a coffee so we can show our appreciation?
Could you please help me to understand how to correctly use Automapper with Prisma ORM.
The main problem is that Prisma generates
type
instead ofclass
. For example:Is there a way of doing
mapper.createMap()
with types or some other way of creating such mapper?Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions