Hey! I’ve been playing around with Apollo GraphQL for couple of days now and it’s been great!
Today I started to fetch some data from a public event REST API. I’ve been successful at fetching / using some REST APIs previously while going through tutorials, but right now that I’ve started working on my own little thing, I feel like I’m a little stuck. Can anyone tell me why I’m getting INTERNAL_SERVER_ERROR
errors and Expected Iterable, but did not find one for field \"Query.listEvents\
messages?
I assume there’s something wrong with my Schema and/or Resolver.
index.js
const { ApolloServer } = require('apollo-server');
const typeDefs = require('./schema');
const resolvers = require('./resolvers');
const EventAPI = require('./datasources/events');
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => {
return {
eventsAPI: new EventAPI(),
};
},
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
datasources: events.js
class EventAPI extends RESTDataSource {
constructor() {
super();
this.baseURL = 'https://api.turku.fi/linkedevents/v1/';
}
getEvents() {
return this.get('event');
}
}
resolvers.js
const resolvers = {
Query: {
listEvents: (_, __, { dataSources }) => {
return dataSources.eventsAPI.getEvents();
},
},
};
schema.js
const typeDefs = gql`
type Query {
listEvents: [Event!]!
}
type Event {
id: ID!
event_status: String!
start_time: String!
end_time: String!
info_url: String
}
`;
Thank you for your time