Objective: To demonstrate how to limit CRUD operations on components specifically to the Sandbox Environment.
Difficulty: Intermediate
In this article:
- Get the Sandbox Library ID
- Querying Components
- Updating Components
- Deleting Components
- Creating Components
A safe way to experiment with the Duro GraphQL API is to execute API operations within your Sandbox Environment as opposed to your Production Environment. This document demonstrates how to restrict CRUD operations on components to a personal Sandbox.
Get the Sandbox library ID
Both environments, the Production Environment and the Sandbox Environment, grant access to distinct libraries: your company library and your testing library, respectively. The 'libraries' query furnishes information encompassing both these libraries. In the context of libraries, a crucial attribute is the type
field, distinguished by values of "GENERAL" for the company library and "PERSONAL" for the Sandbox library. Utilize the Sandbox library ID when creating a component to ensure its addition to the Sandbox library.
Request
Operation
libraries {
connection(first: $first) {
edges {
node {
id
name
type
}
}
}
}
Variables
{
"first": 10,
}
Response
In the results below, the library named “Mark Org” is the company library, and the library named “Mark” is a personal Sandbox.
"data": {
"libraries": {
"connection": {
"edges": [
{
"node": {
"id": "64b9af636eee57951f9421af",
"name": "Mark Org",
"type": "GENERAL"
}
},
{
"node": {
"id": "64b9af636eee57951f9421b0",
"name": "Mark",
"type": "PERSONAL"
}
}
]
}
}
}
}
Querying Components
By default the components
query will retrieve components from the Company (“GENERAL”) library. To retrieve components from the Sandbox (“PERSONAL”) library instead, we set the libraryType
argument to “PERSONAL."
Request
Operation
query Components($first: Int, $libraryType: LibraryType) {
components(libraryType: $libraryType) {
connection(first: $first) {
edges {
node {
id
name
mass
library {
type
}
}
}
}
}
}
Variables
{
"first": 1,
"libraryType": "PERSONAL",
}
Response
"data": {
"components": {
"connection": {
"edges": [
{
"node": {
"id": "64bc3e9be3eb523dc0c07e2d",
"name": "CONN HEADER 10POS DUAL .05, Keying Shroud",
"mass": 33,
"library": {
"type": "PERSONAL"
}
}
}
]
}
}
}
}
Updating Components
When sending an updateComponent
request, we can avoid mutations to components in the company library by only using the component ID of components in the Sandbox.
Request
Operation
mutation UpdateComponent($input: UpdateComponentInput) {
updateComponent(input: $input) {
id
name
mass
library {
name
type
}
}
}
Variables
{
"input": {
"id": "64bc3e9be3eb523dc0c07e2d",
"mass": 21.4
}
}
Response
{
"data": {
"updateComponent": {
"id": "64bc3e9be3eb523dc0c07e2d",
"name": "CONN HEADER 10POS DUAL .05\", Keying Shroud, SMD",
"mass": 21.4,
"library": {
"name": "Mark",
"type": "PERSONAL"
}
}
}
}
Deleting Components
When sending a deleteComponent
request, we can avoid deleting components in the company library by only using the component ID of components in the Sandbox.
Request
Operation
mutation DeleteComponent($input: DeleteInput) {
deleteComponent(input: $input) {
id
archived
name
library {
type
name
}
}
}
Variables
{
"input": {
"id": "64bc3e9be3eb523dc0c07e2d"
}
}
Response
{
"data": {
"deleteComponent": {
"id": "64bc3e9be3eb523dc0c07e2d",
"archived": true,
"name": "CONN HEADER 10POS DUAL .05\", Keying Shroud, SMD",
"library": {
"type": "PERSONAL",
"name": "Mark"
}
}
}
}
Creating Components
By default, the createComponent
mutation will create a component in the company library. To create a component in a Sandbox library instead, set the libraryID
argument to that of the Sandbox.
Note: The createComponent
API request will not allow a component to be created in a Sandbox library if the company library already contains a component with that name.
Request
Operation
mutation CreateComponent($input: CreateComponentInput) {
createComponent(input: $input) {
id
archived
name
category
library {
type
name
}
}
}
Variables
{
"input": {
"category": "Gasket",
"name": "Great Gasket",
"libraryId": "64b9af636eee57951f9421b0"
},
}
Response
{
"data": {
"createComponent": {
"id": "64e4068dece648fb75fc535a",
"archived": false,
"name": "Great Gasket",
"category": "Gasket",
"library": {
"type": "PERSONAL",
"name": "Mark"
}
}
}
}
For more information on how to use APIs in Duro, please visit our Quick Start Guide to using Duro's GraphQL API.
Comments
0 comments
Please sign in to leave a comment.