{"size": 884, "ext": "js", "max_stars_repo_path": "ch05-05-graphql/server.js", "max_stars_repo_name": "xiaodongaini/ReactCookbook-source", "max_stars_repo_stars_event_min_datetime": "2020-11-03T21:56:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T02:16:58.000Z", "max_issues_repo_path": "ch05-05-graphql/server.js", "max_issues_repo_name": "xiaodongaini/ReactCookbook-source", "max_issues_repo_issues_event_min_datetime": "2020-09-09T06:50:25.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T05:19:49.000Z", "max_forks_repo_path": "ch05-05-graphql/server.js", "max_forks_repo_name": "xiaodongaini/ReactCookbook-source", "max_forks_repo_forks_event_min_datetime": "2020-12-10T02:05:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T02:24:01.000Z"}
{"max_stars_count": 66, "max_issues_count": 59, "max_forks_count": 27, "avg_line_length": 19.6444444444, "max_line_length": 70, "alphanum_fraction": 0.5837104072}
const { ApolloServer } = require('apollo-server')
const requireText = require('require-text')

const typeDefs = requireText('./schema.graphql', require)

const messages = [
  {
    id: 0,
    author: 'SC',
    text: 'Rolls complete and a pitch is program. One BRAVO.',
  },
  {
    id: 1,
    author: 'PAO',
    text: 'One BRAVO is an abort control model. Altitude is 2 miles.',
  },
  {
    id: 2,
    author: 'CAPCOM',
    text: 'All is well at Houston. You are good at 1 minute.',
  },
]

const resolvers = {
  Query: {
    messages: () => messages,
  },
  Mutation: {
    addMessage: (parent, message) => {
      const item = { id: messages.length + 1, ...message }
      messages.push(item)
      return item
    },
  },
}

const server = new ApolloServer({
  typeDefs,
  resolvers,
})

server.listen({ port: 5000 }).then(({ url }) => {
  console.log(`🚀 Launched at ${url}!`)
})
