I'm using this library and function: https://github.com/mickhansen/graphql-sequelize/blob/master/src/resolver.js#L119
It's essentially a factory that returns a GraphQL Resolver function. Alongside that, you can add a property to the factory like so:
resolver.contextToOptions = {
dataloaderContext: [EXPECTED_OPTIONS_KEY],
};
This code 100% works and is documented to be used like so. I'm just trying to create a typescript definition file for this library I'm using so I can't just fix it at the source obviously. I've created a type for the factory function like so:
type ResolverOptions = {
after?: (result: any, args: any, context: any, info: GraphQLResolveInfo) => any;
before?: (options: any, args: any, context: any, info: GraphQLResolveInfo) => any;
handleConnection?: boolean;
list?: boolean;
};
export function resolver<T>(targetMaybeThunk: T | ((...args: any[]) => T), options?: ResolverOptions): GraphQLFieldResolver;
And in my code it gives an error:
Property contextToOptions does not exist on type
I tried doing the below:
export function resolver<T>(targetMaybeThunk: T | ((...args: any[]) => T), options?: ResolverOptions): GraphQLFieldResolver;
namespace resolver {
const contextToOptions: {
dataloaderContext: string[];
};
}
And now my code says:
Cannot assign to contextToOptions because it is a read-only property.
I've no idea how to type a factory function to allow adding properties to it.