【问题标题】:Implementing express graphql api with Gatsby graphql使用 Gatsby graphql 实现 express graphql api
【发布时间】:2019-10-12 03:44:35
【问题描述】:

所以我正在使用 express js、graphql、postgres 和 react 构建一个应用程序。而且我已经构建了我的后端,但现在我不想使用反应,而是想使用 GatsbyJs 如何将我的 express graphiql 与我的 Gatsby graphiql 连接或将我的数据直接发送到 Gatsby graphiql

【问题讨论】:

标签: express graphql gatsby


【解决方案1】:

在 gatsby-config.js 中添加以下内容

module.exports = {
  plugins: [
    {
      resolve: "gatsby-source-graphql",
      options: {
        // This type will contain remote schema Query type
        typeName: "MyGraph",
        // This is the field under which it's accessible
        fieldName: "myGraph",
        // URL to query from
        url: "http://localhost:4000/graphql",
      },
    },
  ],
}

然后在 index.js 中进行查询

export const query = graphql
  query {
    myGraph {
      users {
        name
        age
      }
    }
  }

【讨论】:

    猜你喜欢
    • 2019-09-29
    • 2020-11-17
    • 2022-09-29
    • 2017-11-18
    • 2020-08-28
    • 2019-02-19
    • 2017-09-01
    • 2021-05-08
    • 2020-03-23
    相关资源
    最近更新 更多