Hi guys,
Any idea why this fails to compile? I followed all the guidelines correctly.
Server works in dev mode.
Code for the line 44:
// ...
const db: Prisma = new Prisma(prismaOptions)
const typeDefs = importSchema('app-schema.graphql')
const schema = makeExecutableSchema({typeDefs, resolvers})
const server = new GraphQLServer({
schema,
directiveResolvers: directiveResolvers,
context: req => {
return {
...req,
db,
}
},
})
Build failed output:
$ rimraf dist && tsc --pretty
src/index.ts:40:34 - error TS2345: Argument of type '{ schema: GraphQLSchema; directiveResolvers: { isAuthenticated: (next: any, source: any, args: an...' is not assignable to parameter of type 'Props'.
Types of property 'schema' are incompatible.
Type 'GraphQLSchema' is not assignable to type 'GraphQLSchema'. Two different types with this name exist, but they are unrelated.
Types of property 'astNode' are incompatible.
Type 'SchemaDefinitionNode' is not assignable to type 'SchemaDefinitionNode'. Two different types with this name exist, but they are unrelated.
Types of property 'loc' are incompatible.
Type 'Location' is not assignable to type 'Location'. Two different types with this name exist, but they are unrelated.
Types of property 'startToken' are incompatible.
Type 'Token' is not assignable to type 'Token'. Two different types with this name exist, but they are unrelated.
Types of property 'prev' are incompatible.
Type 'Token' is not assignable to type 'Token'. Two different types with this name exist, but they are unrelated.
40 const server = new GraphQLServer({
~
41 schema,
~~~~~~~~~
...
48 },
~~~~
49 })
~
thanks
Server works in dev mode.
In what mode doesn't it work then? are you deploying it to a specific system?
I need to build it to create docker box. the project is based off official Prisma TS boilerplate which has an issue ( found out about it yesterday ) with version mismatch in yarn.lock and package.json. Meaning that if you clone project and run yarn then yarn build it builds it nicely if you install any package then build it fails.
The issue has been solved and I'm adding it here as a ref.
I had the following
// UserMutation.ts
import {forwardTo} from 'prisma-binding'
import {Context} from '../../interfaces'
export default {
async createUser(parent, {data}, ctx: Context, info) {
return ctx.db.mutation.createUser(
{
data,
},
info,
)
},
updateUser: forwardTo('db'),
}
Signatures are different, that's why it fails on the updateUser.
...
createUser: [Function: createUser],
updateUser: [Function],
...
because clearly Iresolvers interface is defined bit differently:
export interface IResolvers {
[key: string]: (() => any) | IResolverObject | GraphQLScalarType;
}
So changing all that to following:
import {Context} from '../../interfaces'
export default {
async createUser(parent, {data}, ctx: Context, info) {
return ctx.db.mutation.createUser(
{
data,
},
info,
)
},
async updateUser(parent, {data, where}, ctx: Context, info) {
return ctx.db.mutation.updateUser(
{
data,
where,
},
info,
)
},
}
builds it even with --declarations :)
I'm having similar issue with IResolver. My project compiles if I modify it but appending | any at Interface.d.ts definition.
(I'm breaking the type checking like other cited solutions)
I don't know this is same for everyone else, but after I added
yarn add --dev @types/graphql
everything works fine for me
Most helpful comment
I don't know this is same for everyone else, but after I added
yarn add --dev @types/graphqleverything works fine for me