schema.js
const { graphql } = require("graphql");
const _ = require('lodash');
const { GraphQLSchema, GraphQLObjectType, GraphQLString } = graphql;
var books = [
{name: 'Wind',genre:'Fantasy',id:'1'},
{name: 'Final',genre:'Fantasy',id:'2'},
{name: 'Long',genre:'Sci-Fi',id:'3'},
];
const BookType = new GraphQLObjectType({
name: 'Book',
fields: ()=>({
id: {type:GraphQLString},
name: {type:GraphQLString},
genre: {type: GraphQLString}
})
});
const BookType = new GraphQLObjectType({ ^
TypeError:GraphQLObjectType不是构造函数
2条答案
按热度按时间oalqel3c1#
你的graphql import语句应该是:
xoefb8l82#
我相信你的错误是试图将字段作为函数传递,而不是类型定义中的对象。
试试这个