reuse::partial$beta-banner.adoc
Publish a GraphQL API schema to Anypoint Exchange. Then use Anypoint Code Builder to import and scaffold the schema into a Mule application. Run and implement the interface.
Complete these procedures:
-
Set up your MuleSoft environment. See start-acb.adoc for more information.
-
Download the Books API GraphQL schema.
Alternatively, create a file namedbooks-api.graphqlwith the following content:schema { query: Query } type Query { bookById(id: ID): Book books: [Book] bestsellers: Bestsellers } type Book { id: ID! name: String pageCount: Int author: Author } type Author { id: ID! firstName: String lastName: String } type Bestsellers { books: [Book] authors: [Author] }
To implement a GraphQL API, the API must first be manually published to Exchange:
-
Navigate to Anypoint Exchange, and sign in.
-
Click Publish new asset.
-
For Name, type
books-api. -
For Asset types, select GraphQL API.
-
For Method, select Upload a GraphQL API Schema:
-
For File upload, click Choose file and browse for your
books-api.graphqlschema file. -
For Lifecycle state, select Stable.
-
Click Publish.
Use Anypoint Code Builder to retrieve the schema from Anypoint Exchange and scaffold the schema into an interface that you can implement from the desktop or cloud IDE.
-
Open Anypoint Code Builder. partial$acb-reusable-steps.adoc
-
Provide the following command:
MuleSoft: Implement an API Specification
-
If prompted to sign in to Anypoint Platform, click Allow, and follow the prompts to sign in.
-
Configure your project using the following values:
-
Project Name:
books-implementation -
Project Location: click Browse, and then select your home directory.
-
Search for your books-api specification in Exchange by typing
booksand pressing Return to display the results. -
In the search results, hover over books-api, and click the Add Asset button that appears:
-
Provide Mule runtime and Java versions.
-
-
Click Create Project.
-
If prompted, trust the authors of the API specification.
Trusting is required before you can work on the project from the IDE.
After you trust the authors, Anypoint Code Builder scaffolds your GraphQL API and creates a project with an empty flow for each type in your Books API GraphQL schema.
GraphQL Schema Mule Flow type Query { bookById(id: ID): Book books: [Book] bestsellers: Bestsellers } type Book { id: ID! name: String pageCount: Int author: Author } type Author { id: ID! firstName: String lastName: String } type Bestsellers { books: [Book] authors: [Author] }
<flow name="Query.bookById"/> <flow name="Query.books"/> <flow name="Query.bestsellers"/> <flow name="Book.author"/> <flow name="Bestsellers.books"/> <flow name="Bestsellers.authors"/>
Each flow contains configurations for the elements
<graphql-router:data-fetcher/>,<set-payload/>, and ` <graphql-router:serialize/>`. The<graphql-router:data-fetcher>element serves as a trigger for a flow. See apikit::apikit-graphql-api-mapping.adoc for more information about data fetchers. -
Proceed to tut-graphql-test-first-implementation.adoc to run your application in Anypoint Code Builder and post GraphQL queries to your endpoint.


