Skip to content

Commit

Permalink
feat(graphql): add an extension for type-graphql integration
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng committed Sep 3, 2020
1 parent ed9c5ef commit 72c22bf
Show file tree
Hide file tree
Showing 49 changed files with 5,147 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@
# - Standby owner(s): n/a
/extensions/typeorm @hacksparrow

# GraphQL
#
# - Issue label: GraphQL
# - Primary owner(s): @raymondfeng
/extensions/graphql @raymondfeng
/examples/graphql @raymondfeng

#
# Build & internal tooling
#
Expand Down
10 changes: 10 additions & 0 deletions docs/site/GraphQL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
lang: en
title: 'GraphQL'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, GraphQL
layout: readme
source: loopback-next
file: extensions/graphql/README.md
sidebar: lb4_sidebar
permalink: /doc/en/lb4/GraphQL.html
---
2 changes: 2 additions & 0 deletions docs/site/MONOREPO.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ one in the monorepo: `npm run update-monorepo-file`
| [examples/context](https://github.com/strongloop/loopback-next/tree/master/examples/context) | @loopback/example-context | Standalone examples to illustrate features provided by @loopback/context |
| [examples/express-composition](https://github.com/strongloop/loopback-next/tree/master/examples/express-composition) | @loopback/example-express-composition | LoopBack 4 REST API on Express |
| [examples/file-transfer](https://github.com/strongloop/loopback-next/tree/master/examples/file-transfer) | @loopback/example-file-transfer | Example application for file upload/download with LoopBack 4 |
| [examples/graphql](https://github.com/strongloop/loopback-next/tree/master/examples/graphql) | @loopback/example-graphql | GraphQL Example Application |
| [examples/greeter-extension](https://github.com/strongloop/loopback-next/tree/master/examples/greeter-extension) | @loopback/example-greeter-extension | An example showing how to implement the extension point/extension pattern using LoopBack 4 |
| [examples/greeting-app](https://github.com/strongloop/loopback-next/tree/master/examples/greeting-app) | @loopback/example-greeting-app | An example greeting application for LoopBack 4 |
| [examples/hello-world](https://github.com/strongloop/loopback-next/tree/master/examples/hello-world) | @loopback/example-hello-world | A simple hello-world Application using LoopBack 4 |
Expand All @@ -41,6 +42,7 @@ one in the monorepo: `npm run update-monorepo-file`
| [extensions/authentication-passport](https://github.com/strongloop/loopback-next/tree/master/extensions/authentication-passport) | @loopback/authentication-passport | A package creating adapters between the passport module and @loopback/authentication |
| [extensions/context-explorer](https://github.com/strongloop/loopback-next/tree/master/extensions/context-explorer) | @loopback/context-explorer | Visualize context hierarchy, bindings, configurations, and dependencies |
| [extensions/cron](https://github.com/strongloop/loopback-next/tree/master/extensions/cron) | @loopback/cron | Schedule tasks using cron-like syntax |
| [extensions/graphql](https://github.com/strongloop/loopback-next/tree/master/extensions/graphql) | @loopback/graphql | LoopBack's graphql integration |
| [extensions/health](https://github.com/strongloop/loopback-next/tree/master/extensions/health) | @loopback/extension-health | An extension exposes health check related endpoints with LoopBack 4 |
| [extensions/logging](https://github.com/strongloop/loopback-next/tree/master/extensions/logging) | @loopback/extension-logging | An extension exposes logging for Winston and Fluentd with LoopBack 4 |
| [extensions/metrics](https://github.com/strongloop/loopback-next/tree/master/extensions/metrics) | @loopback/extension-metrics | An extension exposes metrics for Prometheus with LoopBack 4 |
Expand Down
8 changes: 8 additions & 0 deletions docs/site/sidebars/lb4_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,18 @@ children:
- title: 'Creating Other Forms of APIs'
output: 'web, pdf'
children:
- title: 'Creating GraphQL APIs'
url: GraphQL.html
output: 'web, pdf'

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

- title: 'Running cron jobs'
url: Running-cron-jobs.html
output: 'web, pdf'

- title: 'Accessing Databases'
output: 'web, pdf'
children:
Expand Down
1 change: 1 addition & 0 deletions examples/graphql/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=true
27 changes: 27 additions & 0 deletions examples/graphql/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) IBM Corp. 2020.
Node module: @loopback/example-graphql
This project is licensed under the MIT License, full text below.

--------

MIT License

MIT License Copyright (c) IBM Corp. 2020

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75 changes: 75 additions & 0 deletions examples/graphql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# @loopback/example-graphql

An example application to demonstrate GraphQL integration for LoopBack 4 using
[@loopback/graphql](https://github.com/strongloop/loopback-next/tree/graphql/extensions/graphql).

## Try it out

```sh
npm start
```

You should see the following messages:

```sh
Server is running at http://[::1]:3000
Try http://[::1]:3000/graphql
```

Open http://127.0.0.1:3000/graphql in your browser to play with the GraphiQL.

![graphql-demo](graphql-demo.png)

1. Copy the query to the right panel:

```graphql
query GetRecipe1 {
recipe(recipeId: "1") {
title
description
ratings
creationDate
ratingsCount(minRate: 2)
averageRating
ingredients
numberInCollection
}
}
```

2. Click on the run icon:

```json
{
"data": {
"recipe": {
"title": "Recipe 1",
"description": "Desc 1",
"ratings": [0, 3, 1],
"creationDate": "2018-04-11T00:00:00.000Z",
"ratingsCount": 1,
"averageRating": 1.3333333333333333,
"ingredients": ["one", "two", "three"],
"numberInCollection": 1
}
}
}
```

## Contributions

- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)

## Tests

Run `npm test` from the root folder.

## Contributors

See
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).

## License

MIT
Binary file added examples/graphql/graphql-demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 72c22bf

Please sign in to comment.