在Ubuntu上安装graphql-yoga时引发的错误

时间:2018-11-08 02:34:02

标签: graphql mern

Errors after installing GraphQL Yoga

我试图按照Edureka https://www.youtube.com/watch?v=rpJO0T08Bnc的教程视频学习,并使用其他说明在Ubuntu上进行安装。发生了严重错误,因为我无法在localhost:4000上访问该应用程序。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您创建服务器了吗?让我跟随。

  1. yarn add graphql-yoganpm install graphql-yoga --save
  2. 创建'.babelrc',然后写入{ "presets": [ "env", "stage-3" ] }
  3. 纱线添加全局babel-cli,纱线添加babel-cli babel-preset-env babel-state-3 如果您想使用es6,请安装这些。您可以安装它。
  4. create the index.js并添加

    `import { GraphQLServer } from 'graphql-yoga';
     import resolvers from './graphql/resolvers'
    
      const server = new GraphQLServer({
          typeDefs: "./graphql/schema.graphql",
          resolvers: resolvers
    }); 
    
    server.start(() => console.log("Graphql Server Running "));`
    
  5. 这是我的package.json。遵循此“脚本”

    { "version": "1.0.0", "main": "index.js", "license": "MIT", "dependencies": { "graphql-yoga": "^1.16.7" }, "scripts": { "start": "nodemon --exec babel-node index.js" }, "devDependencies": { "babel-cli": "^6.26.0", "babel-preset-env": "^1.7.0", "babel-preset-stage-3": "^6.24.1" } }

  6. 制作schema.graphql,resolvers.js

这些是我的“ Initail创建GraphQL瑜伽设置”