GraphQL Query Example

In organizations where customer relationship management (CRM) systems are used to optimize sales processes, it is common for support teams to rely on separate systems for their activities. To provide effective assistance, the support team must have access to up-to-date information from the CRM system. This can include:

  • Contact Information: Key details such as email, phone number, and name.
  • Deal Information: Data on ongoing deals, including deal name, expected revenue and deal stages.
  • Metadata of the fields fetched from Contacts and Deals module.

You can use GraphQL for querying these details in a single API call to create a unified view for the support team.

Sample Input

Copiedquery {
  Records {
    Contacts(where: { Email: { equals: "krismarrier@nmail.com" } }) {
      _data {
        Email {
          value
        }
        Full_Name {
          value
        }
       Phone {
          value
        }
        Deals__r {
          _data {
            Expected_Revenue {
              value
            }
            Deal_Name {
              value
            }
            Stage {
              value
            }
          }
        }
      }
    }
  }
  contact_meta: Meta {
    Modules(filter: { api_name: "Contacts" }) {
      _data {
        plural_label
        id
        api_name
        module_name
        description
        singular_label
        fields(filter: { api_names: ["Last_Name", "Email"] }) {
          _data {
            id
            api_name
            display_label
            json_type
            data_type
          }
        }
      }
    }
  }
  deal_meta: Meta {
    Modules(filter: { api_name: "Deals" }) {
      _data {
        plural_label
        id
        api_name
        module_name
        description
        singular_label
        fields(
          filter: { api_names: ["Expected_Revenue", "Deal_Name", "Stage"] }
        ) {
          _data {
            api_name
            id
            display_label
            json_type
            data_type
          }
        }
      }
    }
  }
}

Sample Response

Copied{
    "data": {
        "Records": {
            "Contacts": {
                "_data": [
                    {
                        "Email": {
                            "value": "krismarrier@nmail.com"
                        },
                        "Full_Name": {
                            "value": "Kris Marrier"
                        },
                        "Phone": {
                            "value": "555-555-5555"
                        },
                        "Deals__r": {
                            "_data": [
                                {
                                    "Expected_Revenue": {
                                        "value": null
                                    },
                                    "Deal_Name": {
                                        "value": "King"
                                    },
                                    "Stage": {
                                        "value": "Identify Decision Makers"
                                    }
                                },
                                {
                                    "Expected_Revenue": {
                                        "value": null
                                    },
                                    "Deal_Name": {
                                        "value": "ABC corp"
                                    },
                                    "Stage": {
                                        "value": "Qualification"
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        },
        "contact_meta": {
            "Modules": {
                "_data": [
                    {
                        "plural_label": "Contacts",
                        "id": "5843104000000002179",
                        "api_name": "Contacts",
                        "module_name": "Contacts",
                        "description": null,
                        "singular_label": "Contact",
                        "fields": {
                            "_data": [
                                {
                                    "id": "5843104000000002491",
                                    "api_name": "Last_Name",
                                    "display_label": "Last Name",
                                    "json_type": "string",
                                    "data_type": "text"
                                },
                                {
                                    "id": "5843104000000002497",
                                    "api_name": "Email",
                                    "display_label": "Email",
                                    "json_type": "string",
                                    "data_type": "email"
                                }
                            ]
                        }
                    }
                ]
            }
        },
        "deal_meta": {
            "Modules": {
                "_data": [
                    {
                        "plural_label": "Deals",
                        "id": "5843104000000002181",
                        "api_name": "Deals",
                        "module_name": "Deals",
                        "description": null,
                        "singular_label": "Deal",
                        "fields": {
                            "_data": [
                                {
                                    "api_name": "Deal_Name",
                                    "id": "5843104000000002559",
                                    "display_label": "Potential Name",
                                    "json_type": "string",
                                    "data_type": "text"
                                },
                                {
                                    "api_name": "Stage",
                                    "id": "5843104000000002565",
                                    "display_label": "Stage",
                                    "json_type": "string",
                                    "data_type": "picklist"
                                },
                                {
                                    "api_name": "Expected_Revenue",
                                    "id": "5843104000000031001",
                                    "display_label": "Expected Revenue",
                                    "json_type": "double",
                                    "data_type": "currency"
                                }
                            ]
                        }
                    }
                ]
            }
        }
    }
}

We have covered this example in detail in this Kaizen post: Kaizen #149: Using GraphQL APIs to fetch data in a consolidated way.

For more examples of GraphQL query, refer these pages: