Closed otrebu closed 3 years ago
I have been carefully looking at the issue, I think I must have been to quick in building up my schema and missed some imports.
I was referencing the input types directly in my mutations, which it is not enough on its own.
So this took me a long time to try to solve, but this got my type safety for arguments.
I had custom scalars
import { GraphQLDateTime } from 'graphql-scalars';
import { GraphQLUpload } from 'graphql-upload';
export const DateTime = GraphQLDateTime;
export const Upload = GraphQLUpload;
Which were defined as any in the generated typegen file
To solve this in your makeSchema
declaration this code worked for me
const schema = makeSchema({
// other stuff
sourceTypes: {
modules: [
{ module: '@types/graphql-upload/index.d.ts', alias: 'upload' }, // the location in node_modules where '@types/graphql-upload is defined
],
mapping: {
DateTime: 'Date', // I think Date as a type already exists in node so this worked
Upload: 'upload.FileUpload', // FileUpload is the interface in @types/graphql-upload
},
},
});
This achieved type safety for me
Oh yes @100AD ! I noticed that too, without the mapping you won't have type safety on those fields.
I am going to close this issue soon, I am pretty sure that what was going wrong was my own fault. Mainly to do with having missed to export/import my input types properly.
@tgriesser could be interesting maybe to be able to not have to import input types ( or object types that are returned in Mutations ) if they are used in a Mutation directly. Just a thought.
Usually you just need to open the generated file for the typing to be picked-up, not much we can do
I'm getting a similar error:
Can this be resolved with zod to ensure type safety??
I don't think I am doing anything particularly wrong, but I don't have types for mutation args and return type in the resolve function.
See example below ( what is actually hovered is not the actual issue, the args within the resolve function are of type any, the root type is any and also the return type )
The
nexus-typegen.ts
file is successfully generated.I have generated all my code from the sdl converter, now I am starting again to scratch to see if I can work out what is that breaks the typescript type reflection.