Skip to content

Commit 100f49f

Browse files
committed
docs(examples): converted from e2es
1 parent c2019b4 commit 100f49f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

examples/operation-field-permissions/gateway.config.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import { useOperationFieldPermissions } from '@envelop/operation-field-permissions';
2-
import { defineConfig } from '@graphql-hive/gateway';
2+
import { defineConfig, GatewayContext } from '@graphql-hive/gateway';
33

44
export 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
],

examples/operation-field-permissions/services/users.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}),

0 commit comments

Comments
 (0)