2021-07-15 11:22:04 +00:00
|
|
|
export function createAttribute({
|
|
|
|
name,
|
|
|
|
attributeValues = ["value"],
|
2021-07-27 08:57:17 +00:00
|
|
|
type = "PRODUCT_TYPE",
|
|
|
|
inputType = "DROPDOWN"
|
2021-07-15 11:22:04 +00:00
|
|
|
}) {
|
2021-03-12 12:14:18 +00:00
|
|
|
const values = attributeValues.map(element => `{name:"${element}"}`);
|
|
|
|
const mutation = `mutation{
|
2021-03-12 14:57:02 +00:00
|
|
|
attributeCreate(input:{
|
|
|
|
name:"${name}"
|
|
|
|
valueRequired:false
|
2021-07-15 11:22:04 +00:00
|
|
|
type:${type}
|
2021-03-12 14:57:02 +00:00
|
|
|
values: [${values}]
|
2021-07-27 08:57:17 +00:00
|
|
|
inputType: ${inputType}
|
2021-03-12 14:57:02 +00:00
|
|
|
}){
|
|
|
|
attribute{
|
|
|
|
id
|
|
|
|
name
|
2021-06-08 06:58:36 +00:00
|
|
|
choices(first: 100){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-12 14:57:02 +00:00
|
|
|
}
|
|
|
|
attributeErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-04-28 13:10:47 +00:00
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(mutation)
|
|
|
|
.its("body.data.attributeCreate.attribute");
|
2021-03-12 12:14:18 +00:00
|
|
|
}
|
2021-02-04 11:15:27 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function getAttributes(first, search) {
|
|
|
|
const mutation = `query{
|
2021-03-12 14:57:02 +00:00
|
|
|
attributes(first:${first}, filter:{
|
|
|
|
search:"${search}"
|
|
|
|
}){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-03-12 12:14:18 +00:00
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(mutation)
|
|
|
|
.then(resp => resp.body.data.attributes.edges);
|
|
|
|
}
|
2021-02-04 11:15:27 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function deleteAttribute(attributeId) {
|
|
|
|
const mutation = `mutation{
|
2021-03-12 14:57:02 +00:00
|
|
|
attributeDelete(id:"${attributeId}"){
|
|
|
|
attributeErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-03-12 12:14:18 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-07-09 09:43:45 +00:00
|
|
|
|
|
|
|
export function getAttribute(attributeId) {
|
|
|
|
const query = `query{
|
|
|
|
attribute(id:"${attributeId}"){
|
|
|
|
id
|
|
|
|
inputType
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
entityType
|
|
|
|
valueRequired
|
|
|
|
visibleInStorefront
|
|
|
|
availableInGrid
|
|
|
|
unit
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
return cy.sendRequestWithQuery(query).its("body.data.attribute");
|
|
|
|
}
|