Skip to main content

Injections

Injection is a mechanism to get the value of a parameter from other sources than the graphql query. When a parameter is injected, no value is expected in the query, otherwise, the query will fail. They are specified at the type level for input types that are direct children of a t.struct.

Static

Description: Static injection sets a static value to the parameter.

Method: .set(value)

Parameter: The value to be set, it must be compatible with the target type.

Parent

Description: Parent injection gets the value output of a sibling field (source) in the parent struct. It adds a dependency to the sibling field, so make sure to prevent circular dependencies. Additionally, it requires that the source type is a subtype of the target type.

Note: the parent struct is relative to the function in which the current type is an input.

Method: .from_parent(key)

Parameter: The name (key) of the source field in the parent struct.

Context

Description: Context injection gets the value from the request context that contains authentication data.

Method: .from_context(prop_name)

Parameter: The name or jsonpath of the property in the context.

Secret

Description: Secret injection gets the value from the secrets defined when deploying the typegraph.

Method: .from_secret(secret_name)

Parameter: The name of the secret.

Dynamic

Description: Dynamic injection gets the value from a predefined generator evaluated at runtime.

Method: .inject(generator_name)

Parameter: The name of the generator.

Available generators:

  • now: produces the current datetime as a valid ISO string format. This value depends on the configuration of the typegate host machine.

Example

Loading...