Skip to content

Commit 4ffe2e2

Browse files
authored
Getting started tweaks to make Trevor feedback (#6779)
1 parent bce9150 commit 4ffe2e2

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

docs/source/getting-started.mdx

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: Get started with Apollo Server
3-
description: ""
3+
description: ''
44
---
55

66
This tutorial helps you:
77

8-
* Obtain a basic understanding of GraphQL principles
9-
* Define a GraphQL **schema** that represents the structure of your data set
10-
* Run an instance of Apollo Server that lets you execute queries against your schema
8+
- Obtain a basic understanding of GraphQL principles
9+
- Define a GraphQL **schema** that represents the structure of your data set
10+
- Run an instance of Apollo Server that lets you execute queries against your schema
1111

1212
This tutorial assumes that you are familiar with the command line and
1313
JavaScript and have installed a recent Node.js (14+) version. Additionally, for those interested, this tutorial includes an optional section describing how to set up Apollo Server with TypeScript.
@@ -16,24 +16,26 @@ JavaScript and have installed a recent Node.js (14+) version. Additionally, for
1616

1717
1. From your preferred development directory, create a directory for a new project and `cd` into it:
1818

19-
```bash
20-
mkdir graphql-server-example
21-
cd graphql-server-example
22-
```
19+
```bash
20+
mkdir graphql-server-example
21+
cd graphql-server-example
22+
```
2323

2424
2. Initialize a new Node.js project with `npm` (or another package manager you
25-
prefer, such as Yarn):
25+
prefer, such as Yarn):
2626

27-
```bash
28-
npm init --yes
29-
```
27+
```bash
28+
npm init --yes
29+
```
3030

3131
Your project directory now contains a `package.json` file.
3232

