I am using apollo-server-express
to run my GraphQL server with a prisma database. My main schema is listed below, which just uses graphql-tag/loader
to import other .graphql
files. When I try to run my server locally, I get the following message:
Error: Module build failed (from ./node_modules/graphql-tag/loader.js): GraphQLError: Syntax Error: Unexpected
Clearly, GraphQL wants schema/schema.graphql
to declare some types, etc. Is there a way I can get around this so that I can have a .graphql
file that all it does is import other .graphql
files?
schema/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());
}
You can add a "dummy" or placeholder type that's not actually used anywhere so that the parser doesn't complain. However, the simpler fix would be to stop importing the other type definition files into one file and just pass all of them to typeDefs
as an array.
const server = new ApolloServer({
context: {
prisma,
},
resolvers,
typeDefs: [prismaTypeDefs, someOtherTypeDefs],
});