@GraphQLDataSource

Generates a resolver to fetch data from a GraphQL upstream service.
Directive Definition
directive @GraphQLDataSource (
"""
the host of the origin
"""
host: String!
"""
the url of the origin
"""
url: String!
"""
the HTTP method the client should use for the request, defaults to GET
"""
method: HTTP_METHOD = POST
"""
parameters
"""
params: [Parameter]
) on FIELD_DEFINITION
Example usage
type Query {
country(code: String!): Country
@GraphQLDataSource(
host: "countries.trevorblades.com"
url: "/"
field: "country"
params: [
{
name: "code"
sourceKind: FIELD_ARGUMENTS
sourceName: "code"
variableType: "String!"
}
]
)
}
‚Äč
type Country {
code: String
name: String
native: String
phone: String
continent: Continent
currency: String
languages: [Language]
emoji: String
emojiU: String
coordinates: [Coordinates]
@HttpJsonDataSource(
host: "locationiq.com"
url: "/v1/search_sandbox.php?format=json&q={{ .name }}&accept-language=en"
params: [
{
name: "name"
sourceKind: OBJECT_VARIABLE_ARGUMENT
sourceName: "name"
variableType: "String"
}
]
)
}
Example Query
{
country(code: "DE") {
code
name
}
}

This query will send the following query to the upstream service:

Example Query
{
country(code: "DE") {
code
name
}
}

As you can see in the example, nesting is possible. The "engine" assumes that all fields without a resolver belong to the parent/enclosing data source. Therefore if you nest a field and attach a new @directive this will generate a new resolver.