Skip to content

Commit 2fc0d1e

Browse files
Alan-ChaErikWittern
authored andcommitted
Update LoopBack tutorials
Changes to ports Signed-off-by: Alan Cha <[email protected]>
1 parent 99caf5f commit 2fc0d1e

File tree

2 files changed

+30
-68
lines changed

2 files changed

+30
-68
lines changed

docs/tutorials/cli_loopback.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Please note that while the CLI tool will satisfy most needs, it does not offer t
1010

1111
[![OpenAPI-to-GraphQL](../conveyor_belt.png)](https://www.youtube.com/watch?v=4TrHUBJElrk "Click here to watch!")
1212

13-
1413
## Do it yourself
1514

1615
### Make sure you have installed Node.js
@@ -31,7 +30,7 @@ npm i -g openapi-to-graphql-cli
3130

3231
OpenAPI-to-GraphQL relies on the OpenAPI Specification (OAS) of an existing API to create a GraphQL interface around that API. OpenAPI-to-GraphQL can also retrieve a web-hosted OAS.
3332

34-
If you are using LoopBack, you can simply copy the URL location of the web-hosted OAS, which should be located at http://127.0.0.1:3000/openapi.json after starting the API.
33+
If you are using LoopBack, you can simply copy the URL location of the web-hosted OAS, which should be located at http://localhost:3001/openapi.json after starting the API.
3534

3635
```sh
3736
# in the LoopBack project folder:
@@ -44,9 +43,9 @@ If you want to generate a GraphQL interface for another API, make sure that API
4443

4544
### Start GraphQL server
4645

47-
Once OpenAPI-to-GraphQL is installed and the OAS is obtained, you can create and start the GraphQL server. The created GraphQL server is then accessible by default at [http://127.0.0.1:3001/graphql](http://127.0.0.1:3001/graphql).
46+
Once OpenAPI-to-GraphQL is installed and the OAS is obtained, you can create and start the GraphQL server. The created GraphQL server is then accessible by default at [http://localhost:3000/graphql](http://localhost:3000/graphql).
4847

49-
You can specify a local file containing the OAS specification or a remote url such as `http://127.0.0.1:3000/openapi.json`.
48+
You can specify a local file containing the OAS specification or a remote url such as `http://localhost:3001/openapi.json`.
5049

5150
```sh
5251
openapi-to-graphql <OAS JSON file path or remote url>

docs/tutorials/loopback.md

Lines changed: 27 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,14 @@ Start the API by running the following:
4747
npm start
4848
```
4949

50-
Next, access the API's OAS at [http://127.0.0.1:3000/openapi.json](http://127.0.0.1:3000/openapi.json) and save it to disk.
51-
52-
Then change the server url to match the following. Otherwise, the GraphQL interface will not be able to make calls to the Example Family Tree API.
53-
54-
```
55-
"servers": [
56-
{
57-
"url": "http://localhost:3000"
58-
}
59-
]
60-
```
50+
Next, access the API's OAS at [http://localhost:3001/openapi.json](http://localhost:3001/openapi.json) and save it to disk.
6151

6252
### Install OpenAPI-to-GraphQL
6353

6454
To install OpenAPI-to-GraphQL, clone the repository and link the library (for the CLI commands to work) using the indicated steps.
6555

6656
```
67-
npm i -g openapi-to-graphql
57+
npm i -g openapi-to-graphql-cli
6858
```
6959

7060
Please note that OpenAPI-to-GraphQL can be used either as a library, or via its Command Line Interface (CLI). In this case, we will be using the CLI tool, which will start a server in addition to creating the GraphQL interface.
@@ -77,7 +67,7 @@ Start the GraphQL server by running the following command.
7767
openapi-to-graphql <OAS JSON file path or remote url>
7868
```
7969

80-
The created GraphQL server is then accessible at [http://127.0.0.1:3001/graphql](http://127.0.0.1:3001/graphql).
70+
The created GraphQL server is then accessible at [http://localhost:3000/graphql](http://localhost:3000/graphql).
8171

8272
### Try simple queries
8373

@@ -89,8 +79,8 @@ Try to run a simple query like the following:
8979

9080
GraphQL query
9181
```
92-
query{
93-
person(id: 15){
82+
query {
83+
person(id: 15) {
9484
name
9585
}
9686
}
@@ -136,47 +126,20 @@ Here are the **Link objects** we will be adding to the OAS.
136126
```
137127
"links": {
138128
"mother": {
139-
"operationId": "getPerson",
129+
"operationId": "PersonController.findById",
140130
"parameters": {
141131
"id": "$response.body#/motherId"
142132
}
143133
},
144134
"father": {
145-
"operationId": "getPerson",
135+
"operationId": "PersonController.findById",
146136
"parameters": {
147137
"id": "$response.body#/fatherId"
148138
}
149139
}
150140
}
151141
```
152142

153-
Open the Family Tree API OAS and add the *links* and the *operationId* "getPerson" to match the following structure.
154-
155-
```
156-
{
157-
"paths": {
158-
"/people/{id}": {
159-
"get": {
160-
"operationId": "getPerson"
161-
"responses": {
162-
"200": {
163-
"links": {
164-
...
165-
},
166-
...
167-
},
168-
...
169-
},
170-
...
171-
},
172-
...
173-
},
174-
...
175-
},
176-
...
177-
}
178-
```
179-
180143
After you have saved your changes to the OAS, restart the GraphQL server.
181144

182145
```
@@ -205,19 +168,19 @@ Now we can write much complex queries like the following.
205168

206169
GraphQL query
207170
```
208-
query{
209-
person(id: 15){
171+
query {
172+
person(id: 15) {
210173
name
211174
generation
212-
father{
175+
father {
213176
name
214177
id
215178
generation
216-
mother{
179+
mother {
217180
name
218181
id
219182
generation
220-
father{
183+
father {
221184
name
222185
id
223186
generation
@@ -260,39 +223,39 @@ Expected output
260223
GraphQL query
261224
```
262225
query{
263-
person(id: 15){
264-
mother{
265-
mother{
266-
mother{
226+
person(id: 15) {
227+
mother {
228+
mother {
229+
mother {
267230
name
268231
}
269-
father{
232+
father {
270233
name
271234
}
272235
}
273-
father{
274-
mother{
236+
father {
237+
mother {
275238
name
276239
}
277-
father{
240+
father {
278241
name
279242
}
280243
}
281244
}
282-
father{
283-
mother{
284-
mother{
245+
father {
246+
mother {
247+
mother {
285248
id
286249
}
287-
father{
250+
father {
288251
id
289252
}
290253
}
291-
father{
292-
mother{
254+
father {
255+
mother {
293256
id
294257
}
295-
father{
258+
father {
296259
id
297260
}
298261
}

0 commit comments

Comments
 (0)