Default Values

@default

When generating the input type for the create mutation, the value specified in this directive will be used as the default value for this field.

Definition

"""Int | Float | String | Boolean | ID | DateTime | Enum"""
scalar Scalar

"""Instructs @neo4j/graphql to set the specified value as the default value in the CreateInput type for the object type in which this directive is used."""
directive @default(
    """The default value to use. Must be a scalar type and must match the type of the field with which this directive decorates."""
    value: Scalar!,
) on FIELD_DEFINITION

Usage with Enums

@default may be used with enums. When setting the default value for an enum field, the value must be one of the enumerated enum values.

enum Location {
    HERE
    THERE
    EVERYWHERE
}

type SomeType {
    firstLocation: Location! @default(value: HERE) # valid usage
    secondLocation: Location! @default(value: ELSEWHERE) # invalid usage, will throw an error
}

@coalesce

When translating from GraphQL to Cypher, any instances of fields to which this directive is applied will be wrapped in a coalesce() function in the WHERE clause (see https://neo4j.com/developer/kb/understanding-non-existent-properties-and-null-values/#_use_coalesce_to_use_a_default_for_a_null_value). This helps to query against non-existent properties in a database, however it is encouraged to populate these properties with meaningful values if this is becoming the norm. This is a very primitive implementation of the function which only takes a static default value as opposed to using another property in a node or a Cypher expression.

Definition

"""Int | Float | String | Boolean | ID | DateTime | Enum"""
scalar ScalarOrEnum

"""Instructs @neo4j/graphql to wrap the property in a coalesce() function during queries, using the single value specified."""
directive @coalesce(
    """The value to use in the coalesce() function. Must be a scalar type and must match the type of the field with which this directive decorates."""
    value: Scalar!,
) on FIELD_DEFINITION

Usage with Enums

@coalesce may be used with enums. When setting the default value for an enum field, the value must be one of the enumerated enum values.

enum Status {
    ACTIVE
    INACTIVE
}
type Movie {
    status: Status @coalesce(value: ACTIVE)
}

@queryOptions

The @queryOptions is to be used on nodes, where applied will inject values into a query such as the limit.

Definition

"""The `@queryOptions` is to be used on nodes, where applied will inject values into a query such as the `limit`."""
directive @queryOptions(
    """If no limit argument is supplied on query will fallback to this value."""
    limit: {
        default: Int
        max: Int
    }
) on OBJECT

Limit

Limit has 2 arguments:

  • default - If no limit argument is passed to the query, the default limit will be used. The query may still pass a higher or lower limit.

  • max - Defines the maximum limit to be passed to the query. If a higher value is passed, this will be used instead. If no default value is set, max will be used for queries without limit.