OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Wierdest behaviour, prismaClient when used on diff lines gives error of joi validation,

  • Thread starter Thread starter Jayesh Ahirrao
  • Start date Start date
J

Jayesh Ahirrao

Guest
i am using prisma and graphql i was refactoring the code when i use direct query to prismaCLient it works but if i use the same query from TweetService which does same i get DB_URL required which i load in config using Joi validation

all other queries in TweetService are working fine.

i am attaching the video for ref

Here are some examples: Wokrs:

  1. ==>

Code:
const nestedRelationResolver = {
    User: {
        // tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}), 
        tweets: async (parent: User) => {
            // const tweet = await TweetService.getAllForUser(parent.id, "desc");
            // return tweet;
            return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
        }
        // tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
    }
}
  1. ==>

Code:
const nestedRelationResolver = {
    User: {
        // tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}), 
        tweets: async (parent: User) => {
            const tweet = await TweetService.getAllForUser(parent.id, "desc");
            return tweet;
            return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
        }
        // tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
    }
}
  1. ==>

Code:
const nestedRelationResolver = {
    User: {
        tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}), 
        // tweets: async (parent: User) => {
        //     const tweet = await TweetService.getAllForUser(parent.id, "desc");
        //     return tweet;
        //     return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
        // }
        // tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
    }
}

Does not wokr :

  1. ==>

Code:
const nestedRelationResolver = {
    User: {
        // tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}), 
        // tweets: async (parent: User) => {
        //     const tweet = await TweetService.getAllForUser(parent.id, "desc");
        //     return tweet;
        //     return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
        // }
        tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
    }
}
  1. ==>

Code:
const nestedRelationResolver = {
    User: {
        // tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}), 
        tweets: async (parent: User) => {
            const tweet = await TweetService.getAllForUser(parent.id, "desc");
            return tweet;
            // return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
        }
        // tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
    }
}

even if i remove return and await its fine when i remove the statemtn it gives error

enter image description here

vid for ref Youtube

<p>i am using prisma and graphql
i was refactoring the code
when i use direct query to prismaCLient it works
but if i use the same query from TweetService which does same i get DB_URL required which i load in config using Joi validation</p>
<p>all other queries in TweetService are working fine.</p>
<p>i am attaching the video for ref</p>
<p>Here are some examples:
Wokrs:</p>
<ol>
<li>==></li>
</ol>
<pre><code>const nestedRelationResolver = {
User: {
// tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}),
tweets: async (parent: User) => {
// const tweet = await TweetService.getAllForUser(parent.id, "desc");
// return tweet;
return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
}
// tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
}
}
</code></pre>
<ol start="2">
<li>==></li>
</ol>
<pre><code>const nestedRelationResolver = {
User: {
// tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}),
tweets: async (parent: User) => {
const tweet = await TweetService.getAllForUser(parent.id, "desc");
return tweet;
return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
}
// tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
}
}
</code></pre>
<ol start="3">
<li>==></li>
</ol>
<pre><code>const nestedRelationResolver = {
User: {
tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}),
// tweets: async (parent: User) => {
// const tweet = await TweetService.getAllForUser(parent.id, "desc");
// return tweet;
// return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
// }
// tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
}
}
</code></pre>
<p>Does not wokr :</p>
<ol>
<li>==></li>
</ol>
<pre><code>const nestedRelationResolver = {
User: {
// tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}),
// tweets: async (parent: User) => {
// const tweet = await TweetService.getAllForUser(parent.id, "desc");
// return tweet;
// return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
// }
tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
}
}
</code></pre>
<ol start="2">
<li>==></li>
</ol>
<pre><code>const nestedRelationResolver = {
User: {
// tweets: (parent: User) => prismaClient.tweet.findMany({where: {userId : parent.id} , orderBy: { createdAt: "desc" }}),
tweets: async (parent: User) => {
const tweet = await TweetService.getAllForUser(parent.id, "desc");
return tweet;
// return await prismaClient.tweet.findMany({ where: { userId: parent.id }, orderBy: { createdAt: "desc" } });
}
// tweets: async (parent: User) => await TweetService.getAllForUser(parent.id, "desc"),
}
}
</code></pre>
<p>even if i remove return and await its fine when i remove the statemtn it gives error</p>
<p><a href="https://i.sstatic.net/xF56zjwi.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>vid for ref
<a href="
" rel="nofollow noreferrer">Youtube</a></p>
 

Latest posts

Top