extend schema
@link(
url: "https://specs.grafbase.com/grafbase"
import: ["InputValueSet", "UrlTemplate", "JsonTemplate"]
)
directive @natsPublish(
"""
The NATS provider to use
"""
provider: String! = "default"
"""
The subject to publish to
This supports templating using GraphQL arguments: {{args.argument}}
"""
subject: UrlTemplate!
"""
The body of the message to publish
"""
body: Body! = { selection: "*" }
) on FIELD_DEFINITION
directive @natsSubscription(
"""
The NATS provider to use
"""
provider: String! = "default"
"""
The subject to subscribe to
This supports templating using GraphQL arguments: {{args.argument}}
"""
subject: UrlTemplate!
"""
Selection to apply to the subscription payload. In jq syntax.
"""
selection: JsonTemplate
"""
Stream configuration for JetStream subscriptions
"""
streamConfig: NatsStreamConfiguration
) on FIELD_DEFINITION
directive @natsRequest(
"""
The NATS provider to use
"""
provider: String! = "default"
"""
The subject to publish to
This supports templating using GraphQL arguments: {{args.argument}}
"""
subject: UrlTemplate!
"""
Selection to apply to the subscription payload. In jq syntax.
"""
selection: JsonTemplate
"""
The body of the message to publish
"""
body: Body! = { selection: "*" }
"""
Timeout in milliseconds for the request. If the request does not
receive a response within this time, the request will fail with a
timeout error.
"""
timeoutMs: Int! = 5000
) on FIELD_DEFINITION
directive @natsKeyValue(
"""
The NATS provider to use
"""
provider: String! = "default"
"""
The bucket name to operate on
This supports templating using GraphQL arguments: {{args.argument}}
"""
bucket: UrlTemplate!
"""
The key name to operate on
This supports templating using GraphQL arguments: {{args.argument}}
"""
key: UrlTemplate!
"""
The key-value operation to perform
"""
action: NatsKeyValueAction!
"""
The body of the message to put or create (only used for PUT and
CREATE actions)
"""
body: Body = { selection: "*" }
"""
Selection to apply to the response payload. In jq syntax. (only
used for GET action)
"""
selection: UrlTemplate
) on FIELD_DEFINITION
"""
Available key-value operations for NATS KV
"""
enum NatsKeyValueAction {
"""
Create a new key-value pair. Fails if the key already exists.
"""
CREATE
"""
Put a value for the key, creating it if it doesn't exist or
updating it if it does.
"""
PUT
"""
Get the value for the specified key.
"""
GET
"""
Delete the specified key-value pair.
"""
DELETE
}
"""
Configuration for a NATS stream subscription
"""
input NatsStreamConfiguration {
"""
Stream name for the subscription, defines which stream to pull
messages from
"""
streamName: String!
"""
Consumer name for the subscription
"""
consumerName: String!
"""
Setting durable_name will cause this consumer to be “durable”.
This may be a good choice for workloads that benefit from the
JetStream server or cluster remembering the progress of
consumers for fault tolerance purposes. If a consumer crashes,
the JetStream server or cluster will remember which messages
the consumer acknowledged. When the consumer recovers, this
information will allow the consumer to resume processing where
it left off.
"""
durableName: String
"""
Description of the consumer
"""
description: String
"""
Delivery policy for the subscription
"""
deliverPolicy: NatsStreamDeliverPolicy! = { type: ALL }
"""
Threshold in milliseconds after which a consumer is considered
inactive
"""
inactiveThresholdMs: Int! = 30000
}
"""
Delivery policy configuration for NATS streams
"""
input NatsStreamDeliverPolicy {
"""
The type of delivery policy
"""
type: NatsStreamDeliverPolicyType!
"""
Starting sequence number for BY_START_SEQUENCE policy
"""
startSequence: Int
"""
Starting time in milliseconds for BY_START_TIME policy
"""
startTimeMs: Int
}
"""
Available delivery policy types for NATS streams
"""
enum NatsStreamDeliverPolicyType {
"""
All causes the consumer to receive the oldest messages
still present in the system. This is the default.
"""
ALL
"""
Last will start the consumer with the last sequence received.
"""
LAST
"""
New will only deliver new messages that are received by the
JetStream server after the consumer is created.
"""
NEW
"""
ByStartSeq will look for a defined starting sequence to the
consumer’s configured opt_start_seq parameter.
Set the start sequence number in the policy's startSequence
field. If not set, the consumer will start from the beginning.
"""
BY_START_SEQUENCE
"""
ByStartTime will select the first message with a
timestamp >= to the consumer’s configured opt_start_time
parameter.
Set the start time in the policy's startTimeMs field. If not
set, the consumer will start from the current time in UTC.
"""
BY_START_TIME
"""
LastPerSubject will start the consumer with the last message
for all subjects received.
"""
LAST_PER_SUBJECT
}
"""
Body configuration for NATS publish operations
"""
input Body {
"""
GraphQL selection to include in the message body
"""
selection: InputValueSet
"""
Static JSON content to include in the message body
"""
static: JSON
}
type NatsPublishResult {
success: Boolean!
}
nats0.4.1
Map NATS endpoints to GraphQL fields. Supports regular and JetStream subscriptions, as well as request/reply messaging and the key/value store.13 Mar, 2025
Tom HouléJulius de Bruijn
InstallAdd this to your TOML configuration file:
[extensions]
nats = "0.4.1"