GraphQL API Mapping
The GraphQL API Mapping function type maps functions to GraphQL API endpoints.
It is defined like this:
type: graphql-api-mapping
mapping:
query: |
query GetContacts($limit: Int, $cursor: String) {
contacts(first: $limit, after: $cursor) {
edges {
node {
id
firstName
lastName
email
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
variables:
limit: 100
cursor:
$var: $.cursor
responseMapping:
records:
$var: response.data.contacts.edges[*].nodeFormat
query– The GraphQL query or mutation stringvariables– Variables mapping for the GraphQL queryresponseMapping– Mapping to transform the GraphQL response
Variables
credentials– Authentication credentials from the current connectionparameters– Function-level and collection-level parameters combined- Function-specific input variables
For responseMapping:
response.data– GraphQL response dataresponse.errors– GraphQL response errors (if any)response.extensions– GraphQL response extensions (if any)
Using in Connector Files
When used in connector files, the mapping is written in a separate file named <function-name>.graphql.yml.
For example:
# "list" function of the "Contacts" data collection.
# File location: data/contacts/list.graphql.yml
query: |
query GetContacts($limit: Int, $cursor: String) {
contacts(first: $limit, after: $cursor) {
edges {
node {
id
firstName
lastName
email
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
variables:
limit: 100
cursor:
$var: $.cursor
responseMapping:
records:
$var: response.data.contacts.edges[*].node
cursor:
$cond:
- $var: response.data.contacts.pageInfo.hasNextPage
- $var: response.data.contacts.pageInfo.endCursor
- nullUpdated about 1 month ago
