Skip to content

Commit

Permalink
Merge pull request #56 from rankun203/docs/readme
Browse files Browse the repository at this point in the history
fix(docs): Add example for other GraphQL servers
  • Loading branch information
maticzav authored Jun 13, 2018
2 parents 159495b + 3c2277a commit d4f4922
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ yarn add graphql-shield

## Example

### GraphQL Yoga

```ts
import { GraphQLServer } from 'graphql-yoga'
import { rule, shield, and, or, not } from 'graphql-shield'
Expand Down Expand Up @@ -136,6 +138,19 @@ const server = GraphQLServer({
server.start(() => console.log('Server is running on http://localhost:4000'))
```

### Others

```ts
// Permissions...

// Apply permissions middleware with applyMiddleware
// Giving any schema (instance of GraphQLSchema)

import { applyMiddleware } from 'graphql-middleware';
// schema definition...
schema = applyMiddleware(schema, permissions);
```

## API

### Types
Expand Down Expand Up @@ -214,7 +229,7 @@ const admin = bool =>
| ------------------- | -------- | ------- | ------------------------------------------- |
| allowExternalErrors | false | true | Toggles catching internal resolvers errors. |

By default `shield` ensures no internal data is exposed to client if it was not meant to be. Therfore, all thrown errors during execution resolve in `Not Authenticated!` error message if not otherwise specified using `CustomError`. This can be turned off by setting `allowExternalErrors` option to true.
By default `shield` ensures no internal data is exposed to client if it was not meant to be. Therefore, all thrown errors during execution resolve in `Not Authenticated!` error message if not otherwise specified using `CustomError`. This can be turned off by setting `allowExternalErrors` option to true.

### `allow`, `deny`

Expand Down Expand Up @@ -270,7 +285,7 @@ const permissions = shield({

### `Custom Errors`

Shield, by default, catches all errors thrown durign resolver execution. This way we can be 100% sure none of your internal logic will be exposed to the client if it was not meant to be.
Shield, by default, catches all errors thrown during resolver execution. This way we can be 100% sure none of your internal logic will be exposed to the client if it was not meant to be.

Nevertheless, you can use `CustomError` error types to report your custom error messages to your users.

Expand Down

0 comments on commit d4f4922

Please sign in to comment.