@link Directive

The @link directive connects external resources to your GQLForge configuration. Use it to import protobuf definitions, JavaScript handlers, TLS certificates, and more.

Fields

FieldTypeRequiredDescription
idStringNoAn identifier used to reference this linked resource elsewhere.
srcStringYesURL or local file path to the resource.
type_ofLinkTypeYesThe kind of resource being linked. See table below.
headers[Header]NoHTTP headers sent when fetching a remote src.
metaJSONNoArbitrary metadata attached to the link.
proto_paths[String]NoAdditional search paths for protobuf imports.
TypeDescription
ConfigAnother GQLForge configuration file to merge into the current schema.
ProtobufA .proto file defining gRPC service interfaces.
ScriptA JavaScript file providing custom resolver functions.
CertA TLS certificate file (PEM format).
KeyA TLS private key file (PEM format).
OperationA file containing persisted GraphQL operations.
HtpasswdAn htpasswd file for basic authentication.
JwksA JWKS endpoint or file for JWT validation.
GrpcA gRPC reflection endpoint for service discovery.
SqlA SQL file containing CREATE TABLE statements for schema definition.
PostgresA PostgreSQL connection URL (e.g. postgres://user:pass@host/db).
S3An S3 or S3-compatible endpoint URL for the @s3 directive.

Examples

Linking a JavaScript handler

schema @link(src: "./handlers.js", type_of: Script) @server(port: 8000) {
  query: Query
}

Linking a protobuf file

schema
@link(
  id: "news"
  src: "./news.proto"
  type_of: Protobuf
  proto_paths: ["./proto"]
)
@server(port: 8000) {
  query: Query
}

Linking a PostgreSQL database

schema
@link(type: Postgres, src: "postgres://user:password@localhost:5432/mydb")
@link(type: Sql, src: "./migrations/schema.sql")
@server(port: 8000) {
  query: Query
  mutation: Mutation
}

Linking multiple PostgreSQL databases

When connecting to multiple databases, each @link(type: Postgres) must have a unique id. Use the db field on @postgres to specify which connection to query.

schema
@link(id: "main", type: Postgres, src: "postgres://localhost:5432/main_db")
@link(id: "analytics", type: Postgres, src: "postgres://localhost:5432/analytics_db")
@server(port: 8000) {
  query: Query
}

Linking an S3 storage endpoint

schema
@link(id: "aws", type: S3, src: "https://s3.ap-northeast-1.amazonaws.com", meta: { region: "ap-northeast-1" })
@server(port: 8000) {
  query: Query
}

Linking a JWKS provider for authentication

schema @link(id: "jwks", src: "https://example.com/.well-known/jwks.json", type_of: Jwks) @server(port: 8000) {
  query: Query
}