【发布时间】:2020-06-26 17:53:46
【问题描述】:
我已经开始在 nodejs 上使用带有 graphql 的 typescript。但让我印象深刻的一件事是使用 apollo-server-express 中的gql。有没有办法可以在其他地方使用 graphql 模式中使用的类型。
import { gql } from 'apollo-server-express';
export const userSchema = gql`
type User {
id: String!
name: String
}
type Query {
getUsers: [User]
}
`;
现在我不想为User 创建单独的接口。并希望有如下界面可供使用:
export const usersResolver = {
Query: {
getUsers: () => db.get(condition).then(result => {
const users:Array<User> = [];
}
}
};
另外,我也想在前端使用这些类型。
如何做到这一点。
【问题讨论】:
标签: node.js typescript graphql frontend