Skip to content

Commit 8981f7c

Browse files
committed
Add reviews Query and createReview Mutation
1 parent 18b1d5e commit 8981f7c

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

β€Žsrc/index.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
11
import { ApolloServer, gql } from 'apollo-server'
22

3+
const reviews = [
4+
{
5+
text: 'Super-duper book.',
6+
stars: 5
7+
}
8+
]
9+
310
const server = new ApolloServer({
411
typeDefs: gql`
512
type Query {
613
hello: String!
14+
reviews: [Review!]!
15+
}
16+
type Review {
17+
text: String!
18+
stars: Int
19+
fullReview: String!
20+
}
21+
type Mutation {
22+
createReview(review: CreateReviewInput!): Review
23+
}
24+
input CreateReviewInput {
25+
text: String!
26+
stars: Int
727
}
828
`,
929
resolvers: {
1030
Query: {
11-
hello: () => '🌍🌏🌎'
31+
hello: () => '🌍🌏🌎',
32+
reviews: () => reviews
33+
},
34+
Review: {
35+
fullReview: review =>
36+
`Someone on the internet gave ${review.stars} stars, saying: "${
37+
review.text
38+
}"`
39+
},
40+
Mutation: {
41+
createReview: (_, { review }) => {
42+
reviews.push(review)
43+
return review
44+
}
1245
}
1346
}
1447
})

0 commit comments

Comments
Β (0)