:pray: Hi. I lost 24 hours with this problem. Can ...
# orm-help
y
🙏 Hi. I lost 24 hours with this problem. Can you make any suggestions? When I run createDraft2 mutation, I get error. I show the problem in this video: t.ly/f2wd
r
Hey @Yiğit Rüzgar 👋 Could you share the resolver of your
createDraft2
mutation? It seems that
findUnique
cannot get the argument in
where
.
y
Thanks a lot. You are ultra speed.
This is second video for you: t.ly/pp8f
Gorevlendirmeler.ts - Mutations
Gorevlendirmeler.ts - Queries
models.ts @Ryan
types.ts
mutation($xxx: Int) { createDraft2( data: { surec_numara: 2 gorev_numara: 2 ana_gorev_numara: 4 ana_gorev: "6" baslik: "assda" tarih: "12/12/2020" saat: "145500" termin_dk: 2 termin_gun: 2 termin_saat: 6 eklenme_tarihi: "12/12/2020" eklenme_saati: "141414" aktif: "1" bitirilmesi_gereken_tarih: "12/12/2020" bitirilmesi_gereken_saat: "141412" bitirme_tarihi: "12/12/2020" bitirme_saati: "161616" bitirme_notu: "asd" ekleyen_numara: 6 opsiyonel: "6" gorevlipersonel: { connect: { numara: $xxx } } } ) { baslik } } ---------------->>>>>>>>>>>>>> { "errors": [ { "message": "\nInvalid
prisma.yonetim.findUnique()
invocation:\n\n{\n where: {\n? numara?: Int\n },\n select: {\n gorevlipersonel: true\n }\n}\n\nArgument where of type GorevlendirmelerWhereUniqueInput needs at least one argument. Available args are listed in green.\n\nNote: Lines with ? are optional.\n", "locations": [ { "line": 2, "column": 3 } ], "path": [ "createDraft2" ], "extensions": { "code": "INTERNAL_SERVER_ERROR", "exception": { "clientVersion": "2.12.1", "stacktrace": [ "Error: ", "Invalid
prisma.yonetim.findUnique()
invocation:", "", "{", " where: {", "? numara?: Int", " },", " select: {", " gorevlipersonel: true", " }", "}", "", "Argument where of type GorevlendirmelerWhereUniqueInput needs at least one argument. Available args are listed in green.", "", "Note: Lines with ? are optional.", "", " at Document.validate (/var/www/vhosts/developer3.xyz/next.developer3.xyz/next-auth/node_modules/@prisma/client/runtime/index.js7741319)", " at NewPrismaClient._executeRequest (/var/www/vhosts/developer3.xyz/next.developer3.xyz/next-auth/node_modules/@prisma/client/runtime/index.js7906517)", " at /var/www/vhosts/developer3.xyz/next.developer3.xyz/next-auth/node_modules/@prisma/client/runtime/index.js7900252", " at AsyncResource.runInAsyncScope (async_hooks.js1869)", " at NewPrismaClient._request (/var/www/vhosts/developer3.xyz/next.developer3.xyz/next-auth/node_modules/@prisma/client/runtime/index.js7900225)", " at Object.then (/var/www/vhosts/developer3.xyz/next.developer3.xyz/next-auth/node_modules/@prisma/client/runtime/index.js7911939)", " at processTicksAndRejections (internal/process/task_queues.js975)" ] } } } ], "data": null }
r
Is
ctx.userId
available? Because in your query you are passing it via a variable:
Copy code
gorevlipersonel: { connect: { numara: $xxx } }
And in the resolver you are using
ctx.userId
Copy code
gorevliPersonel: { connect: { numara: ctx.userId } }
I would suggest removing the
connect
and checking if it works. If it does, it means there could be an issue that the
userId
is not defined in the context.
y
When ı change ctx.userId with static number, type safe propery doesnt allow execute query.
r
What the error or message you get when you replace it with a number?
Also your
schema.prisma
doesn’t contain all the models that you have specified here. Could you add them to the repo so that I can reproduce?
y
Sorry for late.. I added repo..
Third Video:

https://www.youtube.com/watch?v=tCO4GL5mreM

UserId is avaliable in token
r
But is it available in the resolver?
y
I can't get a solution after this point. Give me help, please..
r
Checking your repo locally, it seems like there's an issue in the permissions you specified in the
rules.ts
file. I'll check what's the issue in the rule of
createDraft2
y
thanks.
r
This is causing an issue in `rules.ts`:
Copy code
isGorevlendirmelerOwner: rule({ cache: 'contextual' })(
    async (_parent, { numara }, ctx: Context) => {
      try {
        const gorevli = await ctx.prisma.gorevlendirmeler
          .findUnique({
            where: {
              numara,
            },
          })
          .gorevlipersonel()
        console.log('bayrak2')
        return ctx?.userId === gorevli?.numara
      } catch (e) {
        return e
      }
    }
  ),
There’s no such variable as
numara
in the args.
y
what must be ? * And, ı didnt understand that, where from, args passed here..
r
args
are you passed in
createDraft2
like the
data
.
Copy code
createDraft2(
    data: {
      surec_numara: 2
      gorev_numara: 2
      ana_gorev_numara: 4
      ana_gorev: "6"
      baslik: "assda"
      tarih: "12/12/2020"
      saat: "14:55:00"
      termin_dk: 2
      termin_gun: 2
      termin_saat: 6
      eklenme_tarihi: "12/12/2020"
      eklenme_saati: "14:14:14"
      aktif: "1"
      bitirilmesi_gereken_tarih: "12/12/2020"
      bitirilmesi_gereken_saat: "14:14:12"
      bitirme_tarihi: "12/12/2020"
      bitirme_saati: "16:16:16"
      bitirme_notu: "asd"
      ekleyen_numara: 6
      opsiyonel: "6"
      gorevlipersonel: { connect: { numara: $xxx } }
    }
  ) {
    baslik
  }
}
Here the
data
is the args. that you have passed.
y
Ok, ı understood args. Now, what must I do ?
r
What are you trying to check in the rule above?
y
The user with the "userId" number in the token can add with the "createDraft" mutation.
r
Then it would better to add it this way:
Copy code
isGorevlendirmelerOwner: rule({ cache: 'contextual' })(
    async (_parent, _args, ctx: Context) => {
      try {
        const gorevli = await ctx.prisma.yonetim.findUnique({
          where: {
            numara: ctx.userId,
          },
        })
        console.log('bayrak2')
        return ctx?.userId === gorevli?.numara
      } catch (e) {
        return e
      }
    }
  ),
y
Thanks. I am examining the new codes. I will return to you 🙏
💯 1
is there a short way cancel graphql-shield temporary for look the mutations and queries work correctly
r
Comment out the rules in the
rules.ts
y
Thanks a lot.. I passed to other steps of your helps. Now, I get some errors with date and time fields.. How can I integrate my database date and time fields with Schema Datetime fields ? I suppose that converto isoString, but how ? /// Lastly I insert this values, and problem is solved. ( 2020-05-05T163444.719+03:00 ) What is the best way, for the Datetime fields.
💯 1
r
Yes that's correct you would need to pass an ISO string. So if you have a Date object, you can pass:
date.toISOString()
y
thank you..
🙌 2