本文整理汇总了TypeScript中graphql.GraphQLFieldResolver.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GraphQLFieldResolver.default方法的具体用法?TypeScript GraphQLFieldResolver.default怎么用?TypeScript GraphQLFieldResolver.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphql.GraphQLFieldResolver
的用法示例。
在下文中一共展示了GraphQLFieldResolver.default方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (obj, args, ctx, info) => {
return Promise.resolve(outerResolver(obj, args, ctx, info)).then(root => {
if (innerResolver) {
return innerResolver(root, args, ctx, info);
}
return defaultFieldResolver(root, args, ctx, info);
});
};
示例2: copyOwnProps
field.resolve = (
rootObject?: any,
args?: { [key: string]: any },
context?: any,
info?: GraphQLResolveInfo,
) =>
Promise.all([
mockResolver(rootObject, args, context, info),
oldResolver(rootObject, args, context, info),
]).then(values => {
const [mockedValue, resolvedValue] = values;
// In case we couldn't mock
if (mockedValue instanceof Error) {
// only if value was not resolved, populate the error.
if (undefined === resolvedValue) {
throw mockedValue;
}
return resolvedValue;
}
if (resolvedValue instanceof Date && mockedValue instanceof Date) {
return undefined !== resolvedValue ? resolvedValue : mockedValue;
}
if (isObject(mockedValue) && isObject(resolvedValue)) {
// Object.assign() won't do here, as we need to all properties, including
// the non-enumerable ones and defined using Object.defineProperty
const emptyObject = Object.create(
Object.getPrototypeOf(resolvedValue),
);
return copyOwnProps(emptyObject, resolvedValue, mockedValue);
}
return undefined !== resolvedValue ? resolvedValue : mockedValue;
});
示例3: return
return (root, args, ctx, info) => {
try {
const result = fn(root, args, ctx, info);
// If the resolve function returns a Promise log any Promise rejects.
if (
result &&
typeof result.then === 'function' &&
typeof result.catch === 'function'
) {
result.catch((reason: Error | string) => {
// make sure that it's an error we're logging.
const error = reason instanceof Error ? reason : new Error(reason);
logError(error);
// We don't want to leave an unhandled exception so pass on error.
return reason;
});
}
return result;
} catch (e) {
logError(e);
// we want to pass on the error, just in case.
throw e;
}
};
示例4: Error
return (root, args, ctx, info) => {
const result = fn(root, args, ctx, info);
if (typeof result === 'undefined') {
throw new Error(`Resolve function for "${hint}" returned undefined`);
}
return result;
};