Skip to content

Commit

Permalink
docs: apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dhmlau committed Oct 24, 2018
1 parent cb77b58 commit 1a09b11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 42 deletions.
49 changes: 15 additions & 34 deletions docs/site/exposing-graphql-apis.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
lang: en
title: 'Exposing GraphQL APIs'
keywords: LoopBack 4.0, LoopBack 4
keywords: LoopBack 4.0, LoopBack 4, GraphQL
sidebar: lb4_sidebar
permalink: /doc/en/lb4/exposing-graphql-apis.html
---
Expand All @@ -23,38 +23,13 @@ below:
lb4 example todo
```

### Customize the Server URL of the REST Server

OASGraph expects the provided OpenAPI specification to have the `servers` url to
be the server hosting the REST endpoints. We're going to modify the constructor
of `TodoListApplication` in `src/application.ts` to include this information.

```ts
constructor(options: ApplicationConfig = {}) {
// Add this snippet at the beginning of the constructor
options = Object.assign(
{},
{
rest: {
openApiSpec: {
servers: [{url: 'http://localhost:3000'}],
},
},
},
);
// end of the code snippet
super(options);
...
}
```

### Install OASGraph and Required Dependencies

From your LoopBack application, run the following command to install OASGraph
and the required dependencies:

```sh
npm i --save oasgraph express-graphql
npm i --save oasgraph express express-graphql
```

### Start the GraphQL Server
Expand All @@ -68,6 +43,12 @@ express on port 3001. Specifying the OpenAPI spec generated by the
todo-application as the parameter, start up the server by running the following
command:

```sh
npx oasgraph http://localhost:3000/openapi.json
```

If you're using npm version lower than 5.2, run the command below instead:

```sh
node_modules/.bin/oasgraph http://localhost:3000/openapi.json
```
Expand All @@ -94,13 +75,13 @@ Here are some examples of the `query` and `mutation` calls:
The expected output looks like this:

```json
{ "data": { "todos": [ { "id": 1, "title":
"Take over the galaxy", "desc":
"MWAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA" }, { "id": 2, "title":
"destroy alderaan", "desc": "Make sure there are no survivors left!" }, { "id":
3, "title": "terrorize senate", "desc": "Tell them they're getting a budget
cut." }, { "id": 4, "title": "crush rebel scum", "desc": "Every.Last.One." } ] }
}
{ "data": { "todos": [
{ "id": 1, "title": "Take over the galaxy", "desc": "MWAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA" },
{ "id": 2, "title": "destroy alderaan", "desc": "Make sure there are no survivors left!" },
{"id": 3, "title": "terrorize senate", "desc": "Tell them they're getting a budget
cut." },
{ "id": 4, "title": "crush rebel scum", "desc": "Every.Last.One." }
] } }
```

2. Create a to-do instance and retrieve its ID and title in the response object
Expand Down
20 changes: 12 additions & 8 deletions docs/site/sidebars/lb4_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ children:
url: soap-calculator-tutorial-run-and-test.html
output: 'web, pdf'

- title: 'Exposing GraphQL APIs'
url: exposing-graphql-apis.html
output: 'web, pdf'

- title: 'Deploying to IBM Cloud'
url: Deploying-to-IBM-Cloud.html
output: 'web, pdf'

- title: 'Key concepts'
url: Concepts.html
output: 'web, pdf'
Expand Down Expand Up @@ -199,6 +191,18 @@ children:
url: Error-handling.html
output: 'web, pdf'

- title: 'How tos'
url: Concepts.html
output: 'web, pdf'
children:
- title: 'Exposing GraphQL APIs'
url: exposing-graphql-apis.html
output: 'web, pdf'

- title: 'Deploying to IBM Cloud'
url: Deploying-to-IBM-Cloud.html
output: 'web, pdf'

- title: 'Booting an Application'
url: Booting-an-Application.html
output: 'web, pdf'
Expand Down

0 comments on commit 1a09b11

Please sign in to comment.