File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed
examples/operation-field-permissions Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 11import { useOperationFieldPermissions } from '@envelop/operation-field-permissions' ;
2- import { defineConfig } from '@graphql-hive/gateway' ;
2+ import { defineConfig , GatewayContext } from '@graphql-hive/gateway' ;
33
44export const gatewayConfig = defineConfig ( {
55 plugins : ( ) => [
66 useOperationFieldPermissions ( {
7- getPermissions ( ) {
8- return new Set ( [ 'Query.allowed' ] ) ;
7+ getPermissions ( ctx : GatewayContext ) {
8+ const auth = ctx . request . headers . get ( 'authorization' ) ;
9+ if (
10+ auth ===
11+ 'Bearer TOKEN' /** NOTE: proper token validity check goes here */
12+ ) {
13+ // allow all fields
14+ return new Set ( [ '*' ] ) ;
15+ }
16+ // allow only introspection
17+ return new Set ( [ 'Query.registrationOpen' ] ) ;
918 } ,
1019 } ) as any , // TODO: fix generic in envelop
1120 ] ,
Original file line number Diff line number Diff line change @@ -7,14 +7,17 @@ createServer(
77 schema : createSchema < any > ( {
88 typeDefs : /* GraphQL */ `
99 type Query {
10- allowed: String!
11- disallowed: String!
10+ registrationOpen: Boolean!
11+ me: User!
12+ }
13+ type User {
14+ name: String!
1215 }
1316 ` ,
1417 resolvers : {
1518 Query : {
16- allowed : ( ) => 'cool' ,
17- disallowed : ( ) => 'very not cool' ,
19+ registrationOpen : ( ) => false ,
20+ me : ( ) => ( { name : 'John' } ) ,
1821 } ,
1922 } ,
2023 } ) ,
You can’t perform that action at this time.
0 commit comments