简体   繁体   中英

Implementing express graphql api with Gatsby graphql

So I am building an app using express js ,graphql, postgres and react. And I have already build my backend but now instead of using react, I want to use GatsbyJs how do I connect my express graphiql with my Gatsby graphiql or send my data directly to Gatsby graphiql

Add the following in 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",
      },
    },
  ],
}

Then in say index.js make the query

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM