---
# System prepended metadata

title: mm

---

# mm
## playground
https://wpem-cch-ensaas.dev001.wise-paas.com/
## machine type
machine type目前就四種，只需接查詢的即可

### 查詢全部machine type
request

```graphql=
query {
  wpemMachineTypes() {
    name
    label
    parameterTypes {
      type
      units
    }
    createdAt
    updatedAt
  }
}
```

response
```json=
{
  "data": {
    "wpemMachineTypes": [
      {
        "name": "temperatureMeter",
        "label": "Temperature meter",
        "parameterTypes": [
          {
            "type": "temperature",
            "units": [
              "°C"
            ]
          }
        ],
        "createdAt": 1661244891016,
        "updatedAt": 1661244891016
      },
      {
        "name": "humidityMeter",
        "label": "Humidity meter",
        "parameterTypes": [
          {
            "type": "humidity",
            "units": [
              "%"
            ]
          }
        ],
        "createdAt": 1661244891036,
        "updatedAt": 1661244891036
      },
      {
        "name": "noiseDosimeter",
        "label": "Noise dosimeter",
        "parameterTypes": [
          {
            "type": "noise",
            "units": [
              "%"
            ]
          }
        ],
        "createdAt": 1661244891057,
        "updatedAt": 1661244891057
      },
      {
        "name": "aqi",
        "label": "AQI",
        "parameterTypes": [
          {
            "type": "CO",
            "units": [
              "ppm"
            ]
          },
          {
            "type": "O3",
            "units": [
              "ppb"
            ]
          },
          {
            "type": "NO2",
            "units": [
              "ppb"
            ]
          },
          {
            "type": "SO2",
            "units": [
              "ppb"
            ]
          },
          {
            "type": "PM10",
            "units": [
              "μg/m3"
            ]
          },
          {
            "type": "PM2.5",
            "units": [
              "μg/m3"
            ]
          }
        ],
        "createdAt": 1661244891076,
        "updatedAt": 1661244891076
      }
    ]
  }
}

```
### 查詢指定machine type
```graphql
query {
  wpemMachineTypes(names: ["temperatureMeter"]) {
    name
    label
    parameterTypes {
      type
      units
    }
    createdAt
    updatedAt
  }
}
```
### 刪除machine type

```graphql
mutation{
  wpemMachineTypeDelete(name: "temperatureMeter")
}
```

## parameter
### 建立parameter

Request：
```graphql=
mutation {
  wpemParameterCreate (input: [{
    tenantId: "aa"
    groupId: "aa"
    machineType: "meter"
    machineId: "aa"
    parameterId: "aabb4411"
    parameterType: "Number"
    name: "test"
    location: "aaa/bbb/test"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
    
  },{
    tenantId: "aa"
    groupId: "aa"
    machineType: "meter"
    machineId: "aa"
    parameterId: "aabb44"
    parameterType: "Number"
    name: "test"
    location: "aaa/bbb/test"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
    
  }]){
    id
    createdAt
  }
}
```

Response
```json=

{
  "data": {
    "wpemParameterCreate": [
      {
        "id": "2bdumrco0400",
        "createdAt": 1661244962662
      },
      {
        "id": "2bdumrco0401",
        "createdAt": 1661244962662
      }
    ]
  }
}

```


### 查詢全部parameter
request
```graphql=
query {
  wpemParameters(){
    id
    machineId
    name
    alerts
  }
}
```

response:

```json=
{
  "data": {
    "wpemParameters": [
      {
        "id": "2bdumrco0400",
        "machineId": "aa",
        "name": "test",
        "alerts": [
          "a1",
          "a3"
        ]
      },
      {
        "id": "2bdumrco0401",
        "machineId": "aa",
        "name": "test",
        "alerts": [
          "a1",
          "a3"
        ]
      }
    ]
  }
}

```

### 查詢指定（單/多個）parameter
request
```graphql=
query {
  wpemParameters(ids:["2bdumrco0401"]){
    id
    machineId
    name
    alerts
  }
}

```

response

```json=
{
  "data": {
    "wpemParameters": [
      {
        "id": "2bdumrco0401",
        "machineId": "aa",
        "name": "test",
        "alerts": [
          "na1",
          "na2"
        ]
      }
    ]
  }
}
```

### 刪除parameter
request:
```graphql=
mutation {
  wpemParameterDelete(ids: ["2bdumrco0401"])
}
```


response:
```json=
{
  "data": {
    "wpemParameterDelete": true
  }
}
```

## graphql schema

```graphql=
# GraphQL schema example
#
# https://gqlgen.com/getting-started/

type WpemMachineType {
  name: String!
  label: String!
  parameterTypes: [WpemParameterType]!
  createdAt: Int!
  updatedAt: Int!
}

type WpemParameterType {
  type: String!
  units: [String]!
}

input WpemParameterInput {
  type: String!
  units: [String]!
}

input WpemMachineTypeCreateInput {
  name: String!
  label: String!
  parameterTypes: [WpemParameterInput]!
}

type WpemMachineTypeCreatePayload {
  name: String!
  label: String!
  parameterTypes: [WpemParameterType]!
  createdAt: Int!
}

input WpemMachineTypeUpdateInput {
  name: String!
  label: String
  parameterTypes: [WpemParameterInput]
}

type WpemMachineTypeUpdatePayload {
  name: String!
  label: String!
  parameterTypes: [WpemParameterType]!
  updatedAt: Int!
}

extend type Query {
  wpemMachineTypes(names: [String]): [WpemMachineType]!
}

extend type Mutation {
  wpemMachineTypeCreate(input: WpemMachineTypeCreateInput!):WpemMachineTypeCreatePayload
  wpemMachineTypeUpdate(input: WpemMachineTypeUpdateInput!):WpemMachineTypeUpdatePayload
  wpemMachineTypeDelete(names: [String]!):Boolean
}

# GraphQL schema example
#
# https://gqlgen.com/getting-started/
interface Node {
  # The ID of the object.
  id: ID!
}

type WpemParameter implements Node {
  id: ID!
  tenantId: String
  groupId: String
  machineId: String
  parameterId: String
  machineType: String
  parameterType: String
  name: String
  location: String
  alerts: [String]
  silences: [String]
  tags: [String]
  createdAt: Int
  updatedAt: Int
}

input WpemParameterCreateInput {
  tenantId: String!
  groupId: String!
  machineId: String!
  parameterId: String!
  machineType: String!
  parameterType: String!
  name: String!
  location: String!
  alerts: [String]
  silences: [String]
  tags: [String]
}

type WpemParameterCreatePayload {
  id: ID!
  tenantId: String
  groupId: String
  machineId: String
  parameterId: String
  machineType: String
  parameterType: String
  location: String
  name: String
  alerts: [String]
  silences: [String]
  tags: [String]
  createdAt: Int
}

input WpemParameterUpdateInput {
  id: String!
  name: String
  location: String
  alerts: [String]
  silences: [String]
  tags: [String]
}

type WpemParameterUpdatePayload {
  id: ID!
  tenantId: String
  groupId: String
  machineId: String
  parameterId: String
  machineType: String
  parameterType: String
  name: String
  location: String
  alerts: [String]
  silences: [String]
  tags: [String]
  updatedAt: Int
}

extend type Query {
  wpemParameters(ids: [String]): [WpemParameter]!
}

extend type Mutation {
  wpemParameterCreate(input: [WpemParameterCreateInput]!):[WpemParameterCreatePayload]
  wpemParameterUpdate(input: [WpemParameterUpdateInput]!):[WpemParameterUpdatePayload]
  wpemParameterDelete(ids: [String]!):Boolean
}
```

## 測試資料
```graphql=
mutation {
  wpemParameterCreate (input: [{
    tenantId: "testTenant"
    groupId: "testgroup"
    machineType: "temperatureMeter"
    machineId: "temperature1"
    machineName: "temperature"
    parameterId: "temperaturePara1"
    parameterType: "temperature"
    name: "temp-1"
    location: "/testTenant/testgroup/temperature"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
    
  },{
    tenantId: "testTenant"
    groupId: "testgroup"
    machineType: "temperatureMeter"
    machineId: "temperature1"
    machineName: "temperature"
    parameterId: "temperaturePara2"
    parameterType: "temperature"
    name: "temp-2"
    location: "/testTenant/testgroup/temperature"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
  }]){
    id
    createdAt
  }
}


mutation {
  wpemParameterCreate (input: [{
    tenantId: "testTenant"
    groupId: "testgroup"
    machineType: "humidityMeter"
    machineId: "humidity1"
    machineName: "humidity1"
    parameterId: "humidityPara1"
    parameterType: "humidity"
    name: "humidity-1"
    location: "/testTenant/testgroup/humidity"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
    
  },{
    tenantId: "testTenant"
    groupId: "testgroup"
    machineType: "humidityMeter"
    machineId: "humidity1"
    machineName: "humidity1"
    parameterId: "humidityPara2"
    parameterType: "humidity"
    name: "humidity-2"
    location: "/testTenant/testgroup/humidity"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
  }]){
    id
    createdAt
  }
}

mutation {
  wpemParameterCreate (input: [{
    tenantId: "testTenant"
    groupId: "testgroup"
    machineType: "noiseDosimeter"
    machineId: "noise1"
    parameterId: "noisePara1"
    machineName: "noise1"
    parameterType: "noise"
    name: "noise-1"
    location: "/testTenant/testgroup/noise"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
    
  },{
    tenantId: "testTenant"
    groupId: "testgroup"
    machineType: "noiseDosimeter"
    machineId: "noise1"
    machineName: "noise1"
    parameterId: "noisePara2"
    parameterType: "noise"
    name: "noise-2"
    location: "/testTenant/testgroup/noise"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
  }]){
    id
    createdAt
  }
}


mutation {
  wpemParameterCreate (input: [{
    tenantId: "testTenant"
    groupId: "testgroup"
    machineType: "aqi"
    machineId: "aqi1"
    machineName: "aqi"
    parameterId: "aqiPara1"
    parameterType: "NO2"
    name: "NO2-1"
    location: "/testTenant/testgroup/aqi"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
    
  },{
    tenantId: "testTenant"
    groupId: "testgroup"
    machineType: "aqi"
    machineId: "aqi1"
    machineName: "aqi"
    parameterId: "aqiPara2"
    parameterType: "PM2.5"
    name: "PM2.5-1"
    location: "/testTenant/testgroup/aqi"
    alerts: ["a1","a3"]
    silences: ["s1", "s2"]
    tags: ["t1", "t2"]
  }]){
    id
    createdAt
  }
}

```