微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

GraphQL 游乐场未显示在 localhost:4000 上

如何解决GraphQL 游乐场未显示在 localhost:4000 上

问题总结

我是 GraphQL 世界的新手,我正在使用初学者脚本来启动服务器并访问本地主机上的游乐场。当我访问它时,我看到一个空白页面,其中包含单词 EOF 作为纯文本(文件结尾)。

我的尝试

索引js

import { GraphQLServer } from 'graphql-yoga'

//Type DeFinitions (Schema)
const typeDefs = `
type Query {
    hello: String!
}
`

//Resolvers
const resolvers = {
    Query: {
        hello(){
            return 'This is my first query!'
        }
    }
}

const server = new GraphQLServer({
    typeDefs,resolvers
})

server.start(()=>{
    console.log(`server is up on: ${server.options.port}`)
})

控制台输出

server is up on: 4000

Web 浏览器输出

EOF 显示为纯文本,控制台上没有任何特定的错误消息。

我的 package.json

{
  "name": "graphql-basics","version": "1.0.0","description": "","main": "index.js","scripts": {
    "start": "babel-node src/index.js","test": "echo \"Error: no test specified\" && exit 1"
  },"author": "","license": "ISC","dependencies": {
    "babel-cli": "^6.26.0","babel-preset-env": "^1.7.0","graphql-yoga": "^1.14.10"
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。