Skip to content

Commit 10bc0e9

Browse files
Merge pull request #18 from MacondoExpress/filterable-doc
add documentation of the filterable directive
2 parents dc1a495 + 162aeae commit 10bc0e9

File tree

2 files changed

+151
-1
lines changed

2 files changed

+151
-1
lines changed

modules/ROOT/pages/reference/directives/index.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ The `@exclude` directive is used on object types to instruct them to be skipped
4848

4949
Reference: xref::reference/directives/schema-configuration/type-configuration.adoc#_exclude_deprecated[`@exclude`]
5050

51+
== `@filterable`
52+
53+
The `@filterable` directive defines the filters generated for a field.
54+
55+
Reference: xref:reference/directives/schema-configuration/field-configuration.adoc#_filterable[`@filterable`]
56+
5157
== `@fulltext`
5258

5359
The `@fulltext` directive indicates that there should be a Fulltext index inserted into the database for the specified Node and its properties.

modules/ROOT/pages/reference/directives/schema-configuration/field-configuration.adoc

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Actor {
3030
}
3131
----
3232

33-
By using the directives `@selectable`, `@settable`, and `@relationship` it is possible to control how these fields are exposed.
33+
By using the directives `@selectable`, `@settable`, `@filterable` and `@relationship` it is possible to control how these fields are exposed.
3434
For instance, to hide the field `age` in the Selection Set, you can use the `@selectable` directive:
3535

3636
[source, graphql, indent=0]
@@ -395,6 +395,150 @@ input ActorUpdateInput {
395395

396396
This means the `actedIn` can be updated on an update, but it will not be available on create operations.
397397

398+
== `@filterable`
399+
400+
This directive defines the filters generated for the field to which this directive is applied.
401+
It has two arguments:
402+
403+
* **byValue**: If disabled, this field will not generate value filters.
404+
* **byAggregate**: If disabled, this field will not generate aggregation filters.
405+
406+
=== Definition
407+
408+
[source, graphql, indent=0]
409+
----
410+
"""Instructs @neo4j/graphql to generate filters for this field."""
411+
directive @filterable(byValue: Boolean! = true, byAggregate: Boolean! = true) on FIELD_DEFINITION
412+
----
413+
414+
==== Usage
415+
416+
With this definition:
417+
418+
[source, graphql, indent=0]
419+
----
420+
type Movie {
421+
title: String!
422+
description: String @filterable(byValue: false, byAggregate: false)
423+
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
424+
}
425+
426+
type Actor {
427+
name: String!
428+
actedIn: [Movie!]!
429+
@relationship(type: "ACTED_IN", direction: OUT)
430+
}
431+
----
432+
433+
The following input fields will be generated:
434+
435+
[source, graphql, indent=0]
436+
----
437+
input MovieWhere {
438+
OR: [MovieWhere!]
439+
AND: [MovieWhere!]
440+
NOT: MovieWhere
441+
title: String
442+
title_IN: [String!]
443+
title_CONTAINS: String
444+
title_STARTS_WITH: String
445+
title_ENDS_WITH: String
446+
actorsAggregate: MovieActorsAggregateInput
447+
actors_ALL: ActorWhere
448+
actors_NONE: ActorWhere
449+
actors_SINGLE: ActorWhere
450+
actors_SOME: ActorWhere
451+
actorsConnection_ALL: MovieActorsConnectionWhere
452+
actorsConnection_NONE: MovieActorsConnectionWhere
453+
actorsConnection_SINGLE: MovieActorsConnectionWhere
454+
actorsConnection_SOME: MovieActorsConnectionWhere
455+
}
456+
457+
input ActorActedInNodeAggregationWhereInput {
458+
AND: [ActorActedInNodeAggregationWhereInput!]
459+
OR: [ActorActedInNodeAggregationWhereInput!]
460+
NOT: ActorActedInNodeAggregationWhereInput
461+
title_AVERAGE_LENGTH_EQUAL: Float
462+
title_LONGEST_LENGTH_EQUAL: Int
463+
title_SHORTEST_LENGTH_EQUAL: Int
464+
title_AVERAGE_LENGTH_GT: Float
465+
title_LONGEST_LENGTH_GT: Int
466+
title_SHORTEST_LENGTH_GT: Int
467+
title_AVERAGE_LENGTH_GTE: Float
468+
title_LONGEST_LENGTH_GTE: Int
469+
title_SHORTEST_LENGTH_GTE: Int
470+
title_AVERAGE_LENGTH_LT: Float
471+
title_LONGEST_LENGTH_LT: Int
472+
title_SHORTEST_LENGTH_LT: Int
473+
title_AVERAGE_LENGTH_LTE: Float
474+
title_LONGEST_LENGTH_LTE: Int
475+
title_SHORTEST_LENGTH_LTE: Int
476+
}
477+
----
478+
479+
As shown by the generated input fields, the `description` field is not available for filtering on both value and aggregation filters.
480+
481+
=== `@filterable` with Relationships
482+
483+
This directive can be used along with relationship fields.
484+
When an operation on a field is disabled this way, that relationship will not be available on top-level operations.
485+
For example:
486+
487+
[source, graphql, indent=0]
488+
----
489+
type Movie {
490+
title: String!
491+
description: String @filterable(byValue: false, byAggregate: false)
492+
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN) @filterable(byValue: false, byAggregate: false)
493+
}
494+
495+
type Actor {
496+
name: String!
497+
actedIn: [Movie!]!
498+
@relationship(type: "ACTED_IN", direction: OUT)
499+
500+
}
501+
----
502+
503+
The following input fields will be generated:
504+
505+
[source, graphql, indent=0]
506+
----
507+
input MovieWhere {
508+
OR: [MovieWhere!]
509+
AND: [MovieWhere!]
510+
NOT: MovieWhere
511+
title: String
512+
title_IN: [String!]
513+
title_CONTAINS: String
514+
title_STARTS_WITH: String
515+
title_ENDS_WITH: String
516+
}
517+
518+
input ActorActedInNodeAggregationWhereInput {
519+
AND: [ActorActedInNodeAggregationWhereInput!]
520+
OR: [ActorActedInNodeAggregationWhereInput!]
521+
NOT: ActorActedInNodeAggregationWhereInput
522+
title_AVERAGE_LENGTH_EQUAL: Float
523+
title_LONGEST_LENGTH_EQUAL: Int
524+
title_SHORTEST_LENGTH_EQUAL: Int
525+
title_AVERAGE_LENGTH_GT: Float
526+
title_LONGEST_LENGTH_GT: Int
527+
title_SHORTEST_LENGTH_GT: Int
528+
title_AVERAGE_LENGTH_GTE: Float
529+
title_LONGEST_LENGTH_GTE: Int
530+
title_SHORTEST_LENGTH_GTE: Int
531+
title_AVERAGE_LENGTH_LT: Float
532+
title_LONGEST_LENGTH_LT: Int
533+
title_SHORTEST_LENGTH_LT: Int
534+
title_AVERAGE_LENGTH_LTE: Float
535+
title_LONGEST_LENGTH_LTE: Int
536+
title_SHORTEST_LENGTH_LTE: Int
537+
}
538+
----
539+
540+
As shown by the above inputs fields, the `actors` field is not available for filtering on both value and aggregation filters.
541+
398542
== `@readonly` label:deprecated[]
399543

400544
With this directive, fields will only be featured in mutations for creating and in object types for querying.

0 commit comments

Comments
 (0)