Skip to content

Commit 320145d

Browse files
committed
Ready for basic query
1 parent f7b2cab commit 320145d

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

graphQLApollo/data/_db.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export default books =
2-
[{
1+
const books =
2+
[{
33
"_id": {
44
"$oid": "66e179c074a9720c956c04a1"
55
},
@@ -448,4 +448,6 @@ export default books =
448448
"author": "Carlie Clarey",
449449
"pages": 587,
450450
"price": 1.66
451-
}]
451+
}]
452+
453+
export default { books }

graphQLApollo/index.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@ import { typeDefs } from './schema/schema.js';
88
// data
99
import db from './data/_db.js'
1010

11+
//resolvers
12+
const resolvers = {
13+
Query: {
14+
books() {
15+
return db.books
16+
},
17+
}
18+
}
19+
1120
// The ApolloServer constructor requires two parameters: your schema
1221
// definition and your set of resolvers.
1322
const server = new ApolloServer({
14-
typeDefs,
15-
resolvers,
16-
});
17-
// Passing an ApolloServer instance to the `startStandaloneServer` function:
18-
// 1. creates an Express app
19-
// 2. installs your ApolloServer instance as middleware
20-
// 3. prepares your app to handle incoming requests
21-
const { url } = await startStandaloneServer(server, {
22-
listen: { port: 4000 },
23-
});
24-
25-
console.log(`Server ready at: ${url}`);
26-
23+
typeDefs,
24+
resolvers,
25+
});
26+
// Passing an ApolloServer instance to the `startStandaloneServer` function:
27+
// 1. creates an Express app
28+
// 2. installs your ApolloServer instance as middleware
29+
// 3. prepares your app to handle incoming requests
30+
const { url } = await startStandaloneServer(server, {
31+
listen: { port: 4000 },
32+
});
33+
34+
console.log(`Server ready at: ${url}`);

graphQLApollo/schema/schema.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export const typeDefs = `#graphql
22
type Book {
3-
id: {
4-
ID!
5-
}
3+
id: ID!
64
title: String!
75
author: String
8-
pages: int
9-
price: float
6+
pages: Int
7+
price: Float
8+
}
9+
10+
type Query {
11+
books: [Book]
1012
}
1113
`

0 commit comments

Comments
 (0)