Skip to content

Commit

Permalink
Fix Resolver type (#4943)
Browse files Browse the repository at this point in the history
* Match Resolver and Resolvers

The exported type for Resolve differs from Resolvers. This causes some type errors when trying to type your resolvers. Where we call the resolver we only use the indicated parameters (fieldName never gets passed to the resolver, e.g https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/core/LocalState.ts#L391). Also it is aligned with the GraphQL Resolver API

* Add Changelog
  • Loading branch information
peoplenarthax authored and hwillson committed Sep 4, 2019
1 parent 815aa16 commit fa581c1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
- Documentation updates. <br/>
[@michael-watson](https://github.com/michael-watson) in [#4940](https://github.com/apollographql/apollo-client/pull/4940) <br/>
[@hwillson](https://github.com/hwillson) in [#4969](https://github.com/apollographql/apollo-client/pull/4969)

- Fix type for `Resolver` and use it in the definition of `Resolvers`. <br /> [@peoplenarthax](https://github.com/peoplenarthax)

## Apollo Client (2.6.1)

Expand Down
9 changes: 4 additions & 5 deletions packages/apollo-client/src/core/LocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ import { Resolvers, OperationVariables } from './types';
import { capitalizeFirstLetter } from '../util/capitalizeFirstLetter';

export type Resolver = (
fieldName: string,
rootValue: any,
args: any,
context: any,
info: {
rootValue?: any,
args?: any,
context?: any,
info?: {
field: FieldNode;
},
) => any;
Expand Down
8 changes: 2 additions & 6 deletions packages/apollo-client/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DocumentNode, GraphQLError } from 'graphql';

import { QueryStoreValue } from '../data/queries';
import { NetworkStatus } from './networkStatus';
import { Resolver } from './LocalState';

export type QueryListener = (
queryStoreValue: QueryStoreValue,
Expand Down Expand Up @@ -48,11 +49,6 @@ export type MutationQueryReducersMap<T = { [key: string]: any }> = {

export interface Resolvers {
[key: string]: {
[field: string]: (
rootValue?: any,
args?: any,
context?: any,
info?: any,
) => any;
[ field: string ]: Resolver;
};
}

0 comments on commit fa581c1

Please sign in to comment.