Using embeddable fields

πŸ“£ Note: This functionality will be available soon.

Resolve a field within an argument for another field from the same type, or within directive arguments, using syntax {{ fieldName }}.

Field echoStr is also added on every type of the schema, to make it convenient to use:

query {
posts {
description: echoStr(value: "The title is '{{ title }}'")
}
}

The embedded field can include arguments, using syntax {{ fieldName(fieldArgs) }}. When an input is of type String, the quotes must be escaped (becoming \"):

query {
posts {
description: echoStr(value: "The date is '{{ date(\"d/m/Y\") }}'")
}
}

Embedding fields enables to fetch more data with a shorter query, and avoid manipulating the data in the client to give it the desired shape.

Examples permalink

Compose a string containing the values from several fields:

query {
posts {
description: echoStr(value: "'{{ title }}' was posted on {{ date }}")
}
}

Change the title of the post, depending on the post having comments or not:

query {
posts {
title: echoStr(
value: "({{ commentCount }}) {{ title }} - posted on {{ date }}"
) @include(if: "{{ hasComments }}")
title
@skip(if: "{{ hasComments }}")
}
}

Retrieve the posts containing the user's email:

query {
users {
email
posts(searchfor: "{{ email }}") {
id
title
content
}
}
}

Combined with nested mutations, send an email to many users, personalizing the content for each:

mutation {
customers(expiringDays: 7) {
sendEmail(
subject: "Hey {{ name }}, your account will expire in 1 week!",
content: "Click here to extend your service: {{ userAccountURL }}"
)
}
}

Send a single email to many users, adding them all in the to field:

mutation {
users {
id @sendEmail(
to: "{{ email }}",
subject: "You are awesome!",
content: "We just wanted to remind you of that :)"
)
}
}

GraphQL spec permalink

This functionality is currently not part of the GraphQL spec, but a related one has been requested: