Skip to content

Commit e263499

Browse files
committed
improve docs
1 parent 17a849e commit e263499

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
11
# GraphQL Authentication Prisma
22

3-
TODO
3+
A Prisma adapter for [Graphql Authentication](https://github.com/Volst/graphql-authentication/blob/master/README.md).
4+
5+
# Install
6+
7+
Node v8+ should be used. Install with Yarn or npm:
8+
9+
```
10+
yarn add graphql-authentication graphql-authentication-prisma email-templates
11+
npm i graphql-authentication graphql-authentication-prisma email-templates
12+
```
13+
14+
# Usage with Prisma
15+
16+
## Step 1
17+
18+
In your Prisma `datamodel.graphql` file, add this [User model](./example/datamodel.graphql).
19+
20+
## Step 2
21+
22+
In your `schema.graphql` for your own server, add something like the following (you can also import specific endpoints only):
23+
24+
```graphql
25+
# import Query.*, Mutation.* from "node_modules/graphql-authentication/schema.graphql"
26+
```
27+
28+
## Step 3
29+
30+
In your server we now need to map these types to resolvers and pass in some options. The following example uses [graphql-yoga](https://github.com/graphcool/graphql-yoga/), but it should also work with Apollo Server.
31+
32+
```js
33+
import { authQueries, authMutations, graphqlAuthenticationConfig } from 'graphql-authentication';
34+
import { GraphqlAuthenticationPrismaAdapter } from 'graphql-authentication-prisma';
35+
import * as Email from 'email-templates';
36+
37+
const resolvers = {
38+
Query: {
39+
...authQueries
40+
},
41+
Mutation: {
42+
...authMutations
43+
}
44+
};
45+
46+
const server = new GraphQLServer({
47+
typeDefs: './schema.graphql',
48+
resolvers,
49+
context: req => ({
50+
...req,
51+
db: new Prisma({...}),
52+
graphqlAuthentication: graphqlAuthenticationConfig({
53+
adapter: new GraphqlAuthenticationPrismaAdapter(),
54+
// Required, used for signing JWT tokens
55+
secret: 'wheredidthesodago',
56+
// Optional, for sending emails with email-templates (https://www.npmjs.com/package/email-templates)
57+
mailer: new Email(),
58+
// Optional, the URL to your frontend which is used in emails
59+
mailAppUrl: 'http://example.com',
60+
})
61+
})
62+
});
63+
```
64+
65+
## Step 4
66+
67+
Lastly, if you want to send emails, you should copy the email templates to your own project. Checkout [the example email templates](./example/emails).
68+
69+
### [Full Documentation](https://github.com/Volst/graphql-authentication/blob/master/README.md#documentation)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# GraphQL Authentication
2+
3+
A very opinionated user authentication package for [GraphQL](https://graphql.org/). It uses old-school email/password authentication.
4+
5+
This package does not access your data layer (e.g. an ORM); for that you need to write a _adapter_ (which is not hard to do).
6+
If you use Prisma, there is already an adapter for you, **[graphql-authentication-prisma](https://github.com/Volst/graphql-authentication/tree/master/packages/graphql-authentication-prisma)**.
7+
8+
### [Full Documentation](https://github.com/Volst/graphql-authentication/blob/master/README.md)

0 commit comments

Comments
 (0)