I have a TS error whenever I try use GraphQL context.params.variables that I need on relation resolvers:
relation: (_obj, { root, context }) => {
return db.thing.findUnique({id:root?.id, date:context.params.variables.date, field:"thing", take: 2})
I found this on node_modules/@redwoodjs/graphql-server/dist/types.d.ts:
/** This is an interface so you can extend it inside your application when needed */
export interface RedwoodGraphQLContext {
event: APIGatewayProxyEvent;
requestContext: LambdaContext;
currentUser?: ThenArg<ReturnType<GetCurrentUser>> | AuthContextPayload | null;
[index: string]: unknown;
}
I tried extending it in api/types/custom.d.ts (with or without export
before interface
):
// custom.d.ts
declare module '@redwoodjs/graphql-server' {
interface RedwoodGraphQLContext {
params: {variables: any};
}
}
And my api/tsconfig.json:
{
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"esModuleInterop": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"skipLibCheck": false,
"baseUrl": "./",
"rootDirs": [
"./src",
"../.redwood/types/mirror/api/src"
],
"paths": {
"src/*": [
"./src/*",
"../.redwood/types/mirror/api/src/*"
],
"types/*": ["./types/*", "../types/*"],
"@redwoodjs/testing": ["../node_modules/@redwoodjs/testing/api"],
// An attempt
"@redwoodjs/graphql-server": ["./types/custom.d.ts", "../node_modules/@redwoodjs/graphql-server"]
},
"typeRoots": [
"../node_modules/@types",
"./node_modules/@types"
],
"types": ["jest"],
},
"include": [
"src",
"../.redwood/types/includes/all-*",
"../.redwood/types/includes/api-*",
"../types",
// An attempt
"./types/custom.d.ts",
"../web/src/fragments"
]
}
I still have the type error. How can I properly extend the type RedwoodGraphQLContext ?