Skip to content

Instantly share code, notes, and snippets.

@booknara
Created June 2, 2023 20:50
Show Gist options
  • Save booknara/d8e30b6a949207a3d01c4c5b2c8fc9b9 to your computer and use it in GitHub Desktop.
Save booknara/d8e30b6a949207a3d01c4c5b2c8fc9b9 to your computer and use it in GitHub Desktop.
GraphQL practice using node.js with Apollo Server
const { ApolloServer, gql } = require("apollo-server");
const typeDefs = gql`
scalar Date
"""
An object that describes the chracteristics of a ski day
"""
type SkiDay {
"A ski day unique ID"
id: ID!
"The date that a ski day occurred"
date: Date!
mountain: String!
conditions: Conditions
}
enum Conditions {
POWDER
HEAVY
ICY
}
type Query {
totalDays: Int!
allDays: [SkiDay!]!
}
input AddDayInput {
date: Date!
mountain: String!
conditions: Conditions
}
type RemoveDayPayload {
day: SkiDay!
removed: Boolean
totalBefore: Int
totalAfter: Int
}
type Mutation {
addDay(input: AddDayInput!): SkiDay!
removeDay(id: ID!): RemoveDayPayload!
}
type Subscription {
newDay: SkiDay!
}
`;
const resolvers = {
};
const mocks = {
Date: () => "1/2/2025",
// String: () => "Cool Day",
// Query: () => ({
// allDays: () => new MockList(8)
// })
}
const server = new ApolloServer({
typeDefs,
mocks
});
server
.listen()
.then(({ url }) => console.log(`Server running at ${url}`)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment