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