About GraphQL
GraphQL is a set of API technologies developed by Facebook as an alternative to REST. It was released to the public in 2015 as an open-source project, and is hosted by the Linux Foundation at GraphQL.org. They also host the OpenAPI specification, which is the preferred standard for describing REST APIs.
GraphQL can be thought of as a query language for APIs. You request data with queries. You create, update, and delete data with mutations. Queries and mutations follow the same syntax. The following examples taken from GraphQL.org show a query and a mutation are sent to a GraphQL server that hosts information about Star Wars.
Examples
Example 1 - Query
Query
query HeroNameAndFriends {
hero {
name
friends {
name
}
}
}
Result
{
"data":{
"hero":{
"name":"R2-D2",
"friends":[
{
"name":"Luke Skywalker"
},
{
"name":"Han Solo"
},
{
"name":"Leia Organa"
}
]
}
}
}
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!"
}
}
Result
{
"data":{
"createReview":{
"stars":5,
"commentary":"This is a great movie!"
}
}
}
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:
- Verify that the Data Management API, Model Derivative API, and Webhooks API are selected under API Access.
- Specify
http://localhost:8080/
for the Callback URL, .
- 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
- 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/fusiondata/2022-04/graphql' \ -X 'POST' \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "query": "query { hubs { results { name } } }", "variables": {} }'
Show MoreResponse
{ "data": { "hubs" : { "results" : [ { "name" : "Autodesk-Platform-Services" }, { "name" : "ME-FLC" }, { "name" : " Forge-Data-Team" }, { "name" : "PIM-ME-Release" } ] } } }
Show More