You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/cli_loopback.md
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,6 @@ Please note that while the CLI tool will satisfy most needs, it does not offer t
10
10
11
11
[](https://www.youtube.com/watch?v=4TrHUBJElrk"Click here to watch!")
12
12
13
-
14
13
## Do it yourself
15
14
16
15
### Make sure you have installed Node.js
@@ -31,7 +30,7 @@ npm i -g openapi-to-graphql-cli
31
30
32
31
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.
33
32
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.
35
34
36
35
```sh
37
36
# in the LoopBack project folder:
@@ -44,9 +43,9 @@ If you want to generate a GraphQL interface for another API, make sure that API
44
43
45
44
### Start GraphQL server
46
45
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).
48
47
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`.
50
49
51
50
```sh
52
51
openapi-to-graphql <OAS JSON file path or remote url>
Copy file name to clipboardExpand all lines: docs/tutorials/loopback.md
+27-64Lines changed: 27 additions & 64 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,24 +47,14 @@ Start the API by running the following:
47
47
npm start
48
48
```
49
49
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.
61
51
62
52
### Install OpenAPI-to-GraphQL
63
53
64
54
To install OpenAPI-to-GraphQL, clone the repository and link the library (for the CLI commands to work) using the indicated steps.
65
55
66
56
```
67
-
npm i -g openapi-to-graphql
57
+
npm i -g openapi-to-graphql-cli
68
58
```
69
59
70
60
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.
77
67
openapi-to-graphql <OAS JSON file path or remote url>
78
68
```
79
69
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).
81
71
82
72
### Try simple queries
83
73
@@ -89,8 +79,8 @@ Try to run a simple query like the following:
89
79
90
80
GraphQL query
91
81
```
92
-
query{
93
-
person(id: 15){
82
+
query{
83
+
person(id: 15){
94
84
name
95
85
}
96
86
}
@@ -136,47 +126,20 @@ Here are the **Link objects** we will be adding to the OAS.
136
126
```
137
127
"links": {
138
128
"mother": {
139
-
"operationId": "getPerson",
129
+
"operationId": "PersonController.findById",
140
130
"parameters": {
141
131
"id": "$response.body#/motherId"
142
132
}
143
133
},
144
134
"father": {
145
-
"operationId": "getPerson",
135
+
"operationId": "PersonController.findById",
146
136
"parameters": {
147
137
"id": "$response.body#/fatherId"
148
138
}
149
139
}
150
140
}
151
141
```
152
142
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
-
180
143
After you have saved your changes to the OAS, restart the GraphQL server.
181
144
182
145
```
@@ -205,19 +168,19 @@ Now we can write much complex queries like the following.
0 commit comments