Custom Directives
@rename¶
# Directive used to rename a type or field when registration with Data Api
directive @rename(to: String!) on FIELD_DEFINITION | OBJECT | INTERFACE
@resolver¶
# @resolver directive definition
directive @resolver(field: String, arguments: [ResolverArgument!]) on FIELD_DEFINITION
# Input type for @resolver arguments.
input ResolverArgument {
name : String!
value : String!
}
It defines the target field, its arguments and argument values. Under the hood, this will call the backend service that owns the target field.
field¶
This parameter defines the path of the target field. The target field should be owned by a data provider that is already registered in GraphQL Orchestrator. It has the following syntax
{rootField}.{childField1}.{childField2}...{targetField}
where it forms a path from rootField to targetField.
arguments¶
the targetField can have zero or more arguments. This is an array of ResolverArgument
where
each defines
- argument name. This should match an argument name of the targetField
- argument value. The value should conform to Input Values syntax.
Examples¶
-
target field without parameters
extend type User { allPets : Pet @resolver(field: "allPets") }
-
target field with scalar type argument
extend type User { pet : Pet @resolver(field: "petById" arguments: [{name : "id", value: "$petId"}]) }
where $petId is a variable reference to
petId
field in typeUser
.Note: During execution, parent field will be resolved first. In this example, will call User service. The User object/field will be resolved first before resolving the child fields. Thus guarantees that petId will have value.
-
target field with object argument
Let's say that the target field argument is
type Query { petById(petId: PetId): Pet } input PetId { id: ID }
One can define @resolver like
extend type User { petById : Pet @resolver(field: "petById" arguments: [{name : "petId", value: "{id : \"$petId\"}"}]) }
where
$petId
is a variable reference to a field of typeUser
See Usage