Skip to content

Commit

Permalink
Export default resolver function as defaultResolver
Browse files Browse the repository at this point in the history
Closes #527
  • Loading branch information
leebyron committed Nov 3, 2016
1 parent b93f049 commit c6a6388
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ function resolveField(
}

const returnType = fieldDef.type;
const resolveFn = fieldDef.resolve || defaultResolveFn;
const resolveFn = fieldDef.resolve || defaultFieldResolver;

// The resolve function's optional third argument is a context value that
// is provided to every resolve function within an execution. It is commonly
Expand Down Expand Up @@ -1017,7 +1017,8 @@ function defaultResolveTypeFn(
* and returns it as the result, or if it's a function, returns the result
* of calling that function while passing along args and context.
*/
function defaultResolveFn(source: any, args, context, { fieldName }) {
export const defaultFieldResolver: GraphQLFieldResolveFn<any> =
function (source, args, context, { fieldName }) {
// ensure source is a value for which property access is acceptable.
if (typeof source === 'object' || typeof source === 'function') {
const property = source[fieldName];
Expand All @@ -1026,7 +1027,7 @@ function defaultResolveFn(source: any, args, context, { fieldName }) {
}
return property;
}
}
};

/**
* Checks to see if this object acts like a Promise, i.e. has a "then"
Expand Down
2 changes: 1 addition & 1 deletion src/execution/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

export { execute } from './execute';
export { execute, defaultFieldResolver } from './execute';
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export {
// Execute GraphQL queries.
export {
execute,
defaultFieldResolver,
} from './execution';


Expand Down

0 comments on commit c6a6388

Please sign in to comment.