如何解决如何解决无效的插件选项...[1]注册是必需的错误?
我正尝试通过graphql插件运行Hapi,如下所示。
index.js
const Hapi = require('hapi');
const mongoose = require('mongoose');
const {
graphqlHapi,graphiqlHapi,} = require('apollo-server-hapi');
const schema = require('./graphql/schema');
const HOST = 'localhost';
const PORT = 3000;
const StartServer = async () => {
const server = new Hapi.server({
port: PORT,host: HOST,});
server.route({
method: 'GET',path: '/',handler: (request,h) => {
return 'Hello World!';
},});
await server.register([
{
plugin: graphqlHapi,options: {
path: '/graphql',graphqlOptions: { schema },route: { cors: true },},{
plugin: graphiqlHapi,options: {
path: '/graphiql',graphiqlOptions: { 'endpointURL': '/graphql' },]).catch((e) => console.log(e));
try {
await server.start();
}
catch (err) {
console.log(`Error while starting server: ${ err.message }`);
}
console.log(`Server running at: ${ server.info.uri }`);
};
StartServer();
schema.js
const graphql = require('graphql');
const UserType = require('./UserType');
const {
GraphQLObjectType,GraphQLString,GraphQLSchema,} = graphql;
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',fields: {
user: {
type: UserType,args: { id: { type: GraphQLString } },resolve(parent,args) {
return { test: true };
},});
module.exports = new GraphQLSchema({ query: RootQuery });
UserType.js
const graphql = require('graphql');
const {
GraphQLObjectType,GraphQLNumber,} = graphql;
const UserType = new GraphQLObjectType({
name: 'User',fields: () => ({
id: { type: GraphQLString },name: { type: GraphQLString },joinDate: { type: GraphQLNumber },lastLoginDate: { type: GraphQLNumber },}),});
module.exports = UserType;
Error: Invalid plugin options {
"plugin": {
"options": {
"path": "/graphql","graphqlOptions": {
"schema": {
"_queryType": "RootQueryType","_directives": [
"@include","@skip","@deprecated","@specifiedBy"
],"_typeMap": {
"RootQueryType": "RootQueryType","User": "User","String": "String","Boolean": "Boolean","__Schema": "__Schema","__Type": "__Type","__TypeKind": "__TypeKind","__Field": "__Field","__InputValue": "__InputValue","__EnumValue": "__EnumValue","__Directive": "__Directive","__DirectiveLocation": "__DirectiveLocation"
},"_subTypeMap": {},"_implementationsMap": {}
}
},"route": {
"cors": true
}
},"register" [1]: -- missing --
}
}
[1] "register" is required
at Object.exports.apply (C:\Users\aironsid\Documents\tatooify\node_modules\hapi\lib\config.js:19:15)
at internals.Server.register (C:\Users\aironsid\Documents\tatooify\node_modules\hapi\lib\server.js:412:31)
at StartServer (C:\Users\aironsid\Documents\tatooify\server\index.js:27:16)
at Object.<anonymous> (C:\Users\aironsid\Documents\tatooify\server\index.js:56:1)
at Module._compile (internal/modules/cjs/loader.js:1075:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1096:10)
at Module.load (internal/modules/cjs/loader.js:940:32)
at Function.Module._load (internal/modules/cjs/loader.js:781:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
为了使事情变得更有趣,服务器启动了,我可以得到Hello world
的响应。知道我搞砸了吗?我试图遵循this教程
我的package.json依赖项
"dependencies": {
"@hapi/eslint-config-hapi": "^13.0.2","@hapi/eslint-plugin-hapi": "^4.3.5","@hapi/hapi": "^20.0.0","@hapi/lab": "^23.0.0","apollo-server-hapi": "^2.17.0","graphql": "^15.3.0","mongoose": "^5.10.4"
},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。