graphql-hive / graphql-hive/envelop

Poor typings in `ExecutionArgs` in `@envelop/types`

Open
#2,085 2 comments 2 reactions 1 assignee Claimed by @EmrysMyrddin View on GitHub
kind/bug stage/1-reproduction
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

I enabled `@typescript-eslint/no-unsafe-member-access` (part of `plugin:@typescript-eslint/recommended-type-checked`) and I get into trouble now for ```Unsafe member access .definitions on an `any` value.```

This is due to the typings in `ExecutionArgs` in `@envelop/types` `v5.0.0` which look like this:
```ts
export interface ExecutionArgs {
schema: any;
document: any;
rootValue?: any;
contextValue?: any;
variableValues?: any;
operationName?: any;
fieldResolver?: any;
typeResolver?: any;
subscribeFieldResolver?: any;
}
```
Example:
```ts
import { type Plugin } from 'graphql-yoga';
export const useErrorHandling = (): Plugin => {
return {
onExecute: (payload) => {
const operationName = payload.args.operationName as unknown as string; // manual type casting...
const operation = payload.args.document.definitions[0]
// ^-- Unsafe member access .definitions on an `any` value
```

Is unsafely accessing `definitions` on `document: any`.

**Describe the solution you'd like**

Isn't there anything we can do to give the user more hints that we have some sort of clue what these properties are? It is set by the framework isn't it so we should know that it is at least e.g.

```ts
export interface ExecutionArgs {
schema: Schema; // Whatever the correct type is
document: Document; // Whatever this type is, and that it is likely including `operation` which is e.g `query` | `mutation`
rootValue?: RootValue; // Whatever the correct type is
contextValue?: Record; // Should be possible to get from Context generic
variableValues?: Record;
operationName?: string;
fieldResolver?: SomeFn;
typeResolver?: AnotherFn;
subscribeFieldResolver?: ThirdFn;
}
```

**Describe alternatives you've considered**

- Overriding the type def myself, but I dont think I can make typings file that overrides an internal type :-(
- Laborious type casting in place everytime we access this

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.