aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-01-19 16:32:06 -0300
committerEuAndreh <eu@euandre.org>2021-01-19 16:32:06 -0300
commite6174d4bf0cdb7ea42780c7e602c3d0d90f9d748 (patch)
treecd64b47b66ea7e3da5c78081121b4b4704c6ce64
parent9b8dc139521ec1445622a2ee3051e12e0ff84bd3 (diff)
downloadapollo-server-demo-e6174d4bf0cdb7ea42780c7e602c3d0d90f9d748.tar.gz
Polish first sequence of steps; add README.md
-rw-r--r--README.md13
-rw-r--r--src/00.js4
-rw-r--r--src/02.js6
-rw-r--r--src/04.js28
4 files changed, 47 insertions, 4 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b9458ed
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+# apollo-server-demo
+
+Step-by-step tutorial building an Apollo GraphQL server.
+
+Install the dependencies with:
+```shell
+$ npm ci
+```
+
+Start the first step with:
+```shell
+$ node src/00.js
+```
diff --git a/src/00.js b/src/00.js
index 9b7e445..26cd087 100644
--- a/src/00.js
+++ b/src/00.js
@@ -20,5 +20,7 @@ ${schema}
What is the curl command to query it?
The expected response is:
- {"data":{"hello":null}}`);
+ {"data":{"hello":null}}
+
+After getting the correct response, move to the next sequential file.`);
});
diff --git a/src/02.js b/src/02.js
index c1f9edb..2cef3de 100644
--- a/src/02.js
+++ b/src/02.js
@@ -27,7 +27,7 @@ server.listen().then(({ url }) => {
We have a new schema:
${schema}
Let's query the new field.
-Where does the value of the new field comes from?
-It isn't null, neither added to the resolvers.
-Also, what happened to the value of the "hello" field?`);
+1. Where does the value of the new field comes from?
+ It isn't null, neither added to the resolvers.
+2. Also, what happened to the value of the "hello" field?`);
});
diff --git a/src/04.js b/src/04.js
new file mode 100644
index 0000000..35fbe6f
--- /dev/null
+++ b/src/04.js
@@ -0,0 +1,28 @@
+const { ApolloServer, gql } = require('apollo-server');
+
+const schema = `
+ type Query {
+ hello: String
+ goodbye: String
+ }
+`;
+
+const typeDefs = gql(schema);
+
+const resolvers = {
+ Query: () => ({
+ hello: () => "hi",
+ }),
+};
+
+const server = new ApolloServer({
+ typeDefs,
+ mocks: resolvers,
+});
+
+server.listen().then(({ url }) => {
+ console.log(`Listening on ${url}
+
+woeifjw
+`);
+});