Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jdgabriel/basic-graphql-shield

Basic Graphql Shield with Apollo Server
https://github.com/jdgabriel/basic-graphql-shield

apollo-server graphql graphql-middleware graphql-server graphql-shield

Last synced: 10 days ago
JSON representation

Basic Graphql Shield with Apollo Server

Awesome Lists containing this project

README

        

# Basic GraphQL Shield

This repository is just the result of a [graphql-shield](https://github.com/jdgabriel/basic-graphql-shield) library study

### How to use and test yourself

```
git clone https://github.com/jdgabriel/basic-graphql-shield.git
yarn install
```

```
yarn dev
```

### Shield of grahpql-shield

All authentication is done through functions that define the user and their access level, if used.

##### FILE: ./src/permission

```javascript
// Import shield
import { shield } from 'graphql-shield';

// Import any custon rules
import isAuthenticated from './isAuthenticated';

export default shield({
Query: {
hello: isAuthenticated
}
});
```

##### FILE: ./src/permission/isAuthenticated

```javascript
// Import rule
import { rule } from 'graphql-shield';

export default rule()(async (parent, args, ctx, info) => {
return ctx.user !== null;
});
```

## Licence MIT

Gabriel Duarte