This repository was archived by the owner on Sep 3, 2021. It is now read-only.
File tree 4 files changed +1009
-187
lines changed
4 files changed +1009
-187
lines changed Original file line number Diff line number Diff line change
1
+ import { makeAugmentedSchema } from '../../src/index' ;
2
+ import { ApolloServer } from 'apollo-server' ;
3
+ import neo4j from 'neo4j-driver' ;
4
+
5
+ // JWT
6
+ // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJzY29wZXMiOlsicmVhZDp1c2VyIiwiY3JlYXRlOnVzZXIiXX0.jCidMhYKk_0s8aQpXojYwZYz00eIG9lD_DbeXRKj4vA
7
+
8
+ // scopes
9
+ // "scopes": ["read:user", "create:user"]
10
+
11
+ // JWT_SECRET
12
+ // oqldBPU1yMXcrTwcha1a9PGi9RHlPVzQ
13
+
14
+ const typeDefs = `
15
+ type User {
16
+ userId: ID!
17
+ name: String
18
+ }
19
+
20
+ type Business {
21
+ name: String
22
+ }
23
+ ` ;
24
+
25
+ const schema = makeAugmentedSchema ( {
26
+ typeDefs,
27
+ config : { auth : { hasScope : true } }
28
+ } ) ;
29
+
30
+ const driver = neo4j . driver (
31
+ 'bolt://localhost:7687' ,
32
+ neo4j . auth . basic ( 'neo4j' , 'letmein' )
33
+ ) ;
34
+
35
+ const server = new ApolloServer ( {
36
+ schema,
37
+ context : ( { req } ) => {
38
+ return {
39
+ req,
40
+ driver
41
+ } ;
42
+ }
43
+ } ) ;
44
+
45
+ server . listen ( ) . then ( ( { url } ) => {
46
+ console . log ( `GraphQL API ready at ${ url } ` ) ;
47
+ } ) ;
Original file line number Diff line number Diff line change 11
11
"start-interface" : " DEBUG=neo4j-graphql.js nodemon ./example/apollo-server/interface-union-example.js --exec babel-node -e js" ,
12
12
"start-gateway" : " nodemon ./example/apollo-federation/gateway.js --exec babel-node -e js" ,
13
13
"start-bookmark-example" : " nodemon ./example/apollo-server/bookmarks.js --exec babel-node -e js" ,
14
+ "start-auth-example" : " JWT_SECRET=oqldBPU1yMXcrTwcha1a9PGi9RHlPVzQ nodemon ./example/apollo-server/authScopes.js --exec babel-node -e js" ,
14
15
"build" : " babel src --presets @babel/preset-env --out-dir dist" ,
15
16
"build-with-sourcemaps" : " babel src --presets @babel/preset-env --out-dir dist --source-maps" ,
16
17
"precommit" : " lint-staged" ,
Original file line number Diff line number Diff line change @@ -251,10 +251,16 @@ export const buildAuthScopeDirective = ({ scopes = [] }) =>
251
251
name : buildName ( { name : 'scopes' } ) ,
252
252
value : {
253
253
kind : Kind . LIST ,
254
- values : scopes . map ( scope => ( {
255
- kind : Kind . STRING ,
256
- value : `${ scope . typeName } : ${ scope . mutation } `
257
- } ) )
254
+ values : scopes . flatMap ( scope => [
255
+ {
256
+ kind : Kind . STRING ,
257
+ value : `${ scope . typeName } : ${ scope . mutation } `
258
+ } ,
259
+ {
260
+ kind : Kind . STRING ,
261
+ value : `${ scope . mutation } :${ scope . typeName } ` . toLowerCase ( )
262
+ }
263
+ ] )
258
264
}
259
265
} )
260
266
]
You can’t perform that action at this time.
0 commit comments