如何解决无法使用 @graphql-tools/merge
从 app.js
文件开始:
import { Server } from "./src/Server";
import { config } from "dotenv";
config();
Server.StartServer();
下面是引导 apollo-server-express 的 Server.ts
文件
import express from "express";
import http from "http";
import { ApolloServer } from "apollo-server-express";
import { GraphQLServerOptions } from "apollo-server-core/src/graphqlOptions";
import { schema } from "./graphql/index";
export class Server {
public static StartServer() {
const app: express.Application = express();
const server = new ApolloServer({
schema,graphiql: true,} as unknown as GraphQLServerOptions);
server.applyMiddleware({ app });
const httpServer = http.createServer(app);
server.installSubscriptionHandlers(httpServer);
httpServer.listen(process.env.PORT,function () {
console.log(`server is running on port ${process.env.PORT}`);
});
}
}
这是我的解析器在此处放置的 user.resolvers.ts
文件:
import { IResolvers } from "graphql-tools";
export const resolver: IResolvers = {
Mutation: {
register: function (parent,args,content,info) {
console.log(parent);
},},Query: {
getUser: function (parent,};
这里我们使用 user.schema.ts
文件中的 typeDef:
import { gql } from "apollo-server-express";
export const typeDef = gql`
type User {
username: String
password: String
}
type Mutation {
register(input: {username: String!,passwprd: String!})
}
type Query {
getUSer(username): User
}
`;
最后在 ./src/graphql/index.ts
文件中,我正在那里为解析器和 typeDefs 进行合并,我正在制作可执行架构以将其添加到 ApolloServer 配置对象,但我面临以下错误:
任何想法和建议将不胜感激。提前感谢贡献者:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。