this.findOneById is not a function (Apollo Server Express v4 GraphQL)
See original GitHub issueI have the following ApolloServer (v4)
import { MongoDataSource } from 'apollo-datasource-mongodb'
export default class LoaderAsset extends MongoDataSource {
async getAsset(assetId) {
return this.findOneById(assetId) // ERROR IS HERE
}
}
async function startApolloServer(app) {
const httpServer = http.createServer(app);
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })]
});
await server.start();
app.use(
'/graphql',
cors(),
bodyParser.json(),
expressMiddleware(server, {
context: async ({ req }) => {
return {
dataSources: {
loaderAsset: new LoaderAsset(modelAsset),
}
}
},
}),
);
const port = config.get('Port') || 8081;
await new Promise(resolve => httpServer.listen({ port }, resolve));
}
when I run graphql and send one assetId, everything is working till I get following error:
this.findOneById is not a function
By the way (this.) has collection and model objects but not any methods.
is it because apollo-datasource-mongodb is not compatible with the new version of apollo server v4?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Apollo Server Express v4 GraphQL this.findOneById is not a ...
when I run graphql and send one assetId, everything is working till I get following error: this.findOneById is not a function By the...
Read more >Issues · GraphQLGuide/apollo-datasource-mongodb - GitHub
Contribute to GraphQLGuide/apollo-datasource-mongodb development by creating an account ... findOneById is not a function (Apollo Server Express v4 GraphQL).
Read more >Using Express with GraphQL – How to create a GraphQL ...
One of the fastest ways to get up and running with GraphQL is to install Apollo Server as middleware on your new or...
Read more >Graphql-typegraphql example to apollo/server/express4 - help
Hello, I wanted to change the example code in src/index.ts to use apollo/server/express4 in prisma-examples/typescript/graphql-typegraphql ...
Read more >create-graphql-server-query-arguments - npm package | Snyk
Learn more about create-graphql-server-query-arguments: package health ... apollo-server-express ... findOneById(id, me, 'pubsub {{typeName}}Inserted'); ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
what i did is i override my datasource class so I can call the initialize method inside in the MongoDatasource class. Now it works for me.
then in my context
I believed its not undefined because that attribute belongs to MongoDataSource class which we use to extend our own Datasource class. sorry for the late response.