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
}
}'
Test Your GraphQL Implementation
With a scaffolded project, run your application locally and test the endpoints of your Mule application.
Note that because the GraphQL schema does not allow examples, Anypoint Code Builder scaffolds an empty project, so in this first run, your responses are empty.
Before You Begin
Complete these procedures:
-
Set up your MuleSoft environment.
See Getting Started with Anypoint Code Builder for more information.
-
Implement the Books API GraphQL Schema.
Run Your Application
To locally deploy your Mule Application, run a debug session in Anypoint Code Builder:
-
In Anypoint Code Builder, open the Books Implementation project.
-
Click the (Run and Debug) icon in the activity bar, then click the Start Debugging (F5) icon.
-
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 (`).
-
-
In the IDE’s terminal, use the
curl
command, and create aPOST
request to the local address, adding the/graphql
path:http://localhost:8081/graphql
:For more information about using the
curl
command in the terminal, see Trigger a flow. -
Send the
curl
request.Anypoint Code Builder returns an empty field for the book:
{ "data": { "bookById": null } }
Other queries you can try for your endpoint are:
-
Query
books
:query books { books{ id name pageCount author{ id firstName lastName } } }
-
Query
bestSellers
:query bestsellers { bestsellers{ books{ id name pageCount author{ id firstName lastName } } authors{ id firstName lastName } } }
These requests return an empty result.
-
-
Proceed to Configure Responses for Your GraphQL Implementation to populate each flow with a custom response for each query.