Skip to content

Commit f50f456

Browse files
Alan-ChaErikWittern
authored andcommitted
Capitalize comments
Signed-off-by: Alan Cha <[email protected]>
1 parent ced79cd commit f50f456

27 files changed

+562
-448
lines changed

docs/tutorials/watson.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
OpenAPI-to-GraphQL is a library that automatically creates GraphQL wrappers for existing REST(-like) APIs, relying on the Swagger or OpenAPI specifications of these APIs. To exemplify what OpenAPI-to-GraphQL can do, let's create a GraphQL wrapper for the [IBM Watson Language Translator API](https://www.ibm.com/watson/services/language-translator/). The Language Translator API uses machine learning capabilities to detect the language of given texts, and to translate texts to any of a number of supported languages.
44

5-
65
## Video demo
76

87
[![OpenAPI-to-GraphQL](../conveyor_belt.png)](https://www.youtube.com/watch?v=87ryTWc85BM "Click here to watch!")
98

10-
119
## Creating a simple wrapper
1210

1311
To create a GraphQL wrapper around the API, we use the Swagger specification of the Language Translator API available [here](https://watson-api-explorer.ng.bluemix.net/listings/language-translator-v2.json). From this specification, OpenAPI-to-GraphQL creates a GraphQL schema, consisting of the API's data types and their relations. OpenAPI-to-GraphQL also creates so-called resolve functions, which interact with the Language Translator API to resolve GraphQL queries. The schema created by OpenAPI-to-GraphQL can be exposed using web application frameworks like [Express.js](https://expressjs.com/) via the [express-graphql](https://github.com/graphql/express-graphql) middleware.
@@ -37,13 +35,12 @@ async function startServer () {
3735
app.listen(3000)
3836
}
3937

40-
// kick things off:
38+
// Kick things off:
4139
startServer()
4240
```
4341

4442
Pretty simple, no?
4543

46-
4744
## Trying out the GraphQL wrapper
4845

4946
Running the above code exposes the created GraphQL wrapper at `localhost:3000`. Visiting `localhost:3000/graphiql`, the well-known GraphiQL in-browser IDE for GraphQL is exposed and allows us to perform first queries, for example to identify the language of a given text:
@@ -52,7 +49,6 @@ Running the above code exposes the created GraphQL wrapper at `localhost:3000`.
5249

5350
Note the `viewerBasicAuth` type at the root of this query. It was created by OpenAPI-to-GraphQL as a mechanism for users to provide their [Language Translator API credentials](https://www.ibm.com/watson/developercloud/language-translator/api/v2/curl.html?curl#authentication) as part of the query. If desired, OpenAPI-to-GraphQL can alternatively be configured to send credentials without the user having to explicitly state them. As we can see, the above query returns a list of identified candidate languages of the given text, which are ranked by a confidence score.
5451

55-
5652
## Enabling nested queries
5753

5854
Running simple queries like this one via GraphQL already provides some benefits, because the user can select the specific data _fields_ to be returned, allowing to reduce response sizes. However, arguably, much more value results from GraphQL's ability to perform more complex, nested queries. To enable nested queries, OpenAPI-to-GraphQL makes use of [links](https://swagger.io/docs/specification/links/), a new feature of the OpenAPI Specification 3.0. Links allow to define dependencies between API operations by specifying how data returned by one operation can be used as input to another operation. If present in a given OpenAPI Specification, OpenAPI-to-GraphQL uses links to enrich GraphQL types, allowing deeply nested queries.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
lib/
1+
lib/
2+
*.md

packages/openapi-to-graphql-cli/lib/openapi-to-graphql.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql-cli/src/openapi-to-graphql.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function startGraphQLServer(oas, port) {
167167
.then(({ schema, report }) => {
168168
console.log(JSON.stringify(report, null, 2))
169169

170-
// save local file if required
170+
// Save local file if required
171171
if (program.save) {
172172
writeSchema(schema)
173173
} else {
@@ -176,7 +176,7 @@ function startGraphQLServer(oas, port) {
176176
app.use(cors())
177177
}
178178

179-
// mounting graphql endpoint using the middleware express-graphql
179+
// Mounting graphql endpoint using the middleware express-graphql
180180
app.use(
181181
'/graphql',
182182
graphqlHTTP({
@@ -185,7 +185,7 @@ function startGraphQLServer(oas, port) {
185185
})
186186
)
187187

188-
// initiating the server on the port specified by user or the default one
188+
// Initiating the server on the port specified by user or the default one
189189
app.listen(port, () => {
190190
console.log(`GraphQL accessible at: http://localhost:${port}/graphql`)
191191
})
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
lib/
1+
lib/
2+
*.md

packages/openapi-to-graphql/lib/auth_builder.js

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/auth_builder.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/index.js

Lines changed: 19 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)