Contact Us 1-800-596-4880

Test Your GraphQL Project

logo cloud IDE Cloud IDE

logo desktop IDE Desktop IDE

Open Beta Release: The cloud IDE is in open beta. Any use of Anypoint Code Builder in its beta state is subject to the applicable beta services terms and conditions, available from the IDE.

Before making changes to your GraphQL project, run the application locally within the IDE to test the endpoints.

Before You Begin

Run Your Application

To deploy your Mule Application locally, within the IDE, run a debug session in Anypoint Code Builder:

  1. In Anypoint Code Builder, open the Books Implementation project.

  2. Click the (Run and Debug) icon in the activity bar, then click the Start Debugging (F5) icon.

  3. From your IDE, open the Terminal window in the console:

    • In the desktop IDE, select View > Terminal.

    • In the cloud IDE, click the (menu) icon, and select Terminal > New Terminal.

    • For either IDE: Press Ctrl and then press the backtick key (`).

  4. In the terminal, open a new command prompt by clicking the plus (+) icon, for example:

    Opening command prompt from Terminal

    Alternatively, select a command shell, such as bash, by clicking the v menu (inverted caret), located beside the plus (+) icon, and selecting the shell to use.

    Opening bash prompt from Terminal

  5. Run the following curl command from the shell’s prompt to trigger the bookById flow:

    curl --request POST \
    --location 'http://localhost:8081/graphql' \
    --header 'Content-Type: application/json' \
    --data '{
      "query": "query bookById($id: ID) {bookById(id: $id){ id name pageCount author{ id firstName lastName}}}",
      "variables": {
        "id": 1
      }
    }'

    If you receive the error curl: (7) Failed to connect to localhost port 8081 after 0 ms: Couldn’t connect to server, stop and rerun the application in debug mode. For guidance with stopping the application, see Debugging Mule Applications.

    Tools such as Postman provide a way to build GraphQL queries. For example, in Postman, you can place your query in the Body tab and find the code snippet for a curl request. The resulting command includes newline (\\n) and tab (\\t) characters that you can delete from the curl command’s --data value. For more information, see Make an HTTP call with GraphQL in the Postman documentation.

    Anypoint Code Builder returns the following output in the terminal (manually reformatted to enhance readability):

    { "data": {
                "bookById": {
                              "id":"#myID",
                              "name":"This is some example data",
                              "pageCount":100,
                              "author": {
                                          "id":"urn:uuid:123e4567-e89b-12d3-a456-426655440000",
                                          "firstName":"This is some example data",
                                          "lastName":"Hello World!"
                                        }
                            }
              }
    }

    The mock data in the output comes from strings in the Set Payload component that is part of the Query.bookById flow (<flow name="Query.bookById"/>):

    <set-payload value="{&#xa;  &quot;id&quot;: &quot;some-id&quot;,&#xa;
      &quot;name&quot;: &quot;This is some example data&quot;,&#xa;
      &quot;pageCount&quot;: -2,&#xa;  &quot;author&quot;: {&#xa;    &quot;id&quot;:
      &quot;urn:uuid:123e4567-e89b-12d3-a456-426655440000&quot;,&#xa;
      &quot;firstName&quot;: &quot;This is some example data&quot;,&#xa;
      &quot;lastName&quot;: &quot;This is some example data&quot;&#xa;  }&#xa;}"
      mimeType="application/json"/>
  6. Optionally, try queries for other endpoints:

    1. Query the books endpoint with the following curl command:

      curl --location 'http://localhost:8081/graphql' \
      --header 'Content-Type: application/json' \
      --data '{"query":"query books { books{  id  name  pageCount  author{ id firstName lastName  } }}","variables":{}}'

      This command returns the following result (manually reformatted to enhance readability):

      { "data": {
                  "books": [{
                               "id":"urn:uuid:123e4567-e89b-12d3-a456-426655440000",
                                "name":"This is some example data",
                                "pageCount":1,
                                "author": {
                                             "id":"urn:uuid:123e4567-e89b-12d3-a456-426655440000",
                                             "firstName":"This is some example data",
                                             "lastName":"Hello World!"
                                          }
                           }]
                 }
      }

      For your reference, the books endpoint has the following structure:

      query books {
      	books{
      		id
      		name
      		pageCount
      		author{
      			id
      			firstName
      			lastName
      		}
      	}
      }
    2. Query bestSellers:

      curl --location 'http://localhost:8081/graphql' \
      --header 'Content-Type: application/json' \
      --data '{"query":"query bestsellers { bestsellers{  books{   id   name   pageCount   author{    id    firstName    lastName   }  }  authors{   id   firstName   lastName  } } }","variables":{}}'

      This command returns the following result (manually reformatted to enhance readability):

      { "data" : {
                   "bestsellers": {
                                    "books": [{
                                                "id":"#myID",
                                                "name":"This is some example data",
                                                "pageCount":1,
                                                "author": {
                                                            "id":"urn:uuid:123e4567-e89b-12d3-a456-426655440000",
                                                            "firstName":"This is some example data",
                                                            "lastName":"Hello World!"
                                                          }
                                              },
                                              {
                                                "id":"some-id",
                                                "name":"Goodbye",
                                                "pageCount":100,
                                                "author": {
                                                            "id":"urn:uuid:123e4567-e89b-12d3-a456-426655440000",
                                                            "firstName":"This is some example data",
                                                            "lastName":"Hello World!"
                                                          }
                                              },
                                              {
                                                "id":"urn:uuid:123e4567-e89b-12d3-a456-426655440000",
                                                "name":"Hello World!",
                                                "pageCount":-10,
                                                "author": {
                                                            "id":"urn:uuid:123e4567-e89b-12d3-a456-426655440000",
                                                            "firstName":"This is some example data",
                                                            "lastName":"Hello World!"
                                                          }
                                              }],
                                    "authors": [{
                                                  "id":"urn:uuid:123e4567-e89b-12d3-a456-426655440000",
                                                  "firstName":"Hello World!",
                                                  "lastName":"Hello World!"
                                                },
                                                {
                                                  "id":"#myID",
                                                  "firstName":"Goodbye",
                                                  "lastName":"Goodbye"
                                                }]
                                  }
                 }
      }

      For your reference, the bestsellers endpoint has the following structure:

      query bestsellers {
      	bestsellers{
      		books{
      			id
      			name
      			pageCount
      			author{
      				id
      				firstName
      				lastName
      			}
      		}
      		authors{
      			id
      			firstName
      			lastName
      		}
      	}
      }
  7. Proceed to Configure Responses for Your GraphQL Implementation to populate each flow with a custom response for each query.