Search code examples
typescriptnexus-prisma

issue when trying to use extendType in prisma nexusjs


I tried using extendtype in my project because all my files are not in a single folder, so for me to able to interact with them all I use extendType. But in the long run, i encounter an error that I can't fix at the moment.

Here is the error:

error:Expected 2 arguments, but got 1.

here is my data model

and after implementing it to my post file i created an error pop-out

Expected 2 arguments, but got 1.


Solution

  • First of all thanks for trying out Nexus.. it appears that you're having multiple Queries hence you're extending "Query", it seems that it's a VScode problem not reading the newly generated types on time or you're not getting something right, so. try this

    • Reload your workspace
    • Try to change t.nonNull.int("id") to t.int("id") if the problem goes away then you're in luck but then since you're not writing the model, you need to do something like this
    
    //... your nexus definition before here
           t.list.field("posts", {
                type: "Post",
                args:{
                  postId: intArg()
                }
                resolve(parent, { postId }, ctx) {
                    return ctx.prisma.post.findMany()
                }
            })
    

    always use t.nonNull for your nexus models not for queries unless when supplying them in arguments

    Secondly, what version of nexus are you using? t.nonNull was introduced recently and might have contributed to the culprit, but your Prisma model is just fine