How should I modify this code to make Neo4j one of the "datasources" of the ApolloServer instance like this example from the docs: Data sources - Apollo GraphQL Docs
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => {
return {
moviesAPI: new MoviesAPI(),
personalizationAPI: new PersonalizationAPI(),
};
},
});
It looks to me that the current code does use the schema generated from neoSchema.getSchema(), and passes it to the ApolloServer, which is what you should do.
Hi @michael.webb, thanks for responding so quickly. To clarify, how should I modify this code to make Neo4j one of the "datasources" of the ApolloServer instance like this example from the docs? Data sources - Apollo GraphQL Docs
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => {
return {
moviesAPI: new MoviesAPI(),
personalizationAPI: new PersonalizationAPI(),
};
},
});
I'm not super familiar with Apollo Server datasources, but from what I can tell, I don't believe we ever supported this. It also seems that datasources is a deprecated method of using the ApolloServer.
The Neo4j graphql library generates the graphql schema which you pass directly into the ApolloServer constructor. The graphql requests sent to the Apollo Server endpoint would then be translated by the library into Cypher and on to the Neo4j database.
Is there a particular need for you to use datasources?
My apologies - I accidentally referenced the old docs. The new docs also references using dataSources.
To your question - My use case is that I'm adding another data source (OracleDB) to my Express.js application, and using dataSources seems to be the only approach that I can think of.
It looks like I'm unable to share any more links. When I try, I get an error message. Could you try this and replace the "(dot)"? Thanks again, Michael. https://www.apollographql (dot) com/docs/apollo-server/data/fetching-rest/#adding-data-sources-to-your-servers-context-function
I think that if you want to integrate a Neo4j database with other data sources in your GraphQL API, you'd typically implement this within the resolvers. With a resolver can call out to different data sources.
This could involve using the Neo4j GraphQL library for parts of your schema that interact with Neo4j, and using custom resolvers or another library for parts of your schema that interact with other data sources.