1
- # graphql-directives
1
+ # graphql-directive
2
2
3
3
[ ![ Build Status] [ build-badge ]] [ build ]
4
4
[ ![ Code Coverage] [ coverage-badge ]] [ coverage ]
@@ -19,7 +19,7 @@ You can [learn more about directives in GraphQL documentation](http://graphql.or
19
19
## Install
20
20
21
21
``` sh
22
- npm install graphql-directives
22
+ npm install graphql-directive
23
23
```
24
24
25
25
## Steps
@@ -41,7 +41,7 @@ This code defines a directive called `dateFormat` that accepts one argument `for
41
41
The second step consists in adding a resolver for the custom directive .
42
42
43
43
```js
44
- import { addDirectiveResolveFunctionsToSchema } from 'graphql -directives '
44
+ import { addDirectiveResolveFunctionsToSchema } from 'graphql -directive '
45
45
46
46
// Attach a resolver map to schema
47
47
addDirectiveResolveFunctionsToSchema(schema, {
@@ -75,7 +75,7 @@ graphql(schema, query, rootValue).then(response => {
75
75
` addDirectiveResolveFunctionsToSchema ` takes two arguments, a GraphQLSchema and a resolver map. It modifies the schema in place by attaching directive resolvers. Internally your resolvers are wrapped into another one.
76
76
77
77
``` js
78
- import { addDirectiveResolveFunctionsToSchema } from ' graphql-directives '
78
+ import { addDirectiveResolveFunctionsToSchema } from ' graphql-directive '
79
79
80
80
const resolverMap = {
81
81
// Will be called when a @upperCase directive is applied to a field.
@@ -113,7 +113,7 @@ Text formatting is a good use case for directives. It can be helpful to directly
113
113
114
114
``` js
115
115
import { buildSchema } from ' graphql'
116
- import { addDirectiveResolveFunctionsToSchema } from ' graphql-directives '
116
+ import { addDirectiveResolveFunctionsToSchema } from ' graphql-directive '
117
117
118
118
// Schema
119
119
const schema = buildSchema (`
@@ -129,15 +129,15 @@ addDirectiveResolveFunctionsToSchema(schema, {
129
129
})
130
130
```
131
131
132
- [ See complete example] ( https://github.com/smooth-code/graphql-directives /blob/master/examples/upperCase.js )
132
+ [ See complete example] ( https://github.com/smooth-code/graphql-directive /blob/master/examples/upperCase.js )
133
133
134
134
### Date formatting: ` @dateFormat(format: String) `
135
135
136
136
Date formatting is a CPU expensive operation. Since all directives are resolved server-side, it speeds up your client and it is easily cachable.
137
137
138
138
``` js
139
139
import { buildSchema } from ' graphql'
140
- import { addDirectiveResolveFunctionsToSchema } from ' graphql-directives '
140
+ import { addDirectiveResolveFunctionsToSchema } from ' graphql-directive '
141
141
import format from ' date-fns/format'
142
142
143
143
// Schema
@@ -154,15 +154,15 @@ addDirectiveResolveFunctionsToSchema(schema, {
154
154
})
155
155
```
156
156
157
- [ See complete example] ( https://github.com/smooth-code/graphql-directives /blob/master/examples/dateFormat.js )
157
+ [ See complete example] ( https://github.com/smooth-code/graphql-directive /blob/master/examples/dateFormat.js )
158
158
159
159
### Authentication: ` @requireAuth `
160
160
161
161
Authentication is a very good usage of ` FIELD_DEFINITION ` directives. By using a directive you can restrict only one specific field without modifying your resolvers.
162
162
163
163
``` js
164
164
import { buildSchema } from ' graphql'
165
- import { addDirectiveResolveFunctionsToSchema } from ' graphql-directives '
165
+ import { addDirectiveResolveFunctionsToSchema } from ' graphql-directive '
166
166
167
167
// Schema
168
168
const schema = buildSchema (`
@@ -179,7 +179,7 @@ addDirectiveResolveFunctionsToSchema(schema, {
179
179
})
180
180
```
181
181
182
- [ See complete example] ( https://github.com/smooth-code/graphql-directives /blob/master/examples/requireAuth.js )
182
+ [ See complete example] ( https://github.com/smooth-code/graphql-directive /blob/master/examples/requireAuth.js )
183
183
184
184
## Limitations
185
185
@@ -195,11 +195,11 @@ addDirectiveResolveFunctionsToSchema(schema, {
195
195
196
196
MIT
197
197
198
- [ build-badge ] : https://img.shields.io/travis/smooth-code/graphql-directives .svg?style=flat-square
199
- [ build ] : https://travis-ci.org/smooth-code/graphql-directives
200
- [ coverage-badge ] : https://img.shields.io/codecov/c/github/smooth-code/graphql-directives .svg?style=flat-square
201
- [ coverage ] : https://codecov.io/github/smooth-code/graphql-directives
202
- [ version-badge ] : https://img.shields.io/npm/v/graphql-directives .svg?style=flat-square
203
- [ package ] : https://www.npmjs.com/package/graphql-directives
204
- [ license-badge ] : https://img.shields.io/npm/l/graphql-directives .svg?style=flat-square
205
- [ license ] : https://github.com/smooth-code/graphql-directives /blob/master/LICENSE
198
+ [ build-badge ] : https://img.shields.io/travis/smooth-code/graphql-directive .svg?style=flat-square
199
+ [ build ] : https://travis-ci.org/smooth-code/graphql-directive
200
+ [ coverage-badge ] : https://img.shields.io/codecov/c/github/smooth-code/graphql-directive .svg?style=flat-square
201
+ [ coverage ] : https://codecov.io/github/smooth-code/graphql-directive
202
+ [ version-badge ] : https://img.shields.io/npm/v/graphql-directive .svg?style=flat-square
203
+ [ package ] : https://www.npmjs.com/package/graphql-directive
204
+ [ license-badge ] : https://img.shields.io/npm/l/graphql-directive .svg?style=flat-square
205
+ [ license ] : https://github.com/smooth-code/graphql-directive /blob/master/LICENSE
0 commit comments