Skip to content

Commit 9b2cf74

Browse files
committed
init
1 parent b785581 commit 9b2cf74

9 files changed

+452
-241
lines changed

README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Intro to GraphQL
2+
> Scott Moss & Frontend Masters
3+
4+
## Resources
5+
* [Slides](https://slides.com/scotups/intro-to-graphql)
6+
* [Nodejs](https://nodejs.org/en/)
7+
* [MongoDB](https://www.mongodb.com/)
8+
* [Apollo](https://www.apollographql.com/docs/apollo-server/)
9+
* [GraphQL](https://graphql.org/)
10+
11+
## Course
12+
This course has two parts, slides and excercises. The slides describe the excerices in detail. Each excercise has a starting branch and solution branch. Example `lesson-1` and `lesson-1-solution`.
13+
## Excercises
14+
### Hello world GraphQL server with Apollo Server
15+
* branch - `lesson-1`
16+
17+
In this lesson you'll be creating a simple GraphQL server using Apollo Server.
18+
- [ ] install dependencies with yarn (prefered for version locking) or npm
19+
- [ ] create a schema with at least one Type
20+
- [ ] create a query from that Type
21+
- [ ] create a mutation for that Type
22+
- [ ] create mock resolvers for query and mutation
23+
- [ ] start the server
24+
- [ ] using GraphQL playground, perform query and mutation
25+
26+
### Creating Schema with SDL
27+
* branch - `lesson-2`
28+
* test command - `yarn test-schema` or `npm run test-schema`
29+
30+
This exercise will have you creating a GraphQL Schema based on the the mongoose models already created
31+
- [ ] create Type for product
32+
- [ ] create enums for product
33+
- [ ] create inputs for product
34+
- [ ] create queries for product
35+
- [ ] create mutations for product
36+
- [ ] ensure all tests pass by running test command
37+
38+
### Resolving Queries and Mutations
39+
* branch - `lesson-3`
40+
* test command - `yarn test-resolvers` or `npm run test-resolvers`
41+
42+
In this exercise, you'll be creating resolvers for the Queries and Mutations on the product type. You'll be using Mongoose models to perform CRUD in your resolvers.
43+
44+
- [ ] create resolvers for product queries
45+
- [ ] create resolvers for product mutations
46+
- [ ] create resolvers for prouduct createdBy field
47+
- [ ] ensure all tests pass by running test command
48+
49+
### Interfaces and Unions
50+
* branch - `lesson-4`
51+
* test command - `yarn test-interfaces` or `npm run test-interfaces`
52+
53+
Now that you know about schemas and resolvers, we need to make some changes. Our product model in mongoose is split between 3 different product types. We need to make the product type an interface and then create types for each possible type in our mongoose model. Don't forget to create resolver to resolve the type.
54+
55+
- [ ] change product type to an interface
56+
- [ ] create Bike type that implements product
57+
- [ ] create GamingPc type that implements product
58+
- [ ] create Drone type that implements product
59+
- [ ] create resolver for product interface that resolves the type
60+
- [ ] ensure all tests pass by running test command
61+
62+
### Authentication
63+
* branch - `lesson-5`
64+
* test command - `yarn test-auth` or `npm run test-auth`
65+
66+
There are many many ways to authenticate with GraphQL. Our API is a public API, so we'll use API keys. Some queries need authentication, and some queries also need the correct role. Authenticate the request and update the product resolvers!
67+
68+
- [ ] authenticate the request and add use to context
69+
- [ ] block all product queries and mutations if no user
70+
- [ ] block all product mutations if not an admin role
71+
- [ ] ensure all tests pass by running test command
72+
73+
### Testing
74+
The other types don't have any test, go ahead and write some!

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"license": "MIT",
66
"scripts": {
77
"build": "babel src --out-dir dist",
8-
"test": "NODE_ENV=testing jest --forceExit --detectOpenHandles --verbose false",
8+
"test": "cross-env NODE_ENV=testing jest --forceExit --detectOpenHandles --silent",
9+
"test-schema": "GQL_LESSON=lesson-2 npm test -- -t lesson-2",
10+
"test-resolvers": "npm test -- -t lesson-3",
11+
"test-interfaces": "cross-env npm test -- -t lesson-4",
12+
"test-auth": "npm test -- -t lesson-5",
913
"dev": "nodemon --exec yarn restart",
1014
"restart": "rimraf dist && yarn build && yarn start",
1115
"start": "node dist/index.js"
@@ -19,6 +23,7 @@
1923
"babel-core": "7.0.0-bridge.0",
2024
"babel-eslint": "^8.2.1",
2125
"babel-jest": "^23.4.2",
26+
"cross-env": "^5.2.0",
2227
"eslint": "^4.15.0",
2328
"eslint-config-prettier": "^2.9.0",
2429
"eslint-config-standard": "^11.0.0",

src/__tests__/schema.spec.js

-149
This file was deleted.

0 commit comments

Comments
 (0)