Problem
When using a specific graphql context type in an executor of wrapSchema, TypeScript will raise an error because the types of the context and the TContext of SubschemaConfig are incompatible.
import type {CustomAppContext} from './context'
import { wrapSchema } from '@graphql-tools/wrap'
const executor: AsyncExecutor<CustomAppContext> = ...
wrapSchema({
schema,
executor, // TS will error here
})
The TS error is Type 'AsyncExecutor<GraphQLContext>' is not assignable to type 'Executor<Record<string, any>>'.
Solution
Updating wrapSchema to make it generic works:
import { GraphQLSchema } from 'graphql';
import { SubschemaConfig } from '@graphql-tools/delegate';
export declare function wrapSchema<K = any, V = any, C = K, TContext = Record<string, any>>(subschemaConfig: SubschemaConfig<K, V, C, TContext>): GraphQLSchema;
// let's you write
wrapSchema<any, any, any, GraphQLContext>(...) // which works
Another alternative for typings:
// I'd prefer, it makes the signature easier to grasp, the K V C is a bit confusing from an external perspective
declare function wrapSchema<TContext = Record<string, any>>(subschemaConfig: SubschemaConfig<any, any, any, TContext>): GraphQLSchema;
I tried something like declare function wrapSchema<Config extends SubschemaConfig>(subschemaConfig: Config): GraphQLSchema; but somehow I still had the same issue.
I'll open a PR meanwhile, but feel free to let me know if I missed anything.
Problem
When using a specific graphql
contexttype in anexecutorofwrapSchema, TypeScript will raise an error because the types of the context and theTContextofSubschemaConfigare incompatible.The TS error is
Type 'AsyncExecutor<GraphQLContext>' is not assignable to type 'Executor<Record<string, any>>'.Solution
Updating
wrapSchemato make it generic works:Another alternative for typings:
I tried something like
declare function wrapSchema<Config extends SubschemaConfig>(subschemaConfig: Config): GraphQLSchema;but somehow I still had the same issue.I'll open a PR meanwhile, but feel free to let me know if I missed anything.