3333
## Step 2: Install dependencies
34+
3435
Applications that run Apollo Server require two top-level dependencies:
35-
* [`graphql`](https://npm.im/graphql) (also known as `graphql-js`) is the library that implements the core GraphQL parsing and execution algorithms.
36-
* [`@apollo/server`](https://www.npmjs.com/package/@apollo/server) is the main library for Apollo Server itself. Apollo Server knows how to turn HTTP requests and responses into GraphQL operations and run them in an extensible context with support for plugins and other features.
36+
37+
- [`graphql`](https://npm.im/graphql) (also known as `graphql-js`) is the library that implements the core GraphQL parsing and execution algorithms.
38+
- [`@apollo/server`](https://www.npmjs.com/package/@apollo/server) is the main library for Apollo Server itself. Apollo Server knows how to turn HTTP requests and responses into GraphQL operations and run them in an extensible context with support for plugins and other features.
3739

3840
Run the following command to install both of these packages and save them in
3941
your project's `node_modules` directory:
@@ -55,10 +57,10 @@ mkdir src
5557
touch src/index.ts
5658
```
5759

58-
2. Run the following command to install the `typescript` package into your project's dev dependencies:
60+
2. Run the following command to install the `typescript` and `@types/node` packages into your project's dev dependencies:
5961

6062
```bash
61-
npm install --save-dev typescript
63+
npm install --save-dev typescript @types/node
6264
```
6365

6466
3. Next, create a `tsconfig.json` file in your project:
@@ -74,25 +76,29 @@ touch tsconfig.json
7476
"compilerOptions": {
7577
"rootDirs": ["src"],
7678
"outDir": "dist",
77-
"lib": ["es2019"],
78-
"target": "es2019",
79+
"lib": ["es2020"],
80+
"target": "es2020",
7981
"module": "esnext",
8082
"moduleResolution": "node",
81-
"esModuleInterop": true
83+
"esModuleInterop": true,
84+
"types": ["node"]
8285
}
8386
}
8487
```
8588

8689
For more information on the compiler options above, see the [TypeScript Compiler docs](https://www.typescriptlang.org/tsconfig).
8790

8891
5. Finally, replace the default `scripts` entry in your `package.json` file with the following `type` and `scripts` entries:
92+
8993
```json title="package.json"
9094
{
9195
// ...etc.
9296
"type": "module",
9397
"scripts": {
94-
"start": "tsc && node ./dist/index.js"
95-
},
98+
"compile": "tsc",
99+
"postinstall": "npm run compile",
100+
"start": "npm run compile && node ./dist/index.js"
101+
}
96102
// other dependencies
97103
}
98104
```
@@ -103,7 +109,7 @@ The above `start` script tells TypeScript to compile your code into JavaScript b
103109

104110
```
105111
106-
> tsc && node ./dist/index.js
112+
> npm run compile && node ./dist/index.js
107113
```
108114

109115
</ExpansionPanel>
@@ -119,13 +125,14 @@ If you are using JavaScript, create a `index.js` file that will contain **all**
119125
```
120126

121127
Now replace the default `scripts` entry in your `package.json` file with these `type` and `scripts` entries:
128+
122129
```json title="package.json"
123130
{
124131
// ...etc.
125132
"type": "module",
126133
"scripts": {
127134
"start": "node index.js"
128-
},
135+
}
129136
// other dependencies
130137
}
131138
```
@@ -171,7 +178,6 @@ const typeDefs = `#graphql
171178

172179
</MultiCodeBlock>
173180

174-
175181
> Adding `#graphql` to the beginning of a [template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) provides GraphQL syntax highlighting in supporting IDEs.
176182
177183
This snippet defines a simple, valid GraphQL schema. Clients will be able to execute a query named `books`, and our server will return an array of zero or more `Book`s.
@@ -279,14 +285,14 @@ We can now execute GraphQL queries on our server. To execute our first query, we
279285

280286
Visit `http://localhost:4000` in your browser, which will open the Apollo Sandbox:
281287

282-
<img class="screenshot" src="./images/sandbox.jpeg" alt="Apollo Sandbox"/>
288+
<img class="screenshot" src="./images/sandbox.jpeg" alt="Apollo Sandbox" />
283289

284290
The Sandbox UI includes:
285291

286-
* An Operations panel for writing and executing queries (in the middle)
287-
* A Response panel for viewing query results (on the right)
288-
* Tabs for schema exploration, search, and settings (on the left)
289-
* A URL bar for connecting to other GraphQL servers (in the upper left)
292+
- An Operations panel for writing and executing queries (in the middle)
293+
- A Response panel for viewing query results (on the right)
294+
- Tabs for schema exploration, search, and settings (on the left)
295+
- A URL bar for connecting to other GraphQL servers (in the upper left)
290296

291297
Our server supports a single query named `books`. Let's execute it!
292298

@@ -303,7 +309,12 @@ query GetBooks {
303309

304310
Paste this string into the Operations panel and click the blue button in the upper right. The results (from our hardcoded data set) appear in the Response panel:
305311

306-
<img class="screenshot" src="./images/sandbox-response.png" width="400" alt="Sandbox response panel"/>
312+
<img
313+
class="screenshot"
314+
src="./images/sandbox-response.png"
315+
width="400"
316+
alt="Sandbox response panel"
317+
/>
307318

308319
> **Note:** If Apollo Sandbox can't find your schema, ensure you have introspection enabled by passing `introspection: true` to the `ApolloServer` constructor. We recommend disabling introspection when using Apollo Server in a production environment.
309320
@@ -314,7 +325,10 @@ One of the most important concepts of GraphQL is that clients can choose to quer
314325
You can view and fork the complete example on Github:
315326

316327
<div align="left">
317-
<ButtonLink href="https://github.com/apollographql/docs-examples/tree/main/apollo-server/v4/getting-started" size="lg">
328+
<ButtonLink
329+
href="https://github.com/apollographql/docs-examples/tree/main/apollo-server/v4/getting-started"
330+
size="lg"
331+
>
318332
See the full example!
319333
</ButtonLink>
320334
</div>
@@ -331,10 +345,8 @@ This example application is a great starting point for working with
331345
Apollo Server. Check out the following resources to learn more about the basics
332346
of schemas, resolvers, and deployment:
333347

334-
* [Schema basics](/apollo-server/schema/schema/)
335-
* [Resolvers](/apollo-server/data/resolvers/)
336-
* [Deploying with Heroku](/apollo-server/deployment/heroku/)
337-
338-
Want to learn how to modularize and scale a GraphQL API? Check out the [Apollo Federation Docs](/federation) to learn how a federated architecture can create a unified *supergraph* that combines multiple GraphQL APIs.
339-
348+
- [Schema basics](/apollo-server/schema/schema/)
349+
- [Resolvers](/apollo-server/data/resolvers/)
350+
- [Deploying with Heroku](/apollo-server/deployment/heroku/)
340351

352+
Want to learn how to modularize and scale a GraphQL API? Check out the [Apollo Federation Docs](/federation) to learn how a federated architecture can create a unified _supergraph_ that combines multiple GraphQL APIs.

0 commit comments

Comments
 (0)