-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add tutorial to expose GraphQL APIs #1899
Conversation
docs/site/exposing-graphql-api.md
Outdated
lb4 example todo | ||
``` | ||
|
||
### Install OASGraph and required dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: all upper case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Will change it.
Actually our docs are not quite inconsistent on the capitalization of the titles. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think this line is missing from inside the src/application.ts file, or can it be resolved differently? options = Object.assign({}, {
rest: {
openApiSpec: {
servers: [{url:'http://localhost:3000'}],
}
}
}); otherwise, the query in the doc will return
|
be7dcc2
to
cb77b58
Compare
Thanks @marioestradarosa for catching that. Somehow I thought it's no longer needed! PTAL again. |
@dhmlau , I have just open a PR #1900 that I think can make things easier for the application in this matter. If it lands, then I believe we should then modify the examples accordingly. thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good.
docs/site/exposing-graphql-apis.md
Outdated
--- | ||
lang: en | ||
title: 'Exposing GraphQL APIs' | ||
keywords: LoopBack 4.0, LoopBack 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add "GraphQL" keyword too?
docs/site/exposing-graphql-apis.md
Outdated
and the required dependencies: | ||
|
||
```sh | ||
npm i --save oasgraph express-graphql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious, why do we have to install express-graphql
ourselves? I would expect the CLI command oasgraph
to be self-contained and come with all dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OASGraph is meant to be used as a library to transform from OpenAPI to GraphQL schema, It doesn't need express-graphql
, since you can use any other package once you have your schema converted. The main idea of the library is to be used inside the application.
However the CLI is used to test the implementation and it requires express-graphql
. It is not a separate package (like monorepo), it is just a single file that implements the GraphQL server with the generated schema. IMO, it is not meant for production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @marioestradarosa. @dhmlau has pointed me to IBM/openapi-to-graphql#30, I have a better understanding now.
So, assuming oasgraph is not going to change, I am proposing the following changes:
Include express
in the modules to install, we must not rely on express
being installed in top-level node_modules
by being a dependency of @loopback/rest
.
$ npm i --save oasgraph express express-graphql
Explain the users why we are asking them to install those two extra express modules and point them to the discussion in IBM/openapi-to-graphql#30 to learn more and/or give us feedback.
docs/site/exposing-graphql-apis.md
Outdated
The expected output looks like this: | ||
|
||
```json | ||
{ "data": { "todos": [ { "id": 1, "title": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you reformat the data to make it easier to read please? E.g. use JSON.stringify(data, null, 2)
, or perhaps put each todos array item on its own line.
{ "data": { "todos": [
{"id": 1, /*...*/},
{"id": 2, /*...*/},
// etc.
]}}
docs/site/sidebars/lb4_sidebar.yml
Outdated
@@ -98,6 +98,11 @@ children: | |||
- title: 'Run and Test it' | |||
url: soap-calculator-tutorial-run-and-test.html | |||
output: 'web, pdf' | |||
|
|||
- title: 'Exposing GraphQL APIs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still a Tutorial? I feel that "Exposing GraphQL APIs" and "Deploying to IBM Cloud" don't belong to Tutorials section, I would certainly not look for these pages in Tutorials myself!
Can we introduce a new section "Guides" please and move both pages there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about turning them into a How to sections ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to
sounds good to me.
@dhmlau, according to PR #1900 and @raymondfeng suggestions, here is the final code for the application.ts, this will populate the server property automatically. options = Object.assign(
{
rest: {
openApiSpec: {
setServersFromRequest: true,
},
},
},
options,
); |
Hmm, we may want to use a deep-assign implementation instead of |
docs/site/exposing-graphql-apis.md
Outdated
command: | ||
|
||
```sh | ||
node_modules/.bin/oasgraph http://localhost:3000/openapi.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified as npx oasgraph http://localhost:3000/openapi.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just need to mention the user that npx
comes bundled with npm version >5.2 . it works fine, I have just tested, didn't know about npx
😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node.js 8.9.0, the minimal Node.js version required by LoopBack 4, comes with npm version 5.5.1, which includes npx
. IMO, there is no need to explain how to run oasgraph on npm version older than 5.2.
Having said that, I think most LoopBack users are probably not familiar with npx yet, so we should give them a pointer on where to learn more.
For example, add the following paragraph after the code snippet showing how to invoke npx
:
_Haven't heard about `npx` yet? It's a cool helper provided by `npm`
and available out of the box since Node.js 8.x. Learn more in their announcement blog post:
[Introducing npx: an npm package runner](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b))_
I thought that adding options as the end parameter prevents this overwrite. I did some tests. If we place the options as the second parameter as it is here in this comment, then the config that comes in by the caller takes precedence. On the other hand, if we place it as the first parameter, the rest property defined here in options = Object.assign(
options,
{
rest: {
openApiSpec: {
setServersFromRequest: true,
},
},
},
); Which one is better for this case?. |
Thanks for your feedback! To move this PR forward, I'm going to incorporate the feedback with the major changes:
|
docs/site/exposing-graphql-apis.md
Outdated
command: | ||
|
||
```sh | ||
node_modules/.bin/oasgraph http://localhost:3000/openapi.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node.js 8.9.0, the minimal Node.js version required by LoopBack 4, comes with npm version 5.5.1, which includes npx
. IMO, there is no need to explain how to run oasgraph on npm version older than 5.2.
Having said that, I think most LoopBack users are probably not familiar with npx yet, so we should give them a pointer on where to learn more.
For example, add the following paragraph after the code snippet showing how to invoke npx
:
_Haven't heard about `npx` yet? It's a cool helper provided by `npm`
and available out of the box since Node.js 8.x. Learn more in their announcement blog post:
[Introducing npx: an npm package runner](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b))_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@dhmlau , I think your PR is now ready to land 👍 |
Fixes #1775
Based on the QuickLab we've created for Node+JS Interactive, this PR added the GraphQL APIs part as one of the tutorials.