Hi @Amerehei,
Thanks for the clarification of the use case you are trying to solve.
While we don’t currently support passing arbitrary JSON-LD contexts by URL, and don’t have the ability to validate against the schema published by schema.org, we do support using vocab or inline context to create namespaces to help avoid collisions.
For example:
When creating the following trait:
mutation ($workspace: String!, $id:String!) { traits: updateTraits(workspaceId:$workspace, id:$id, input: { context: "http://schema.org/", content: {isTemplate: 1} })}
When using create or update a trait using schema.org context, you would create a trait at http://schema.org/isTemplate which actually has no definition on schema.org and would not validate. The context
doesn’t define the schema, it only maps short property names to entities in a schema, it only helps with avoiding collisions.
Options to manage JSON-LD traits
- Use vocab to create your own namespace:
mutation ($workspace: String!, $id:String!) { traits: updateTraits(workspaceId:$workspace, id:$id, input: {vocab: "http://schema.company.org/", content: {isTemplate: 1}}) }
This will put your traits in your own namespace: http://schema.company.org/isTemplate
where it would not collide with anything in schema.org
You can then query to look for isTemplate
in http://schema.company.org namespace:
#query to return elements with matching vocab namespace:
query filterTraits($workspaceId: String!, $queryTraits:TraitInput!){
elements(workspaceId: $workspaceId, traits:$queryTraits) {
__typename
id
traits
transform {
x
y
scaleX
scaleY
}
}
}
with variables using the previous vocab: http://schema.company.org/
{
"workspaceId": "{{workspaceID}}",
"queryTraits":{ "context":{
"@vocab": "http://schema.company.org/"
},"content":{"isTemplate":1} }
}
- Use an inline context:
#update element JSON-LD traits metadata with inline
mutation ($workspace: String!, $id:String!) {
traits: updateTraits(workspaceId:$workspace, id:$id, input: {context: { isTemplate: "http://schema.company.org/isTemplate"}, content: {isTemplate: 1}})
}
You can then query to look for elements with TraitInput
:
#query to return elements with matching trait data:
query filterTraits($workspaceId: String!, $queryTraits:TraitInput!){
elements(workspaceId: $workspaceId, traits:$queryTraits) {
__typename
id
traits
transform {
x
y
scaleX
scaleY
}
}
}
with variables with inline context:
{
"workspaceId": "{{workspaceID}}",
"queryTraits":{"context":{"isTemplate":"http://schema.company.org/isTemplate"}, "content":{"isTemplate":1} }
}
note the response that there are multiple namespaces to avoid collisions:
{
"data": {
"elements": [
{
"__typename": "Shape",
"id": "6516afa810aa3624fc2df6c8",
"traits": {
"http://schema.company.org/testTraits": 1,
"http://schema.org/testTraits": 1,
"http://schema.foo.org/testTraits": 1,
"http://foo.org/testTraits": 1,
"http://schema.bar.org/testTraits": 1,
"http://schema.bar.org/isTemplate": 1,
"http://schema.company.org/foo": 1,
"http://schema.company.org/isTemplate": 1
},
"transform": {
"x": -261,
"y": 53.03025667734585,
"scaleX": 1,
"scaleY": 1
}
}
]
}
}
I hope this clarifies what we currently support and how you can use context
and vocab
to avoid collisions with namespaces.