首页 > 解决方案 > 自动生成 GraphQL API 接口

问题描述

我正在使用 Apollo 访问 GraphQL 端点。我在文件中有完整的架构。假设架构如下:

type Widget {
    widgetId: ID!
    name: String
}

type Query {
    listWidgets: [Widget!]!
}

type Mutation {
    updateWidget(
        widgetId: ID!
        name: String
    ): Widget!
}

我想创建一个具有如下接口的 API 对象:

const api = MyApi(endpoint);

const widgets = await api.listWidgets();

const modifiedWidget = await api.updateWidget({
    widgetId: 'myId',
    name: 'My widget',
});

是否有现有的系统可以做到这一点?

标签: javascriptnode.jsgraphqlapollo-client

解决方案


到目前为止,我在研究中看到的最强大的东西是graphql-sequelize,它是 Sequelize 接口的一个 graphql 数据库后端,它是 Node.js 目前更流行的 ORM 之一。


推荐阅读