import { ApolloServer , gql , UserInputError } from 'apollo-server-express' ; export interface Book { title : string ; author : string ; } export const database = { books : [ ] , } ; const typeDefs = gql `
  type Query {
    books(first: Int, skip: Int): [Book!]!
  }
  type Book {
    title: String!
    author: String!
  }
  type Mutation {
    createBook(title: String!, author: String!): Book!
  }
` ; const resolvers = { Query : { books : ( parent , { first = 10 , skip = 0 , } ) => { if ( first < 0 ) { throw new UserInputError ( '`first` must be a positive integer' ) ; } return database . books . slice ( skip , skip + first ) ; } , } , Mutation : { createBook ( parent , { title , author } ) { database . books . push ( { title , author } ) ; return database . books [ database . books . length - 1 ] ; } , } , } ; export const apolloServer = new ApolloServer ( { typeDefs , resolvers } ) ;