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[*].node

Format

  • query – The GraphQL query or mutation string
  • variables – Variables mapping for the GraphQL query
  • responseMapping – Mapping to transform the GraphQL response

Variables

  • credentials – Authentication credentials from the current connection
  • parameters – Function-level and collection-level parameters combined
  • Function-specific input variables

For responseMapping:

  • response.data – GraphQL response data
  • response.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
      - null