apollographql / apollographql/apollo-tooling

Incomplete (and duplicate) GraphQLResolverMap typings

Open
#1,671 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

**Intended outcome:**

`GraphQLResolverMap` should accept `enum` and _scalars_. The following resolver should not produce any TypeScript error:

```ts
enum SomeEnum {
FOO = "foo",
BAR = "bar",
}

const AnotherEnum = {
FOO: "foo",
BAR: "bar",
};

const resolvers: GraphQLResolverMap = {
SomeEnum,
AnotherEnum,
};
```

**Actual outcome:**

Works fine when using `GraphQLResolverMap` from `apollo-graphql` but does not when importing from `@apollographql/apollo-tools`.

`GraphQLResolverMap` is defined within `apollo-graphql` and `@apollographql/apollo-tools` but the definitions are not the same.

```ts
// apollo-graphql/src/schema/resolverMap.ts
export interface GraphQLResolverMap {
[typeName: string]:
| {
[fieldName: string]:
| GraphQLFieldResolver
| {
requires?: string;
resolve: GraphQLFieldResolver;
};
}
| GraphQLScalarType
| {
[enumValue: string]: string | number;
};
}
```

```ts
// apollo-tools/src/schema/resolverMap.ts
export interface GraphQLResolverMap {
[typeName: string]: {
[fieldName: string]:
| GraphQLFieldResolver
| {
requires?: string;
resolve: GraphQLFieldResolver;
subscribe?: undefined;
}
| {
requires?: string;
resolve?: undefined;
subscribe: GraphQLFieldResolver;
}
| {
requires?: string;
resolve: GraphQLFieldResolver;
subscribe: GraphQLFieldResolver;
};
};
}
```

This is problematic since `apollo-server` uses the definitions from `@apollographql/apollo-tools` to type `modules` config parameter.

**How to reproduce the issue:**

```ts
import {
GraphQLResolverMap,
} from "apollo-graphql";
import {
GraphQLResolverMap as GraphQLResolverMap_,
} from "@apollographql/apollo-tools";

enum SomeEnum {
FOO = "foo",
BAR = "bar",
}

const AnotherEnum = {
FOO: "foo",
BAR: "bar",
};

const resolvers1: GraphQLResolverMap = {
SomeEnum,
AnotherEnum,
};

const resolvers2: GraphQLResolverMap_ = {
SomeEnum,
AnotherEnum,
};
```

**Versions**

- `@apollographql/apollo-tools`: 0.4.1
- `apollo-graphql`: 4.0.0

Contributor guide

Open the contributing guide

Research direction

Start by comparing apollo-graphql/src/schema/resolverMap.ts with apollo-tools/src/schema/resolverMap.ts, focusing on the resolver value types and their enum and scalar support. Update the apollo-tools typing to match the intended GraphQLResolverMap behavior, then verify that the reproduction assigns both enum forms without a TypeScript error while retaining resolver and subscription support.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.