I'm setting up a GraphQL api and am getting a null value when the request goes through my dataSources function. When I return the data directly from the resolver it works, but when I go through the dataSources, it does not.
Here is my graphql.js
file:
const typeDefs = gql`
type Query {
tours: Tour
tour(id: ID!): Tour
}
type Tour {
id: String
name: String
href: String
}
`;
const resolvers = {
Query: {
tours: (_, __, { dataSources }) => {
dataSources.ToursAPI.getAllTours();
}
}
};
Here is my tours.js
file which contains my dataSources (which is simplified to simply return an object that mirrors my schema). The console.log is just to ensure that the function is firing, and it is indeed firing.
async getAllTours() {
const tourObject = {
id: "ID",
name: "NAME",
href: "HREF"
};
console.log(tourObject);
return tourObject;
};
When I return the exact same object directly in the resolver, it works, but when I go through the dataSource function, it returns null. I know the function is firing because the console.log fires on my terminal. So somehow the data is getting lost between the getAllTours function and the resolver, but I can't figure out why.