Skip to content

Commit 3ec5a8d

Browse files
committed
Added Launchpad instances
1 parent 885c915 commit 3ec5a8d

File tree

9 files changed

+1310
-0
lines changed

9 files changed

+1310
-0
lines changed

launchpad-instances/s1v5.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
# Treehouse - Introduction to GraphQL - Stage 1 - Video 5
3+
4+
```javascript
5+
import { makeExecutableSchema } from "graphql-tools";
6+
7+
const studios = [
8+
{
9+
id: "studio_0",
10+
name: "Paramount",
11+
location: "Hollywood",
12+
movieIds: [
13+
"movie_0",
14+
"movie_1",
15+
"movie_2",
16+
]
17+
},
18+
{
19+
id: "studio_1",
20+
name: "Universal",
21+
location: "Universal City",
22+
movieIds: [
23+
"movie_3",
24+
]
25+
},
26+
];
27+
28+
const movies = [
29+
{
30+
id: "movie_0",
31+
title: "Arachnophobia",
32+
tagline: "Eight legs, two fangs, and an attitude.",
33+
revenue: 53200000,
34+
},
35+
{
36+
id: "movie_1",
37+
title: "Armageddon",
38+
tagline: "Earth. It was fun while it lasted.",
39+
revenue: 553700000,
40+
},
41+
{
42+
id: "movie_2",
43+
title: "Catch Me If You Can",
44+
tagline: "The true story of a real fake.",
45+
revenue: 352100000,
46+
},
47+
{
48+
id: "movie_3",
49+
title: "Christmas Vacation",
50+
tagline: "Yule crack up.",
51+
revenue: 71300000,
52+
},
53+
];
54+
55+
/**
56+
* This typeDefs variable holds our GraphQL Schema. This is the only
57+
* part of this file you need to know about, you can ignore the rest!
58+
*/
59+
const typeDefs = `
60+
type Movie {
61+
id: ID!
62+
title: String!
63+
tagline: String
64+
revenue: Int
65+
studio: Studio
66+
}
67+
68+
type Studio {
69+
id: ID!
70+
name: String!
71+
location: String!
72+
}
73+
74+
type Query {
75+
allMovies: [Movie!]
76+
}
77+
`;
78+
79+
const resolvers = {
80+
Query: {
81+
allMovies: (root, args, context) => {
82+
return movies;
83+
},
84+
},
85+
Movie: {
86+
studio: (root, args, context) => {
87+
return studios.find(studio => {
88+
return studio.movieIds.find(movieId => movieId === root.id);
89+
});
90+
},
91+
}
92+
};
93+
94+
export const schema = makeExecutableSchema({
95+
typeDefs,
96+
resolvers,
97+
});
98+
```

launchpad-instances/s2v2.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
# Treehouse - Introduction to GraphQL - Stage 2 - Video 2
3+
4+
```javascript
5+
import { makeExecutableSchema } from "graphql-tools";
6+
7+
const studios = [
8+
{
9+
id: "studio_0",
10+
name: "Paramount",
11+
location: "Hollywood",
12+
movieIds: [
13+
"movie_0",
14+
"movie_1",
15+
"movie_2",
16+
]
17+
},
18+
{
19+
id: "studio_1",
20+
name: "Universal",
21+
location: "Universal City",
22+
movieIds: [
23+
"movie_3",
24+
]
25+
},
26+
];
27+
28+
const movies = [
29+
{
30+
id: "movie_0",
31+
title: "Arachnophobia",
32+
tagline: "Eight legs, two fangs, and an attitude.",
33+
revenue: 53200000,
34+
},
35+
{
36+
id: "movie_1",
37+
title: "Armageddon",
38+
tagline: "Earth. It was fun while it lasted.",
39+
revenue: 553700000,
40+
},
41+
{
42+
id: "movie_2",
43+
title: "Catch Me If You Can",
44+
tagline: "The true story of a real fake.",
45+
revenue: 352100000,
46+
},
47+
{
48+
id: "movie_3",
49+
title: "Christmas Vacation",
50+
tagline: "Yule crack up.",
51+
revenue: 71300000,
52+
},
53+
];
54+
55+
/**
56+
* This typeDefs variable holds our GraphQL Schema. This is the only
57+
* part of this file you need to know about, you can ignore the rest!
58+
*/
59+
const typeDefs = `
60+
type Movie {
61+
id: ID!
62+
title: String!
63+
tagline: String
64+
revenue: Int
65+
studio: Studio
66+
}
67+
68+
type Studio {
69+
id: ID!
70+
name: String!
71+
location: String!
72+
}
73+
74+
type Query {
75+
allMovies: [Movie!]
76+
topMovieByRevenue: Movie!
77+
}
78+
`;
79+
80+
const resolvers = {
81+
Query: {
82+
allMovies: (root, args, context) => {
83+
return movies;
84+
},
85+
topMovieByRevenue: (root, args, context) => {
86+
const moviesByRevenueDesc = movies.sort((movieA, movieB) => (movieA.revenue < movieB.revenue));
87+
88+
return moviesByRevenueDesc[0];
89+
}
90+
},
91+
Movie: {
92+
studio: (root, args, context) => {
93+
return studios.find(studio => {
94+
return studio.movieIds.find(movieId => movieId === root.id);
95+
});
96+
},
97+
}
98+
};
99+
100+
export const schema = makeExecutableSchema({
101+
typeDefs,
102+
resolvers,
103+
});
104+
```

