我是图Ql。的初学者,但我试图创建一个带有节点的grapghql服务器并表示如下...

const graphql = require('graphql');
const _ = require('lodash')
const { GraphQlObjectType, GraphQLString,GraphQLSchema,buildSchema } =
    graphql;
var books=[
    {name:'Hezaro yek Shab',gener:'romans',id:1},
    {name:'Fergosen memorizes',gener:'sport',id:2},
    {name:'Hpliday physics',gener:'sience',id:3}
];

const BookType = new GraphQlObjectType({
    name: 'Book',
    fields: () => ({
        id: { type: GraphQLString },
        title: { type: GraphQLString },
        gener: { type: GraphQLString }
    })
});

const RootQuery=new GraphQlObjectType({
    name:'RootQueryType',
    fields:{
        book:{
            type:BookType,
            args:{ id: { type: GraphQLString }},
            resolve(parent,args){
               return _.find(books,{id:args.id});
            }
        }
    },

});
module.exports=new GraphQLSchema({
    query:RootQuery
});


我使用GraphQlObjectType为书籍和Root Query创建架构,然后将书籍类型也传递给Root Query类型。
我想以某种方式在书本数组中查找特定书本(数据此时不来自数据库-仅来自本地数组)

但是我有这个错误
node.js - 使用graphQlObjectType的图Ql模式-LMLPHP

最佳答案

由于输入错误而导致的GraphQlObjectType is not a constructor错误,请将其更改为GraphQLObjectType

07-28 09:22