@@ -236,7 +236,7 @@ export const gatewayConfig = defineConfig({
236
236
},
237
237
plugins : () => [
238
238
useOperationFieldPermissions ({
239
- getPermissions : async context => {
239
+ getPermissions : context => {
240
240
const { jwt } = context
241
241
242
242
// Check based on identity / user-id.
@@ -257,6 +257,48 @@ export const gatewayConfig = defineConfig({
257
257
})
258
258
```
259
259
260
+ ### Allowing Introspection
261
+
262
+ If you want to allow introspection queries to be executed without a JWT token, you can use the
263
+ operation field permissions plugin to allow only introspection queries when no JWT token ispresent.
264
+ This way, you can still introspect the schema and explore the API without a token, while protecting
265
+ the rest of the API with JWT authentication.
266
+
267
+ <Callout >
268
+ Be careful with this approach, as it allows anyone to introspect your schema without a token. We
269
+ always advise using [ Persisted Documents] ( /docs/gateway/persisted-documents ) to fully secure your
270
+ GraphQL API.
271
+ </Callout >
272
+
273
+ ``` ts filename="gateway.config.ts"
274
+ import { useOperationFieldPermissions } from ' @envelop/operation-field-permissions'
275
+ import { defineConfig } from ' @graphql-hive/gateway'
276
+
277
+ export const gatewayConfig = defineConfig ({
278
+ jwt: {
279
+ ... options ,
280
+ reject: {
281
+ // allow requests with missing token to introspect the schema
282
+ missingToken: false
283
+ }
284
+ },
285
+ plugins : () => [
286
+ useOperationFieldPermissions ({
287
+ getPermissions : context => {
288
+ const { jwt } = context
289
+ if (! jwt ) {
290
+ // allow only introspection if no token is present
291
+ return new Set ([' Query.__schema' , ' Query.__type' , ' Query.__typename' ])
292
+ }
293
+ // allow everything when token is present, or you can return a different
294
+ // set of permissions based on the token like in the previous example
295
+ return ' *'
296
+ }
297
+ })
298
+ ]
299
+ })
300
+ ```
301
+
260
302
### In upstream GraphQL subgraphs
261
303
262
304
<Tabs items = { [' GraphQL-Yoga' , ' Apollo Server' , ' Other GraphQL servers' ]} >
0 commit comments