错误 GraphQL“Query.GetUser 的类型必须是输出类型但得到:未定义”

问题描述

在编写我的第一个 Graphql 时遇到了这个问题。

数据未显示

index.js

  lazy val module = new MapModule{}
  lazy val mapper = JsonMapper.builder()
  .addModule(module)
  .build()
  ...
  val map: Map[String,Any] = mapper.readValue(line,classOf[Map[String,Any]])

schema.js

const express = require('express')
const app = express()
const graphql = require('graphql')
const {graphqlHTTP} = require('express-graphql')
const { GetUser,mutation } = require('./schema')
const { DataType } = require('./DataType')
app.use(express.json())

const schema = new graphql.GraphQLSchema({
    query: new graphql.GraphQLObjectType({
        name:"Query",type:new graphql.GraphQLList(DataType),fields:{GetUser}
    }),mutation:new graphql.GraphQLObjectType({
        name:"Mutation",fields:{mutation}
    })
})
app.use('/graphql',graphqlHTTP({
    schema,graphiql:true
}))

app.listen(1200,()=>{
    console.log("SERVER AT 1200");
})

DataType.js

const graphql = require('graphql')
const {GraphQLObjectType,GraphQLString} = graphql
const {DataType} = require('./DataType')

var data = [
    {
        "name":"Book1","price":123
    },{
        "name":"Book2","price":1232
    },{
        "name":"Book3","price":2021
    },]

exports.GetUser = new GraphQLObjectType({
    name:"GetAllUser",fileds:{
        getAllUser:{
            name:"getUser",resolve:()=>{
                return data;
            }
        }
    }
})

exports.mutation = new GraphQLObjectType({
    name:"AddData",fields:{
        adduser:{
            name:"adduser",type:data,args:{
                name:{type:GraphQLString},price:{type:graphql.GraphQLInt}
            },resolve:(_,args)=>{
                data.push(args)
                return args
            }
        }
    }
})

运行 graphql:

const graphql = require('graphql')

exports.DataType = new graphql.GraphQLObjectType({
    name:"DataType",fields:()=>({
        name:{
            type: graphql.GraphQLString
        },price:{
            type:graphql.GraphQLInt
        }
    })
})

我得到的错误:

query{
  GetUser{
    name

  }
}

错误说 Query.GetUser 的类型必须是输出类型但得到:未定义。

我再次定义了查询的类型,但仍然显示相同的变异错误。

这也是我接触 Graphql 的第一天。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...