Simple question. In javascript I have a resolver l...
# orm-help
y
Simple question. In javascript I have a resolver like
Copy code
const resolvers = {
    Query: {      
        laws(parent, args, context, info) {            
            return context.prisma.query.laws(
                { where: args.where, skip: args.skip, first: args.first, orderBy: args.orderBy },
                info,
            )
        },        
    },
}
, but i struggle to get it working in typescript :
Copy code
export const Query: QueryResolvers.Type = {
  ...QueryResolvers.defaultResolvers,
 
  laws: (parent, args, ctx) => ctx.db.laws({where: args.where})

}
throws the error
Property 'where' does not exist on type '{}'.
I have then tried to do something like
Copy code
interface LawsArgs{
  where?: lawsArgs.LawWhereInput;
  orderBy?: lawsArgs.LawOrderByInput;
  skip?: <http://lawsArgs.Int|lawsArgs.Int>;
  after?: String;
  before?: String;
  first?: <http://lawsArgs.Int|lawsArgs.Int>;
  last?: <http://lawsArgs.Int|lawsArgs.Int>;
}

export const Query: QueryResolvers.Type = {
  ...QueryResolvers.defaultResolvers,
  laws: (parent, args:LawsArgs, ctx) => ctx.db.laws({where: args.where})

}
but still no luck.. (I am a typescript newbie :-()
n
it's
ctx.db.laws(where: args.where)
y
If I do that I get `expected 0-1 arguments, but got 2`error. If you mean
ctx.db.laws({where: args.where})
i get the error
src/resolvers/Query.ts(20,57): error TS2339: Property 'where' does not exist on type '{}'.
I use the interfaces generated by graphqlgen
n
oh my bad
could you share your question + reproduction code in a new thread in the Forum? I'd love to run it locally: https://www.prisma.io/forum/
y
It works fine if I as in your links explicitly input e.g. arguments to
where
but I struggle to use the args. I have searched all the typescript examples in https://github.com/prisma/prisma-examples but there are not examples passing arguments e.g. as in javascript (works perfectly)
Copy code
return context.prisma.query.laws(
                { where: args.where, skip: args.skip, first: args.first, orderBy: args.orderBy },
I will try to post an running example on the forum later today 🙂 I have some kids to look after. School is closed
n
let's say your args are
a
,
b
,
c
, so you can at least do this:
Copy code
const {a, b, c} = ...args.where
ctx.db.laws({where: {a, b, c}})
y
yes but that is not very flexible. In reality is that I want to expose the flexible api of the prisma client, but perhaps that is not a good idea in the first place? Perhaps it is better only to use spceific queries?
n
what about
ctx.db.laws({where: ...args.where})
?
Yes, it's probably a better idea to individually shape your API in the longrun. But there's nothing inherently wrong with 1-1 passing through args either 🙂
y
nope tried that one as well 🙂 just add an additional error :
Copy code
src/resolvers/Query.ts(21,52): error TS1109: Expression expected.
src/resolvers/Query.ts(21,60): error TS2339: Property 'where' does not exist on type '{}'.
🙈 1
n
leaving this up to the TS experts out there! 🙂 I'm sure it's solvable though haha
y
in any case adding a typescript example where args are passed and the interfaces and resolvers are (partly) generated by graphqlgen would be nice 🙂 (i do not understand why you renamed the generator? something similar happened in graphcool and caused confusion for me 🙂 )
n
agreed! you can request new examples/content here: https://github.com/prisma/prisma-content-feedback/issues?
y
found a silly bug... in /src/schema.graphql i replaced
laws: [Law!]!
with
laws(where: LawWhereInput, skip: Int, first: Int, orderBy: LawOrderByInput): [Law!]!
but this lead to the error:
Copy code
src/resolvers/Query.ts(9,45): error TS2322: Type 'import("/home/jens/Desktop/onlaw.dk/packages/graphql/src/generated/graphqlgen").QueryResolvers.LawWhereInput' is not assignable to type 'import("/home/jens/Desktop/onlaw.dk/packages/graphql/src/generated/prisma-client/index").LawWhereInput'.
  Types of property 'justiceSystem' are incompatible.
    Type 'string' is not assignable to type 'JusticeSystemEnum'.
...which indicates that graphqlgen generates a string when it sees an enum. Should i Manually typecast ? in graphqlgen.ts
justiceSystem: string
n
I am not sure 🙂 It's really difficult to help debug errors like this, but if you'd prepare a small reproduction + bug report we can take a look: https://github.com/prisma/graphqlgen
y
I have been communicating with Schickling about this 🙂
👌 1