@@ -489,83 +489,7 @@ as your execution strategy as it has the support for the reactive-streams APIs.
489489
490490See http://www.reactive-streams.org/ for more information on the reactive `` Publisher `` and `` Subscriber `` interfaces.
491491
492- Also see the page on subscriptions for more details on how to write a subscription based graphql service.
493-
494-
495- # Limiting Field Visibility
496-
497- By default every fields defined in a ` GraphqlSchema ` is available. There are cases where you may want to restrict certain fields
498- depending on the user.
499-
500- You can do this by using a ` graphql.schema.visibility.GraphqlFieldVisibility ` implementation and attaching it to the schema.
501-
502- A simple ` graphql.schema.visibility.BlockedFields ` implementation based on fully qualified field name is provided.
503-
504- {{< highlight java "linenos=table" >}}
505-
506- GraphqlFieldVisibility blockedFields = BlockedFields.newBlock()
507- .addPattern("Character.id")
508- .addPattern("Droid.appearsIn")
509- .addPattern(".*\\.hero") // it uses regular expressions
510- .build();
511-
512- GraphQLSchema schema = GraphQLSchema.newSchema()
513- .query(StarWarsSchema.queryType)
514- .fieldVisibility(blockedFields)
515- .build();
516-
517- {{< / highlight >}}
518-
519-
520- There is also another implementation that prevents instrumentation from being able to be performed on your schema, if that is a requirement.
521-
522- Note that this puts your server in contravention of the graphql specification and expectations of most clients so use this with caution.
523-
524-
525- {{< highlight java "linenos=table" >}}
526-
527- GraphQLSchema schema = GraphQLSchema.newSchema()
528- .query(StarWarsSchema.queryType)
529- .fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY)
530- .build();
531-
532- {{< / highlight >}}
533-
534- You can create your own derivation of ` GraphqlFieldVisibility ` to check what ever you need to do to work out what fields
535- should be visible or not.
536-
537- {{< highlight java "linenos=table" >}}
538-
539- class CustomFieldVisibility implements GraphqlFieldVisibility {
540-
541- final YourUserAccessService userAccessService;
542-
543- CustomFieldVisibility(YourUserAccessService userAccessService) {
544- this.userAccessService = userAccessService;
545- }
546-
547- @Override
548- public List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) {
549- if ("AdminType".equals(fieldsContainer.getName())) {
550- if (!userAccessService.isAdminUser()) {
551- return Collections.emptyList();
552- }
553- }
554- return fieldsContainer.getFieldDefinitions();
555- }
556-
557- @Override
558- public GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName) {
559- if ("AdminType".equals(fieldsContainer.getName())) {
560- if (!userAccessService.isAdminUser()) {
561- return null;
562- }
563- }
564- return fieldsContainer.getFieldDefinition(fieldName);
565- }
566- }
567-
568- {{< / highlight >}}
492+ Also see the page on [ subscriptions] ( ../subscriptions ) for more details on how to write a subscription based graphql service.
569493
570494
571495## Query Caching
0 commit comments