Skip to Content

WunderGraph Directives Overview

Published: 2022-05-23

Directives are a way of configuring the behaviour of your API straight from the Operation Definition.

Here's an example using two handy directives:

mutation (
$name: String! @fromClaim(name: NAME)
$email: String! @fromClaim(name: EMAIL)
$message: String! @jsonSchema(
pattern: "^[a-zA-Z 0-9]+$"
)
){
createOnepost(data: {message: $message user: {connectOrCreate: {where: {email: $email} create: {email: $email name: $name}}}}){
id
message
user {
id
name
}
}
}

This example uses the @fromClaim directive to inject Claims into the operation. Additionally, it's using the @jsonSchema directive to set a Regex pattern for the $message variable.

@fromClaim Directive#

Using this directive, you're able to inject Claims into an Operation. (read more)

@jsonSchema Directive#

With this directive, you're able to configure input validation rules for the Operation. (read more)

@hooksVariable Directive#

The hooksVariable Directive can be used to define variables specifically for hooks. (read more)

@rbac Directive#

Via the rbac Directive, you can attach role based access control rules to Operations. (read more)

@injectGeneratedUUID Directive#

The injectGeneratedUUID Directive allows you to inject a UUID into a variable definition. (read more)

@injectCurrentDateTime Directive#

The injectCurrentDateTime Directive makes it possible to inject the current date and time in any format into a variable. (read more)

@injectEnvironmentVariable Directive#

The injectEnvironmentVariable Directive lets you inject variables from the server Environment into an Operation. (read more)

@internalOperation Directive#

The internalOperation Directive marks Operations as internal only, making them accessible only from the hooks environment. (read more)

@export Directive#

Using the export Directive, you can export field values into variables and use them to JOIN another Query field. (read more)

@internal Directive#

When exporting a field to use it later as a foreign key for a JOIN, the @internal directive should be used to mark the field as internal. (read more)

@transform Directive#

The transform Directive allows you to transform the response of an Operation. (read more)


Product

Comparisons

Subscribe to our newsletter!

Stay informed when great things happen! Get the latest news about APIs, GraphQL and more straight into your mailbox.

© 2022 WunderGraph