I'm using apollo-server-express to create backend apis with GraphQL
Now, I want to Write GraphQL Schema in a separate file. e.g. "schema.graphql", So when I put the same code as I wrote in Template String before. into the "schema.graphql" My application is crashed with below error:
Unable to find any GraphQL type definitions for the following pointers
(source: googleapis.com)
Here is my code :
server.js
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
const { importSchema } = require('graphql-import');
const fs = require('fs');
const path = '/graphql';
const apolloServer = new ApolloServer({
typeDefs: importSchema('./greet.graphql'),
resolvers: require('./graphql/resolver'),
});
const app = express();
apolloServer.applyMiddleware({ app, path });
app.listen(8080, () => {
console.log('Server Hosted');
});
greet.graphql
type Query {
greeting: String
}
resolver.js
const Query = {
greeting: () => 'Hello World From NightDevs',
};
module.exports = { Query };
Not only this, but Ive tried this solution also - Stackoverflow Solution
But This doesn't work at all