使用graphQlObjectType的图Ql模式

时间:2018-09-27 05:38:40

标签: node.js express graphql

我是Graph 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类型。 我想以某种方式在书本中找到特定的书(数据目前不来自数据库-仅来自本地数组)

但是我有这个错误 enter image description here

1 个答案:

答案 0 :(得分:2)

GraphQlObjectType is not a constructor出现错字,将其更改为GraphQLObjectType