-
Notifications
You must be signed in to change notification settings - Fork 5
Gradle GraphQL Schema Exploration Language
- Introduction
- Kobby Pattern
-
GSEL query syntax
- Schema Query
- Operation Query
-
Type Query
- enumValue
- field
- anyOverriddenField
- dependency
- anyScalarDependency
- anyObjectDependency
- anyInterfaceDependency
- anyUnionDependency
- anyEnumDependency
- subTypeDependency
- superTypeDependency
- argumentDependency
- anyScalarArgumentDependency
- anyEnumArgumentDependency
- anyInputArgumentDependency
- transitiveDependency
- minWeight
- maxWeight
The GraphQL Schema Exploration Language (GSEL) was developed to enable searching for fields in various GraphQL types based on a set of conditions. The Kobby plugin uses this language to truncate GraphQL schemas before generating DSL, as well as to serve as a GraphQL schema analysis tool.
Queries in this language look like this:
kobby {
schema {
analyze {
byQuery {
forType("Genre") {
// Select values 'COMEDY' and 'HORROR' in the 'Genre' enumeration.
include {
enumValue("COMEDY|HORROR")
}
}
forQuery {
// Select all 'Query' type fields except 'film' and 'films'.
exclude {
field("film")
field("films")
}
}
forMutation {
// Select all 'Mutation' type fields where one of the argument types is `FilmInput`.
include {
argumentDependency("FilmInput")
}
}
forAny {
// For any type, select all fields of type 'Country' or 'Film'.
include {
dependency("Country|Film")
}
}
}
}
}
}The GSEL query uses the Kobby pattern matching tool to find target types or fields. The Kobby pattern syntax is as follows: ↑
-
?- matches one character. -
*- matches zero or more characters. -
|- OR operator. -
__query- alias forQuerytype. -
__mutation- alias forMutationtype. -
__subscription- alias forSubscriptiontype. -
__root- alias forQuery,MutationandSubscriptiontypes. -
__any- alias for any type in the GraphQL schema. -
__anyScalar- alias for any scalar in the GraphQL schema. -
__anyObject- alias for any object in the GraphQL schema. -
__anyInterface- alias for any interface in the GraphQL schema. -
__anyUnion- alias for any union in the GraphQL schema. -
__anyEnum- alias for any enum in the GraphQL schema. -
__anyInput- alias for any input object in the GraphQL schema.
For example:
forType("__root|Actor*") {
include {
argumentDependency("__anyEnum|Film*")
}
}The GSEL query consists of 3 nested layers: ↑
-
Schema Query layer — responsible for searching types in a GraphQL schema (the
forXXXqueries). -
Operation Query layer — responsible for applying the type subquery to the target GraphQL type
(
includeandexcludeoperations). - Type Query layer — responsible for selecting fields in the target GraphQL type.
forType("Actor") { // Schema Query layer
include { // Operation Query layer
dependency("Country") // Type Query layer
}
}The GSEL query may contain multiple forXXX schema queries. In this case, the schema queries conditions are combined
using the "or" operator:
// Find the fields in the "Actor" type or in the "Movie" type.
forType("Actor") {
include {
dependency("Country")
}
}
forType("Film") {
include {
dependency("Country")
}
}To simplify this query, you can use the Kobby Pattern:
forType("Actor|Film") {
include {
dependency("Country")
}
}The part of the query that is responsible for selecting the GraphQL types in which to look for fields. ↑
fun forType(pattern: String) ↑
Apply the operation subquery to all types in the GraphQL schema that match the pattern.
forType("Actor") {
// Operation subquery
}fun forQuery() ↑
Apply the operation subquery to a Query type in the GraphQL schema. Synonym for forType("__query").
forQuery {
// Operation subquery
}fun forMutation() ↑
Apply the operation subquery to a Mutation type in the GraphQL schema. Synonym for forType("__mutation").
forMutation {
// Operation subquery
}fun forSubscription() ↑
Apply the operation subquery to a Subscription type in the GraphQL schema. Synonym for forType("__subscription").
forSubscription {
// Operation subquery
}fun forRoot() ↑
Apply the operation subquery to root types in the GraphQL schema - Query, Mutation and Subscription. Synonym for
forType("__root").
forRoot {
// Operation subquery
}fun forAny() ↑
Apply the operation subquery to any type in the GraphQL schema. Synonym for forType("__any").
forAny {
// Operation subquery
}fun forAnyObject() ↑
Apply the operation subquery to any object in the GraphQL schema. Synonym for forType("__anyObject").
forAnyObject {
// Operation subquery
}fun forAnyInterface() ↑
Apply the operation subquery to any interface in the GraphQL schema. Synonym for forType("__anyInterface").
forAnyInterface {
// Operation subquery
}fun forAnyUnion() ↑
Apply the operation subquery to any union in the GraphQL schema. Synonym for forType("__anyUnion").
forAnyUnion {
// Operation subquery
}fun forAnyEnum() ↑
Apply the operation subquery to any enum in the GraphQL schema. Synonym for forType("__anyEnum").
forAnyEnum {
// Operation subquery
}fun forAnyInput() ↑
Apply the operation subquery to any input object in the GraphQL schema. Synonym for forType("__anyInput").
forAnyInput {
// Operation subquery
}The part of the query responsible for applying the type subquery to the target GraphQL type. ↑
An "Operation Query" contains both include and exclude operation. The exclude operation excludes all fields that
match the include operation from the query result. If the include operation is not specified, the "include all"
operation is assumed to apply.
For example, this query will find all fields of type Film in the Query type and exclude the field named "films" from
the query results.
forType("__query") {
include {
dependency("Film")
}
exclude {
field("films")
}
}fun include() ↑
Apply the type subquery to a target GraphQL type. Put fields of the target type that match the subquery into the query result.
forType("Actor") {
include {
// Type subquery
}
}fun exclude() ↑
Apply the type subquery to a target GraphQL type. Put fields of the target type that do not match the subquery into the query result.
forType("Actor") {
exclude {
// Type subquery
}
}The part of the query that is responsible for selecting fields in the target GraphQL type. ↑
A "Type Query" may contain multiple conditions. In this case, the conditions are combined using the "or" operator:
forQuery { // For type Query
include {
field("country") // include a field named "country",
field("countries") // or a field named "countries",
dependency("Film") // or a field of type "Film"
dependency("Actor") // or a field of type "Actor"
}
}To simplify this query, you can use the Kobby Pattern:
forQuery {
include {
field("country|countries")
dependency("Film|Actor")
}
}fun enumValue(pattern: String) ↑
Select enum values whose name matches the pattern.
forType("Genre") {
exclude {
enumValue("DRAMA|COMEDY")
}
}fun field(pattern: String) ↑
Select fields whose name matches the pattern.
forQuery {
include {
field("country|countries")
}
}fun anyOverriddenField() ↑
Select fields that override any fields from the supertype.
forType("Actor") {
include {
anyOverriddenField()
}
}fun dependency(pattern: String) ↑
Select fields whose type matches the pattern.
forQuery {
include {
dependency("Film|Actor")
}
}fun anyScalarDependency() ↑
Select fields whose type is scalar. Synonym for dependency("__anyScalar").
forType("Film") {
exclude {
anyScalarDependency()
}
}fun anyObjectDependency() ↑
Select fields whose type is object. Synonym for dependency("__anyObject").
forType("Film") {
include {
anyObjectDependency()
}
}fun anyInterfaceDependency() ↑
Select fields whose type is interface. Synonym for dependency("__anyInterface").
forType("Country") {
include {
anyInterfaceDependency()
}
}fun anyUnionDependency() ↑
Select fields whose type is union. Synonym for dependency("__anyUnion").
forType("Country") {
include {
anyUnionDependency()
}
}fun anyEnumDependency() ↑
Select fields whose type is enum. Synonym for dependency("__anyEnum").
forType("Film") {
include {
anyEnumDependency()
}
}fun subTypeDependency(pattern: String) ↑
Select fields where one of the subtypes matches the pattern.
forAny {
include {
subTypeDependency("Actor|Film")
}
}fun superTypeDependency(pattern: String) ↑
Select fields where one of the supertypes matches the pattern.
forAny {
include {
superTypeDependency("Taggable|Native")
}
}fun argumentDependency(pattern: String) ↑
Select fields where one of the argument types matches the pattern.
forMutation {
include {
argumentDependency("ActorInput|FilmInput")
}
}fun anyScalarArgumentDependency() ↑
Select fields where one of the arguments is of type scalar. Synonym for argumentDependency("__anyScalar").
forType("Country") {
exclude {
anyScalarArgumentDependency()
}
}fun anyEnumArgumentDependency() ↑
Select fields where one of the arguments is of type enum. Synonym for argumentDependency("__anyEnum").
forMutation {
include {
anyEnumArgumentDependency()
}
}fun anyInputArgumentDependency() ↑
Select fields where one of the arguments is of type input object. Synonym for argumentDependency("__anyInput").
forMutation {
include {
anyInputArgumentDependency()
}
}fun transitiveDependency(pattern: String) ↑
Select fields where one of the transitive dependencies matches the pattern.
The transitive dependencies of a GraphQL field are all types (except scalars) returned by a query on that field, as well as the types of the field's arguments.
forAny {
include {
transitiveDependency("Tag")
}
}fun minWeight(minWeight: Int) ↑
Select fields whose weight is greater than or equal to the minWeight param.
The weight of a GraphQL type is the number of types (excluding scalars) that are available for querying on a field that returns the given type.
The weight of a GraphQL field is the weight of its type plus the weights of the types of its arguments.
forMutation {
include {
minWeight(9)
}
}fun maxWeight(maxWeight: Int) ↑
Select fields whose weight is less than or equal to the maxWeight param.
The weight of a GraphQL type is the number of types (excluding scalars) that are available for querying on a field that returns the given type.
The weight of a GraphQL field is the weight of its type plus the weights of the types of its arguments.
forMutation {
include {
maxWeight(9)
}
}