Skip to content

Commit

Permalink
fix(docs): Extended README example
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed May 26, 2018
1 parent 5b2ba6a commit dc19de5
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GraphQL Shield helps you create permission layer for your application. Using int
* 馃 **Compatible:** Works with all GraphQL Servers.
* 馃殌 **Blazing fast:** Intelligent V8 Shield engine caches all your request to prevent anything from being called too many times.
* 馃幆 **Per-Type:** Write permissions for your schema, types or specific fields (check the example below).
* 馃挴 **Tested:** Very well [tested](https://github.com/maticzav/graphql-shield/tree/master/tests) functionalities!
* 馃挴 **Tested:** Very well [tested](https://github.com/maticzav/graphql-shield/tree/master/test.js) functionalities!

## Install

Expand Down Expand Up @@ -56,6 +56,41 @@ const typeDefs = `
}
`

const resolvers = {
Query: {
frontPage: () => [{name: "orange", count: 10}, {name: "apple", count: 1}]
}
}

// Auth

const users = {
mathew: {
id: 1,
name: "Mathew"
role: "admin"
},
george: {
id: 2,
name: "George",
role: "editor"
},
johnny: {
id: 3,
name: "Johnny",
role: "customer"
}
}

function getUser(req) {
const auth = req.get('Authorization')
if (users[auth]) {
return users[auth]
} else {
return null
}
}

// Rules

const isAuthenticated = rule()(async (parent, args, ctx, info) => {
Expand Down Expand Up @@ -90,6 +125,10 @@ const server = GraphQLServer({
typeDefs,
resolvers,
middlewares: [permissions],
context: req => ({
...req,
user: getUser(req)
})
})

server.start(() => console.log('Server is running on http://localhost:4000'))
Expand Down

0 comments on commit dc19de5

Please sign in to comment.