---
schema_version: "1"
id: 6db123c15eb08414fa469cb4b8090e2363dc35529bb141997d5c1dfa02b19ddd
title: Running Queries and Mutations
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/datagraph/query-unified-schema.md
canonical_url: https://docs.mulesoft.com/datagraph/query-unified-schema
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 394c80298b15b14cbcc3207227bae11c201fb439e3d9e148c1edfbfc5d877c0c
description: MuleSoft Documentation Site
latest: true
---
---
product: DataGraph
---

# Running Queries and Mutations

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The unified schema resolves into a single GraphQL endpoint. To run queries or mutations against the
unified schema, you first request access (if applicable) and then write and run a GraphQL query in
the query editor.

## Before You Begin

- You must have [the Consume, Contribute, or Admin permission](https://docs.mulesoft.com/datagraph/permissions).

- Review [Anypoint DataGraph API Support](https://docs.mulesoft.com/datagraph/#anypoint-datagraph-api-support)

## Request Access to Run a Query

Before you can run a query or mutation, you must request access.

If you’re using an external client provider, refer to
[Request Access to Environments Using an External Client Provider](#request-access-to-environments-using-an-external-client-provider)

1.  Click **Run Operation**.

2.  In the **Request access to run queries** dialog, select how you want to get access to run your
    queries.

    If you want to use an existing client application or client ID and secret pair, you can find
    them in Exchange. Open Exchange in a new tab, navigate to **My applications** and select an
    application from the list to find relevant information.

    Choose one of the following options:

    - **Use one of my existing applications**: Choose an existing client application from the list,
      and click Request Access.

    - **Create a new application and use it immediately**: Click **Next**, provide an application
      name and an optional description and application URL, and click **Create and Request Access**.

    - **I already have credentials…​**: Click **Next**, provide an existing client ID and secret
      pair, and then click **Authenticate & Request Access**.

3.  To change your access method from the query editor, from the actions menu (**…​**), select
    **Switch Current Credentials**.

## Run a Query

Use the query editor to write, run, and troubleshoot queries.

1.  If any of the APIs in the unified schema require pass-through authentication, click **Add HTTP
    Headers**, and:

    1.  Select a header name.

    2.  Enter a header value.

    3.  To specify additional header name and value pairs for other APIs, click **+Add Header** x

    4.  Click **Save**.

    5.  To edit the HTTP headers, click **Edit HTTP Headers**.

2.  In the query editor, start typing your query using the in-line autocomplete function or type
    **Option/Alt + Shift + Space** to open the autocomplete menu.

    ![Using inline autocompletion to write a query](/mulesoft/current/en-us/datagraph/_images/datagraph-qsg-query-autocompletion.png)

3.  Optionally, in the **Query Variables** pane, add any query variables you want to use.

    ![Inserting a query variable in the query editor](/mulesoft/current/en-us/datagraph/_images/datagraph-query-variable.png)

4.  Click **Run**.

    ![Query editor displays query results](/mulesoft/current/en-us/datagraph/_images/datagraph-qsg-query-result.png)

5.  To see results with query tracing, from the actions menu (**…​**), select **Trace Query**, and
    then click **Run**.

    ![Query trace view open with query results](/mulesoft/current/en-us/datagraph/_images/datagraph-qsg-query-traces.png)

    Query trace results for DataGraph provide the following information:

    - Time taken by DataGraph to parse and validate the query

    - Total response time for the entire query

    - Duration of requests to each source API in the query

6.  To see response logs associated with the query, from the actions menu (**…​**), select **View
    Response Logs**.

    ![Query response logs page](/mulesoft/current/en-us/datagraph/_images/datagraph-qsg-response-logs.png)

    Log levels for DataGraph include DEBUG, INFO, WARN, and ERROR.

7.  Click **View History** to access this same query (or others) later.

8.  To use this query in your application, click **Copy endpoint** to copy the query and the
    automatically generated GraphQL endpoint. You can also copy the query as a curl snippet.

## Run a Mutation

Use the query editor to write and then run mutations. If needed, you can also troubleshoot mutations
in the query editor

1.  If any of the APIs in the unified schema require pass-through authentication, click **Add HTTP
    Headers** and:

    1.  Select a header name.

    2.  Enter a header value.

    3.  To specify additional header name and value pairs for other APIs, click **+Add Header**.

    4.  Click **Save**.

    5.  To edit the HTTP headers, click **Edit HTTP Headers**.

2.  In the query editor, start typing your mutation using the in-line autocomplete function, or type
    **Option/Alt + Shift + Space** to open the autocomplete menu.

    ![Using inline autocompletion to write a mutation](/mulesoft/current/en-us/datagraph/_images/datagraph-mutation-autocomplete.png)

3.  Optionally, in the **Query Variables** pane, add any variables you want to use.

4.  Click **Run**.

    ![Query editor displays mutation results](/mulesoft/current/en-us/datagraph/_images/datagraph-mutation-result.png)

5.  To see results with query tracing, from the actions menu (**…​**), select **Trace Query** and
    then click **Run**.

6.  To see response logs associated with the query, from the actions menu (**…​**), select **View
    Response Logs**.

7.  Click **View History** to access this same mutation (or other) later.

8.  To use this mutation in your application, click **Copy endpoint** to copy the query and the
    automatically generated GraphQL endpoint. You can also copy the query as a curl snippet.

## Query Editor Shortcuts

The following table provides shortcuts you can use in the query editor:

<table><colgroup><col> <col></colgroup><thead><tr><th>Function</th><th>Shortcut</th></tr></thead><tbody><tr><td><p>Prettify query</p></td><td><p>Shift+Ctrl+p</p></td></tr><tr><td><p>Run operation</p></td><td><p>Ctrl+Enter</p></td></tr><tr><td><p>Autocomplete</p></td><td><p>Ctrl+space</p></td></tr><tr><td><p>Comment-out line</p></td><td><p>Cmd+/</p></td></tr><tr><td><p>Jump to end or start of current scope</p></td><td><p>Cmd+m</p></td></tr><tr><td><p>Highlight current word</p></td><td><p>Cmd+d</p></td></tr><tr><td><p>Regex search</p></td><td><p>Cmd+f</p></td></tr><tr><td><p>Search and replace</p></td><td><p>Cmd+h</p></td></tr><tr><td><p>Bring next line up to current line</p></td><td><p>Cmd+j</p></td></tr><tr><td><p>Delete rest of line past cursor</p></td><td><p>Cmd+kk</p></td></tr><tr><td><p>Highlight current line</p></td><td><p>Cmd+l</p></td></tr><tr><td><p>Outdent current line</p></td><td><p>Cmd+[</p></td></tr><tr><td><p>Indent current line</p></td><td><p>Cmd+]</p></td></tr></tbody></table>

## Request Access to Environments Using an External Client Provider

API Manager enables you to configure different client providers for each one of your environments.
Depending on the environment where your data graph runs, your client applications might need to
authenticate using either the default Anypoint Platform native client provider or any of the
supported external client providers. See
[About Client Management](https://docs.mulesoft.com/access-management/managing-api-clients) for more information.

If you don’t configure any specific client provider for an environment, Anypoint Platform uses its
default and native client provider.

When your environment uses an external client provider, the **Request access** pop-up shows the
required and optional fields defined in the external client provider implementation.

For example, when querying the
`/api-federation/xapi/organizations/{organizationID}/environments/{environmentID}/type/federation/api/clientProvider/`
endpoint, returns the configured grant types for that environment:

```JSON
{
    "id": "aaaaaaaa-1a1a-1a1a-1a1a-aaaa1111aaa1",
    "name": "OpenAM",
    "typeName": "openam",
    "grantTypes": [
        {
            "name": "password",
            "label": "Resource Owner Grant",
            "depends": [],
            "exclude": [],
            "required": true (1)
        },
        {
            "name": "implicit",
            "label": "Implicit Grant",
            "depends": [],
            "exclude": [],
            "required": true (1)
        },
        {
            "name": "client_credentials",
            "label": "Client Credentials Grant",
            "depends": [],
            "exclude": [
                "authorization_code" (2)
            ],
            "required": false
        },
        {
            "name": "authorization_code",
            "label": "Authorization Code Grant",
            "depends": [],
            "exclude": [
                "client_credentials" (2)
            ],
            "required": false
        }
    ]
}
```

Those grant types properties are reflected in the UI when configuring access for a client:

![Requesting access using an external client provider](/mulesoft/current/en-us/datagraph/_images/confirm-credentials.png)

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Both <strong>Resource Owner Grant</strong> and <strong>Implicit Grant</strong> are marked as required in the UI.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Both <strong>Client Credentials Grant</strong> and <strong>Authorization Code Grant</strong> are mutually exclusive in the UI.</td></tr></tbody></table>

## Additional Resources

- [Writing GraphQL Queries and Mutations in DataGraph](https://docs.mulesoft.com/datagraph/write-queries-tutorial)

- [Anypoint DataGraph Troubleshooting](https://docs.mulesoft.com/datagraph/troubleshoot-schemas-queries)

- [Configure Multiple Client Providers for Client Management in API Manager](https://docs.mulesoft.com/api-manager/latest/configure-multiple-credential-providers)
