About GraphQL
GraphQL is an open-source query language for APIs, developed by Facebook as an alternative to REST API. It was publicly released in 2015 and is hosted by the Linux Foundation at GraphQL.org.
With GraphQL, you can perform various operations such as querying, creating, updating, and deleting data using mutations. Both queries and mutations follow the same syntax. Below are examples from GraphQL.org that demonstrate how queries and mutations are sent to a GraphQL server hosting information about Star Wars.
Examples
Example 1 - Query
Query
query HeroNameAndFriends { hero { name friends { name } } }
Show More
Result
{ "data":{ "hero":{ "name":"R2-D2", "friends":[ { "name":"Luke Skywalker" }, { "name":"Han Solo" }, { "name":"Leia Organa" } ] } } }
Show More
See this Tutorial on GraphQL queries for more information on queries.
Example 2 - Mutation
Mutation
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) { createReview(episode: $ep, review: $review) { stars commentary } } Variables: { "ep":"JEDI", "review":{ "stars":5, "commentary":"This is a great movie!" } }
Show More
Result
{ "data":{ "createReview":{ "stars":5, "commentary":"This is a great movie!" } } }
Show More
See this Tutorial on GraphQL mutations for more information on mutations.
When the schema of the data is known, you can query for and change the information in the exact shape the data is organized. Moreover, you will only fetch the data you need. In contrast, REST APIs respond with a predefined payload, regardless of whether you need all the information or not.
For more information on GraphQL, see:
The Manufacturing Data Model API provides a unified interface by federating multiple services. For example; to deal with Hubs, Projects and Folders, you typically would have to deal with the Data Management REST API. Manufacturing Data Model API, based on GraphQL service handles the interaction with Data Management, providing you with a unified API experience.
How to use the Manufacturing Data Model API
To use the Manufacturing Data Model API:
- Follow the instructions in the tutorial Create an App . When specifying details of the app:
- Specify
https://mfgdatamodel-explorer.autodesk.io/callback/oauth
for the Callback URL.
- Specify
- Obtain a 3-legged access token. See Before you begin for instructions on how to use Postman to obtain a 3-legged access token. Make sure that you specify the following scopes:
data:read data:create data:write data:search
- Send a POST request to POST https://developer.api.autodesk.com/fusiondata/2022-04/graphql, using the query as the request payload. Each request must contain an
Authorization
header, which must be set toBearer YOUR_ACCESS_TOKEN
, For example;
Request:
curl -v 'https://developer.api.autodesk.com/mfg/graphql' \ -X 'POST' \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "query": "query GetHubs { hubs{ pagination { cursor pageSize } results { id name } } }" "variables": {} }'
Show MoreResponse
{ "data": { "hubs": { "pagination": { "cursor": null, "pageSize": 3 }, "results": [ { "id": "a.YnVzaW5lc3M6YXV0b2Rlc2syNDQ3", "name": "UATTestingLinkHub" }, { "id": "a.YnVzaW5lc3M6YXV0b2Rlc2syMDA2", "name": "L2-Forge-Data-Team" }, { "id": "a.YnVzaW5lc3M6YXV0b2Rlc2syMzk4", "name": "stg-hds-test-hub" } ] } } }
Show More