java query类是什么类,Query.user的类型必须是输出类型,但得到:undefined

http://localhost:4000/当我输入 { user(id: 1) { firstName } } 时

我得到输出 { "errors": [ { "message": "The type of Query.user must be Output Type but got: undefined.\n\nThe type of Query.user(id:) must be Input Type but got: undefined." } ] }

我第一次做这个Graphql而且我不确定我做错了什么,我看到很多例子,但如果我这样做,我还有很多其他错误 . 我试图从类型中更改InputType,但仍然会发出问题 . server.js

var express = require('express'),

app = express(),

port = process.env.PORT || 4000;

var graphQLHTTP = require('express-graphql');

var schema = require('./schema');

app.use(graphQLHTTP({

schema,

graphiql:true,}))

app.listen(port);

schema.js如下

const {

GrpahQLString,

GrpahQLInt,

GraphQLSchema,

GraphQLInputObjectType,

GraphQLObjectType,

GraphQLOutputType

} = require('graphql');

const fetch = require('node-fetch');

const BASE_URL = 'http://localhost:3000';

const UserType = new GraphQLInputObjectType({

name : 'user',

description : "...",

fields: () => ({

id: {

inputType : GrpahQLInt,

// resolve: (user) => user.id,

},

firstName: {

inputType : GrpahQLString,

// resolve: (user) => user.firstname,

},

lastName: {

inputType : GrpahQLString,

// resolve: (user) => user.lastname,

},

email: {

inputType : GrpahQLString,

// resolve: (user) => user.email,

}

})

});

module.exports = new GraphQLSchema({

query: new GraphQLObjectType({

name : 'Query',

fields: () => ({

user : {

inputType: UserType,

args: {

id: {type: GrpahQLInt}

},

resolve : (root ,args) =>

fetch(`${BASE_URL}/users/${args.id}/`).then(res=>res.json()).then(json=> json.user)

}

})

})

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值