javascript - 在 GraphQL Resolvers 文件中定义一个函数
问题描述
我想在定义解析器的同一个 ts 文件中定义一个函数
export const resolvers = {
Query: {
books: () => {
return [
{
title: 'Harry Potter and the Chamber of Secrets',
author: 'J.K. Rowling',
},
{
title: 'Jurassic Park',
author: 'Michael Crichton',
},
];
},
},
};
private export (id: string): boolean {
...
return true;
}
但我得到一个编译错误
TS2304: Cannot find name 'export'.
解决方案
这是因为您的函数声明无效。你可以这样尝试:
private export function someName(id: string): boolean {
return true;
}
但是你会得到另一个错误:
'private' modifier cannot appear on a module or namespace element.
所以最终的解决方案是:
export function someName(id: string): boolean {
return true;
}
推荐阅读
- android - 身份验证和实时数据库中的 Android Firebase 相关错误
- c++ - 从 svc 触发 pendsv || 手动触发 systick 皮质 m4
- java - @ComponentScan 在 org.springframework.context.annotation 包中不存在
- angular - 两个日期之间的 TypeScript 差异
- java - 如何制作私人包裹?
- apache - 一台主机上的多个域 https 和 http
- java - 什么可能导致 Android 应用程序中完全的、灾难性的文件/数据丢失?
- excel - Excel VBA 计时器宏
- php - 在 php 中使用 IMAP 连接到 yahoo 邮件
- java - 深度系统 - 先前的“顶部”项目在更改时闪烁