@scalarType binds a scalar to a constant you write. @generatedScalar asks Graphitron to generate the scalar itself, for a kind it knows. The scalar’s name is yours; kind says what it is. A scalar takes @scalarType or @generatedScalar, not both: the two together are CLAIMS_CONFLICT.

SDL signature

directive @generatedScalar(kind: GeneratedScalarKind!) on SCALAR

enum GeneratedScalarKind { SCHEMA_PATH TYPE_NAME }

Parameters

Name Type Description

kind

GeneratedScalarKind!

What a value of the scalar is: SCHEMA_PATH, a path through this subgraph’s schema, or TYPE_NAME, the name of one of its object types.

Kinds and components

On the wire every generated scalar is a string. Inside the generated code a value is decoded into a record of its components, and a call takes the components it needs by naming them in argMapping, as it takes a key column from a node id.

Kind A value is Components

TYPE_NAME

the name of an object type in this subgraph, as __typename gives it: Sak, SoknadLevert

text, name

SCHEMA_PATH

a type name followed by zero or more field names, separated by dots: Soknad, Sak.soker, Soknad.saker.nodes

text, startType, path, endType

Every kind has text, the value as it was provided. A path’s components, for three values:

Value text startType path endType

Sak.soker

Sak.soker

Sak

soker

Soker

Soknad.saker.nodes

Soknad.saker.nodes

Soknad

saker.nodes

Sak

Soknad

Soknad

Soknad

the empty string

Soknad

A path follows the schema exactly as clients see it: each field must exist on the type the previous step reached, lists and non-null wrappers are stepped through, a connection is stepped through with nodes or edges.node, and arguments are not part of a path. Its start type is its first name, an object or interface type. Its end type is the named type its last field returns, which may be an interface or a union, or the start type when there is no field. A union has no fields, so a path cannot step past one.

Canonical example

scalar Path @generatedScalar(kind: SCHEMA_PATH)

input OpprettAutomatiskUtsendingInput {
    kontekststi: Path! @assertType(component: "startType", type: {implements: "Hendelse"})
    mottakersti: Path!
        @assertType(component: "startType", type: {implements: "Node"})
        @assertType(component: "endType", type: {is: "Soker"})
}

type Mutation {
    opprettAutomatiskUtsending(input: OpprettAutomatiskUtsendingInput!): UtsendingPayload
        @routine(name: "opprett_automatisk_utsending", argMapping: """
            pKontekststi: input.kontekststi.text,
            pKontekstStart: input.kontekststi.startType,
            pKontekstSlutt: input.kontekststi.endType,
            pMottakerStart: input.mottakersti.startType,
            pMottakerSlutt: input.mottakersti.endType
        """)
}

With mottakersti: "Soknad.soker" the function receives 'Soknad' and 'Soker' as the recipient path’s start and end types, and compares type names without knowing the schema. The requirements are @assertType's.

Where a value is checked

A value is decoded where a call takes one of its components: a root or child @service, and a @routine writing on the mutation root. The decode runs before the call and any transaction, against the schema the service actually serves, so a type or field added or removed by a schema customizer counts as served, and the federation and introspection types, whose names start with _, are never a value. The argument’s @assertType requirements run right after.

When a value is wrong, the field answers a client error at the argument’s path, as a malformed node id does, and nothing is called. The message names the argument and what is wrong:

input.mottakersti: Soknad has no field sokr
input.mottakersti: the path's endType `Saksbehandler` is not `Soker`

Route it to your payload with an @error type handling GraphitronClientException, as for node ids. On a child @service the decode runs in the field’s own fetcher, so a wrong value fails that field alone.

A null or absent value is not checked and hands every component as null.

Constraints

  • A value reaches a call only as a component named in argMapping. Binding it whole, by a parameter’s name or type, through an input object a call takes whole, as a column a @mutation writes, as a filter, a tenant or an @outbox key, is GENERATED_SCALAR_BOUND_WHOLE, since only a component binding is decoded and checked.

  • An argument or input field of one that no call takes is GENERATED_SCALAR_UNDECODED, so no @assertType is ever silently skipped. Where another code already says nothing takes it, ARGUMENT_UNBOUND under a @service, COLUMN_UNRESOLVED on a filter naming no column or MEMBER_UNKNOWN under a class its input object is built into, that code speaks instead.

  • A name past the scalar that is none of its kind’s components is ARGMAPPING_PATH_UNRESOLVED.

  • A parameter takes the component’s class, a String for every component today; another is PARAMETER_MISMATCH, at a routine judged against the function’s parameter type.

  • A list of these scalars, or one read through a list of input objects, is not supported yet: GENERATED_SCALAR_LIST_UNSUPPORTED.

  • A component bound at a @condition, at a @routine step of a field’s path or at a @routine read on the query root is not supported yet: GENERATED_SCALAR_SITE_UNSUPPORTED.

As output

A field of a generated scalar reads a string column, or a @service returning a String, and returns it as stored, without checking, since a stored value may predate a schema change. A column jOOQ binds to another class than String holds no such text, so a field of the scalar reading one is GENERATED_SCALAR_COLUMN_NOT_TEXT. A @service is judged by its method’s return type, as any other.

Only this subgraph

A value can only name types this subgraph serves. A type owned by another subgraph is reachable only through a local stub of it.