Javascript Apollo Express GraphQL中获取错误:错误:架构必须包含唯一命名的类型,但包含多个名为“的类型”;日期时间“;
我试图使用Javascript Apollo Express GraphQL中获取错误:错误:架构必须包含唯一命名的类型,但包含多个名为“的类型”;日期时间“;,javascript,node.js,express,graphql,apollo-server,Javascript,Node.js,Express,Graphql,Apollo Server,我试图使用从“graphql中间件”导入{applyMiddleware}库以在变异的输入上添加验证中间件 因此,我创建了一个示例中间件函数,它是日志输入 export const logInput=async(解析、根、参数、上下文、信息)=>{ log(`1.logInput:${JSON.stringify(args)}`); const result=等待解析(根、参数、上下文、信息); console.log(`5.logInput`); 返回结果; }; 现在我根据graphql中
从“graphql中间件”导入{applyMiddleware}代码>库以在变异的输入上添加验证中间件
因此,我创建了一个示例中间件函数,它是日志输入
export const logInput=async(解析、根、参数、上下文、信息)=>{
log(`1.logInput:${JSON.stringify(args)}`);
const result=等待解析(根、参数、上下文、信息);
console.log(`5.logInput`);
返回结果;
};
现在我根据graphql中间件
的文档,将现有的模式
和中间件
传递给graphql中间件
库提供的applyMiddleware()
graphql/index.js
文件包含:因此该文件包含组合所有模式
、类型
和解析器的代码
import{gql,makeExecutableSchema}来自'apollo server express';
从“lodash”导入{merge};
从“graphql类型json”导入{GraphQLJSONObject};
从“graphql iso日期”导入{GraphQLDateTime};
从“/policy”导入{policyType,policysolver,policySchema};
进口{
gitProviderTypes,
gitProviderResolver,
gitProviderSchema,
}来自“/gitProvider”;
常量根=gql`
标量JSON
标量JSONObject
标量GraphQLDateTime
类型MyType{
myValue:JSON
myObject:JSONObject
myDate:GraphQLDateTime
}
类型查询{
_空:字符串
}
类型突变{
_空:字符串
}
模式{
查询:查询
突变:突变
}
`;
常量解析程序=合并(
{JSONObject:GraphQLJSONObject,GraphQLDateTime},
策略解析器,
gitProviderResolver
);
导出默认makeExecutableSchema({
typeDefs:[
根,
保单类型,
政策模式,
gitProviderTypes,
gitProviderSchema,
],
解析器,
});
包含所有类型的示例文件
,有许多文件要处理其他资源
从'apollo server express'导入{gql};
导出默认gql`
输入CreatePolicyResult{
id:字符串
名称:String
采用:布尔型
降价:字符串
}
类型CreateProcedureResult{
id:字符串
类型:字符串
名称:String
文件:字符串
提供者:字符串
采用:布尔型
摘要:字符串
指南:字符串
适用:布尔值
}
类型策略{
_id:id
id:字符串
名称:String
采用:布尔型
标签:[字符串]
程序:[程序]
降价:字符串
html:String
文件:字符串
}
类型程序{
_id:id
id:字符串
类型:字符串
名称:String
摘要:字符串
适用:字符串
提供者:字符串
指南:字符串
通过:字符串
标签:[字符串!]
降价:字符串
html:String
文件:字符串
}
输入程序输入{
id:字符串
类型:字符串
名称:String
摘要:字符串
适用:布尔值
提供者:字符串
指南:字符串
采用:布尔型
标签:[字符串]
降价:字符串
}
输入CreateProcedureInput{
id:字符串!
类型:字符串!
名字:字符串!
降价:绳子!
提供者:字符串!
采纳:布尔!
摘要:字符串
指南:字符串
适用:布尔型!
}
输入策略输入{
id:字符串!
名字:字符串!
采纳:布尔!
降价:绳子!
}
输入更新策略输入{
id:字符串
名称:String
采用:布尔型
标签:[字符串]
降价:字符串
}
输入组织输入{
companyFullName:String!
公司名称:字符串!
CompanyMailDomain:字符串!
companyWebsiteURL:字符串!
securityOfficerName:字符串!
securityofficemail:String!
ctoName:字符串!
电子邮件:字符串!
sourceControl:String!
票务系统:字符串!
ciSystem:字符串!
privacyPolicyURL:字符串!
supportBYODandMDM:布尔值!
}
`;
express.js
文件包含:
从'apollo server express'导入{ApolloServer};
从“graphql中间件”导入{applyMiddleware};
从“/graphql”导入架构;
从“./graphql/middleware”导入{logInput};
const schemaWithMiddleware=applyMiddleware(模式,登录输入);
//在这里,模式是从文件导入的,logInput是中间件
//GraphQL服务器
const server=新服务器({
模式,
上下文:异步({req,res})=>({req,res}),
});
每当我尝试将schema
与applyMiddleware()
一起使用时,当我尝试像这样直接使用它时抛出错误,它就可以正常工作
从'apollo server express'导入{ApolloServer};
从“graphql中间件”导入{applyMiddleware};
从“/graphql”导入架构;
从“./graphql/middleware”导入{logInput};
//这次不用了,现在没问题了
//const schemaWithMiddleware=applyMiddleware(模式,登录输入);
//GraphQL服务器
const server=新服务器({
schema:schema,
上下文:异步({req,res})=>({req,res}),
});
错误抛出:
node:14152) UnhandledPromiseRejectionWarning: Error: Schema must contain uniquely named types but contains multiple types named "DateTime".
at new GraphQLSchema (G:\nanoheal\tego\policy-builder-service\node_modules\graphql\type\schema.js:194:15)
at Object.mapSchema (G:\nanoheal\tego\policy-builder-service\dist\utils\src\mapSchema.js:31:12)
at createNewSchemaWithResolvers (G:\nanoheal\tego\policy-builder-service\dist\schema\src\addResolversToSchema.js:200:14)
at Object.addResolversToSchema (G:\nanoheal\tego\policy-builder-service\dist\schema\src\addResolversToSchema.js:87:11)
at addMiddlewareToSchema (G:\nanoheal\tego\policy-builder-service\node_modules\graphql-middleware\src\middleware.ts:42:21)
at normalisedMiddlewares.reduceRight.schema.schema (G:\nanoheal\tego\policy-builder-service\node_modules\graphql-middleware\src\middleware.ts:91:11)
at Array.reduceRight (<anonymous>)
at applyMiddlewareWithOptions (G:\nanoheal\tego\policy-builder-service\node_modules\graphql-middleware\src\middleware.ts:80:77)
at Object.applyMiddleware (G:\nanoheal\tego\policy-builder-service\node_modules\graphql-middleware\src\middleware.ts:132:10)
at Object.exports.default (G:\nanoheal\tego\policy-builder-service\src\loaders\express.ts:28:34)
at Object.exports.default (G:\nanoheal\tego\policy-builder-service\src\loaders\index.ts:14:24)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at startServer (G:\nanoheal\tego\policy-builder-service\src\server.ts:16:5)
(node:14152) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:14152) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
节点:14152)未处理的PromisejectionWarning:错误:架构必须包含唯一命名的类型,但包含多个名为“DateTime”的类型。
在新的GraphQLSchema(G:\nanoheal\tego\policy builder service\node\u modules\graphql\type\schema.js:194:15)
位于Object.mapSchema(G:\nanoheal\tego\policy builder service\dist\utils\src\mapSchema.js:31:12)