'How to use feathers with graphql?
I want to build graphql in feathers. And try below method。
from index.js
/* eslint-disable no-console */
const logger = require('./logger');
const app = require('./app');
const port = app.get('port');
const { ApolloServer } = require('apollo-server-express');
const { typeDefs } = require('../schema')
const { resolvers } = require('../resolvers')
let apolloServer = null;
async function startServer() {
apolloServer = new ApolloServer({
typeDefs,
resolvers
});
await apolloServer.start();
apolloServer.applyMiddleware({ app });
}
startServer();
const server = app.listen(port);
process.on('unhandledRejection', (reason, p) =>
logger.error('Unhandled Rejection at: Promise ', p, reason)
);
server.on('listening', () =>
logger.info('Feathers application started on http://%s:%d', app.get('host'), port)
);
This code refer "apollo-server-express" example and take it to feathers.
but get info: Page not found {"className":"not-found","code":404,"data":{"url":"/graphql"},"errors":{},"name":"NotFound","type":"FeathersError"}
i think this error is not match feather route,and also create a service to try solve it.
from service-graphql
const { ApolloServer } = require('apollo-server-express');
const { typeDefs } = require('../../../schema')
const { resolvers } = require('../../../resolvers')
module.exports = async function (app) {
// const options = {
// paginate: app.get('paginate')
// };
let apolloServer = null;
async function startServer() {
apolloServer = new ApolloServer({
typeDefs,
resolvers
});
await apolloServer.start();
apolloServer.applyMiddleware({ app });
}
// startServer();
// Initialize our service with any options it requires
app.use('/graphql', await startServer);
// Get our initialized service so that we can register hooks
// const service = app.service('graphql');
// service.hooks(hooks);
};
But it also fail. How can i build a base feathers and graphql project. This is my full code https://github.com/CoreyHuang/baseFeathers
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|