Skip to content

Add TContext to type resolvers #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {
export class GraphQLObjectType {
name: string;
description: ?string;
isTypeOf: ?GraphQLIsTypeOfFn;
isTypeOf: ?GraphQLIsTypeOfFn<*, *>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this isn't <TSource, TContext>? I'm updating the DefinitelyTyped @types/graphql and couldn't find this documented anywhere in Flow. Would be a great help to point me in the right direction.


_typeConfig: GraphQLObjectTypeConfig<*, *>;
_fields: GraphQLFieldMap<*, *>;
Expand Down Expand Up @@ -511,19 +511,19 @@ export type GraphQLObjectTypeConfig<TSource, TContext> = {
name: string;
interfaces?: Thunk<?Array<GraphQLInterfaceType>>;
fields: Thunk<GraphQLFieldConfigMap<TSource, TContext>>;
isTypeOf?: ?GraphQLIsTypeOfFn;
isTypeOf?: ?GraphQLIsTypeOfFn<TSource, TContext>;
description?: ?string
};

export type GraphQLTypeResolver = (
value: mixed,
context: mixed,
export type GraphQLTypeResolver<TSource, TContext> = (
value: TSource,
context: TContext,
info: GraphQLResolveInfo
) => ?GraphQLObjectType | ?string;

export type GraphQLIsTypeOfFn = (
source: mixed,
context: mixed,
export type GraphQLIsTypeOfFn<TSource, TContext> = (
source: TSource,
context: TContext,
info: GraphQLResolveInfo
) => boolean;

Expand Down Expand Up @@ -615,7 +615,7 @@ export type GraphQLFieldMap<TSource, TContext> = {
export class GraphQLInterfaceType {
name: string;
description: ?string;
resolveType: ?GraphQLTypeResolver;
resolveType: ?GraphQLTypeResolver<*, *>;

_typeConfig: GraphQLInterfaceTypeConfig<*, *>;
_fields: GraphQLFieldMap<*, *>;
Expand Down Expand Up @@ -653,7 +653,7 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {
* the default implementation will call `isTypeOf` on each implementing
* Object type.
*/
resolveType?: ?GraphQLTypeResolver,
resolveType?: ?GraphQLTypeResolver<TSource, TContext>,
description?: ?string
};

Expand Down Expand Up @@ -685,13 +685,13 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {
export class GraphQLUnionType {
name: string;
description: ?string;
resolveType: ?GraphQLTypeResolver;
resolveType: ?GraphQLTypeResolver<*, *>;

_typeConfig: GraphQLUnionTypeConfig;
_typeConfig: GraphQLUnionTypeConfig<*, *>;
_types: Array<GraphQLObjectType>;
_possibleTypeNames: {[typeName: string]: boolean};

constructor(config: GraphQLUnionTypeConfig) {
constructor(config: GraphQLUnionTypeConfig<*, *>) {
invariant(config.name, 'Type must be named.');
assertValidName(config.name);
this.name = config.name;
Expand Down Expand Up @@ -748,15 +748,15 @@ function defineTypes(
return types;
}

export type GraphQLUnionTypeConfig = {
export type GraphQLUnionTypeConfig<TSource, TContext> = {
name: string,
types: Thunk<Array<GraphQLObjectType>>,
/**
* Optionally provide a custom type resolver function. If one is not provided,
* the default implementation will call `isTypeOf` on each implementing
* Object type.
*/
resolveType?: ?GraphQLTypeResolver;
resolveType?: ?GraphQLTypeResolver<TSource, TContext>;
description?: ?string;
};

Expand Down