launchpad-instances/s2v3.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
# Treehouse - Introduction to GraphQL - Stage 2 - Video 3
3+
4+
```javascript
5+
import { makeExecutableSchema } from "graphql-tools";
6+
7+
const studios = [
8+
{
9+
id: "studio_0",
10+
name: "Paramount",
11+
location: "Hollywood",
12+
movieIds: [
13+
"movie_0",
14+
"movie_1",
15+
"movie_2",
16+
]
17+
},
18+
{
19+
id: "studio_1",
20+
name: "Universal",
21+
location: "Universal City",
22+
movieIds: [
23+
"movie_3",
24+
]
25+
},
26+
];
27+
28+
const movies = [
29+
{
30+
id: "movie_0",
31+
title: "Arachnophobia",
32+
tagline: "Eight legs, two fangs, and an attitude.",
33+
revenue: 53200000,
34+
},
35+
{
36+
id: "movie_1",
37+
title: "Armageddon",
38+
tagline: "Earth. It was fun while it lasted.",
39+
revenue: 553700000,
40+
},
41+
{
42+
id: "movie_2",
43+
title: "Catch Me If You Can",
44+
tagline: "The true story of a real fake.",
45+
revenue: 352100000,
46+
},
47+
{
48+
id: "movie_3",
49+
title: "Christmas Vacation",
50+
tagline: "Yule crack up.",
51+
revenue: 71300000,
52+
},
53+
];
54+
55+
/**
56+
* This typeDefs variable holds our GraphQL Schema. This is the only
57+
* part of this file you need to know about, you can ignore the rest!
58+
*/
59+
const typeDefs = `
60+
type Movie {
61+
id: ID!
62+
title: String!
63+
tagline: String
64+
revenue: Int
65+
studio: Studio
66+
}
67+
68+
type Studio {
69+
id: ID!
70+
name: String!
71+
location: String!
72+
}
73+
74+
type Query {
75+
allMovies: [Movie!]
76+
topMovieByRevenue: Movie!
77+
}
78+
`;
79+
80+
const resolvers = {
81+
Query: {
82+
allMovies: (root, args, context) => {
83+
return movies;
84+
},
85+
topMovieByRevenue: (root, args, context) => {
86+
const moviesByRevenueDesc = movies.sort((movieA, movieB) => (movieA.revenue < movieB.revenue));
87+
88+
return moviesByRevenueDesc[0];
89+
}
90+
},
91+
Movie: {
92+
studio: (root, args, context) => {
93+
return studios.find(studio => {
94+
return studio.movieIds.find(movieId => movieId === root.id);
95+
});
96+
},
97+
}
98+
};
99+
100+
export const schema = makeExecutableSchema({
101+
typeDefs,
102+
resolvers,
103+
});
104+
```

0 commit comments

Comments
 (0)