-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphql): add an extension for type-graphql integration
- Loading branch information
1 parent
971a7c7
commit d03365f
Showing
41 changed files
with
3,765 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) IBM Corp. 2019. | ||
Node module: @loopback/graphql | ||
This project is licensed under the MIT License, full text below. | ||
|
||
-------- | ||
|
||
MIT License | ||
|
||
MIT License Copyright (c) IBM Corp. 2019 | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# @loopback/graphql | ||
|
||
This module provides integration with [GraphQL](https://graphql.org/) using | ||
[type-graphql](https://typegraphql.com/). | ||
|
||
## Stability: ⚠️Experimental⚠️ | ||
|
||
> Experimental packages provide early access to advanced or experimental | ||
> functionality to get community feedback. Such modules are published to npm | ||
> using `0.x.y` versions. Their APIs and functionality may be subject to | ||
> breaking changes in future releases. | ||
## Basic Use | ||
|
||
```ts | ||
export class MyApplication extends BootMixin(RestApplication) { | ||
constructor(config: ApplicationConfig) { | ||
super(config); | ||
this.projectRoot = __dirname; | ||
this.component(GraphQLComponent); | ||
this.configure(GraphQLBindings.GRAPHQL_SERVER).to({asMiddlewareOnly: true}); | ||
} | ||
} | ||
``` | ||
|
||
## Configure GraphQLServer | ||
|
||
This package can be used in two flavors: | ||
|
||
- As a server for LoopBack applications | ||
- As a middleware for LoopBack REST applications | ||
|
||
## Use LoopBack dependency injections in resolver classes | ||
|
||
All of LoopBack decorators for dependency injection , such as `@inject`, | ||
`@service`, `repository`, and `config`, can be used with resolver classes. | ||
|
||
```ts | ||
import {service} from '@loopback/core'; | ||
@resolver(of => Recipe) | ||
export class RecipeResolver implements ResolverInterface<Recipe> { | ||
constructor( | ||
// constructor injection of service using LoopBack | ||
@service() | ||
private readonly recipeService: RecipeService, | ||
) {} | ||
} | ||
``` | ||
|
||
## Boot GraphQL resolvers | ||
|
||
The `GraphQLComponent` contributes a booter that discovers and registers | ||
resolver classes from `src/graphql-resolvers` during `app.boot()`. | ||
|
||
- recipe-resolver.ts | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install --save @loopback/graphql | ||
``` | ||
|
||
## Try it out | ||
|
||
```sh | ||
npm run build | ||
node dist/__tests__/fixtures/graphql-test/src/index.js | ||
``` | ||
|
||
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. | ||
|
||
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 |
Oops, something went wrong.