我正在使用apollo-server-express
prisma 数据库运行我的 GraphQL 服务器。下面列出了我的主要架构,它仅用于graphql-tag/loader
导入其他.graphql
文件。当我尝试在本地运行我的服务器时,我收到以下消息:
错误:模块构建失败(来自 ./node_modules/graphql-tag/loader.js):GraphQLError:语法错误:意外
显然,GraphQL 想要schema/schema.graphql
声明一些类型等。有没有办法解决这个问题,以便我可以拥有一个.graphql
文件,它所做的只是导入其他.graphql
文件?
架构/schema.graphql:
#import '../generated/prisma.graphql'
#import './secondSchema.graphql'
index.js:
import http from 'http';
import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import resolvers from './schema/resolvers';
import schema from './schema/schema.graphql';
import prisma from './prisma';
const server = new ApolloServer({
context: {
prisma,
},
resolvers,
typeDefs: schema,
});
const app = express();
server.applyMiddleware({ app });
const PORT = 5000;
const httpServer = http.createServer(app);
server.installSubscriptionHandlers(httpServer);
httpServer.listen(PORT, () => {
console.log(`Server ready at http://localhost:${PORT}${server.graphqlPath}`);
console.log(`Subscriptions ready at ws://localhost:${PORT}${server.subscriptionsPath}`);
});
if (module.hot) {
module.hot.accept();
module.hot.dispose(() => server.stop());
}