When extending Apollo Server's DataSources
we have to create an initialize method, inside the class :
initialize(config){
this.context=config.context
}
Yet I cannot clearly define a mental model when it comes to the relationship between the class extension of DataSources and context.As seen in the GitHub repo of Apollo , the way to access the methods of your custom data source is by destructuring dataSource , like this:
getRandomData: (parent,args,{dataSource})=>{
return dataSources.randomMethod()
}
Yet , how do we pass the context to Apollo Server? I thought something like this :
const server= new ApolloServer({
typeDefs,
schema,
context,
dataSources:()=>({...})
}
But if it were like this , {dataSources}
destructuring does not make sense in the resolvers , so what exactly is the relationship between dataSources and context? Thank you !