Reputation: 204
i am beginner in Graph Ql.but i am trying to create a grapghql server with node and express as follow...
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
});
i used GraphQlObjectType to create schema for book and for Root Query and then passed book type into Root Query type as well . any way i want to find particular book in array of books (data dont come from database at this time -just from local array)
Upvotes: 1
Views: 1224
Reputation: 3936
The GraphQlObjectType is not a constructor
error because of a typo, change it to GraphQLObjectType.
Upvotes: 4