---
title: 객체 생성
slug: docs-kr/parse-graphql/graphql-mutation-create-object
description: Parse Server에서 GraphQL로 객체 생성 방법, 버전에 따른 클래스 및 일반 변형 사용법.
image: https://www.back4app.com/_public/img/back4app-og.png
createdAt: 2024-02-16T13:10:31.766Z
---

# Parse GraphQL API를 통한 객체 생성

## 문제

Parse GraphQL API를 통해 데이터베이스에 새 객체를 생성하고 싶습니다.

## 해결책

Parse GraphQL을 사용하여 데이터베이스에 새 객체를 생성하는 두 가지 방법이 있습니다:

- [일반 변형 사용 ](https://www.back4app.com/docs/parse-graphql/graphql-mutation-create-object#mutation-generic)- - 객체의 클래스를 이미 생성하지 않은 경우 사용해야 하는 변형입니다.
- [클래스 변형 사용 ](https://www.back4app.com/docs/parse-graphql/graphql-mutation-create-object#mutation-class)- 객체의 클래스를 이미 생성한 경우 권장되는 변형입니다.

## 버전 정보

실행할 Parse 버전에 따라 GraphQL 쿼리, 변형 및 결과가 약간 다를 수 있습니다.
실행 중인 Parse 버전과 함께 올바른 예제를 선택하십시오.

### 일반 변형 사용하기

일반 변형을 사용하면 Parse Server는 스키마 없는 데이터베이스처럼 동작합니다. 즉, 애플리케이션의 스키마에서 객체의 클래스를 미리 정의할 필요가 없습니다. 객체의 데이터를 전송하기만 하면 Parse Server는 이를 저장할 뿐만 아니라 학습하고, 애플리케이션의 스키마에 새로운 클래스를 자동으로 생성합니다.

따라서 객체의 <font color="#2166ae">`create`</font> 일반 변형은 객체의 클래스를 이미 생성하지 않은 경우 새 객체를 생성하는 데 사용해야 하는 방법입니다. 기존 클래스의 객체를 생성하는 데도 이 변형을 사용할 수 있지만, 이러한 경우에는 [클래스 변형](https://www.back4app.com/docs/parse-graphql/graphql-mutation-create-object#mutation-class)을 사용하는 것이 좋습니다.

**클래스:**

:::CodeblockTabs
Request

```graphql
     #In Parse 3.10.0 and later you must first create the Class itself:
1    mutation CreateClass {
2      createClass(input:{
3        name: "Hero"
4        schemaFields: {
5          addStrings: [{name: "name"}]
6          addNumbers: [{name: "height"}]
7        }
8      }){
9        class{
10         schemaFields{
11           name
12           __typename
13         }
14       }
15     }
16   }
```

Response

```graphql
1   {
2     "data": {
3       "createClass": {
4         "class": {
5           "schemaFields": [
6             {
7               "name": "objectId",
8               "__typename": "SchemaStringField"
9             },
10            {
11              "name": "updatedAt",
12              "__typename": "SchemaDateField"
13            },
14            {
15              "name": "createdAt",
16              "__typename": "SchemaDateField"
17            },
18            {
19              "name": "name",
20              "__typename": "SchemaStringField"
21            },
22            {
23              "name": "height",
24              "__typename": "SchemaNumberField"
25            },
26            {
27              "name": "ACL",
28              "__typename": "SchemaACLField"
29            }
30          ]
31        }
32      }
33    }
34  }
```
:::

**객체:**

:::CodeblockTabs
Request

```graphql
1   mutation CreateObject{
2     createHero(input: {fields: {name: "Luke Skywalker"}}){
3       hero{
4         id
5         name
6       }
7     }
8   }
```

Response

```graphql
1   {
2     "data": {
3       "createHero": {
4         "hero": {
5           "id": "SGVybzo5QjFPMUFxcXN1",
6           "name": "Luke Skywalker"
7         }
8       }
9     }
10  }
```
:::

### 클래스 변형 사용

응용 프로그램의 스키마에서 객체의 클래스를 이미 생성한 경우(예: [일반 변형](https://www.back4app.com/docs/parse-graphql/graphql-mutation-create-object#mutation-generic)) Parse Server는 즉시 GraphQL API에 이 클래스의 새 객체를 생성하기 위한 <font color="#2166ae">`create<ClassName>`</font> 변형을 추가합니다.

따라서 객체의 클래스 변형은 이미 객체의 클래스를 생성한 경우 새 객체를 생성하는 데 권장되는 방법입니다. 이 변형은 클래스의 데이터를 알고 있으므로 코드 자동 완성 및 유효성 검사와 같은 추가 기능을 자동으로 사용할 수 있습니다. 또한 클래스 생성 변형을 통해 날짜, 포인터, 관계, 파일, 지리적 포인트, 다각형 또는 바이트를 전송할 때 데이터 유형을 지정할 필요가 없습니다.

:::hint{type="info"}
**이 예제는 객체의 클래스를 이미 생성한 경우에만 작동합니다.&#x20;**&#xD074;래스를 생성하려면 **[일반 변형](https://www.back4app.com/docs/parse-graphql/graphql-mutation-create-object#mutation-generic)을 사용하십시오.**
:::

:::CodeblockTabs
Request

```graphql
1   mutation CreateObject{
2     createHero(input: {fields: {name: "R2-D2"}}){
3       hero{
4         id
5         createdAt
6       }
7     }
8   }
```

Response

```graphql
   #Notice the id property refers to the Global id in the Relay specification, not to confuse with the objectId from Parse.
1   {
2     "data": {
3       "createHero": {
4         "hero": {
5           "id": "SGVybzpVRm5TVDM1YnBp",
6           "createdAt": "2020-02-06T13:13:26.678Z"
7         }
8       }
9     }
10  }
```
:::

## 이전 Parse 서버 버전

::::ExpandableHeading{isOpen="true"}
**파스 서버 3.9.0**

**일반 변형**

**클래스:**

:::CodeblockTabs
요청

```graphql
     #파스 3.9.0에서는 먼저 클래스를 생성해야 합니다:
1   mutation CreateClass {
2     createClass(
3       name: "영웅"
4       schemaFields: {
5         addStrings: [{name: "이름"}]
6         addNumbers: [{name: "신장"}]
7       }){
8       schemaFields{
9         name
10        __typename
11      }
12    }
13  }
```

응답

```graphql

1   {
2     "data": {
3       "createClass": {
4         "schemaFields": [
5           {
6             "name": "objectId",
7             "__typename": "SchemaStringField"
8           },
9           {
10            "name": "updatedAt",
11            "__typename": "SchemaDateField"
12          },
13          {
14            "name": "createdAt",
15            "__typename": "SchemaDateField"
16          },
17          {
18            "name": "이름",
19            "__typename": "SchemaStringField"
20          },
21          {
22            "name": "신장",
23            "__typename": "SchemaNumberField"
24          },
25          {
26            "name": "ACL",
27            "__typename": "SchemaACLField"
28          }
29        ]
30      }
31    }
32  }
```
:::

**객체:**

:::CodeblockTabs
요청

```graphql
   #그리고 객체를 생성합니다:
   #파스 3.9.0에서는 먼저 클래스를 생성해야 합니다:
1   mutation CreateObject{
2     createHero(fields:{
3       name: "루크 스카이워커"
4     }){
5       id
6       createdAt
7     }
8   }
```

응답

```graphql
1   {
2     "data": {
3       "createHero": {
4         "id": "CkhurmMjZW",
5         "createdAt": "2019-11-04T12:37:22.462Z"
6       }
7     }
8   }
```
:::

**클래스 변형**

:::CodeblockTabs
파스 서버 3.9.0

```graphql
1   mutation CreateObject{
2     createHero(fields:{
3       name: "R2-D2"
4     }){
5       id
6       createdAt
7     }
8   }
```

결과 파스 3.9.0

```graphql
1   {
2     "data": {
3       "createHero": {
4         "id": "n5GrpEi0iL",
5         "createdAt": "2019-11-04T12:45:00.882Z"
6       }
7     }
8   }
```
:::
::::

::::ExpandableHeading{isOpen="true"}
**파스 서버 3.8.0**

**일반 변형:**

:::CodeblockTabs
파스 서버 3.8.0

```graphql
1   mutation CreateObject {
2     create(className: "Hero" fields:{
3       name: "Luke Skywalker"
4     }){
5       objectId
6       createdAt
7     }
8   }
```

결과 파스 3.8.0

```graphql
1   {
2     "data": {
3       "objects": {
4         "create": {
5           "objectId": "ffyOBOTk85",
6           "createdAt": "2019-07-15T01:25:20.875Z"
7         }
8       }
9     }
10   }
```
:::

**클래스 변형:**

:::CodeblockTabs
파스 서버 3.8.0

```graphql
1   mutation CreateHero {
2     createHero(fields: { name: "R2-D2" }) {
3       objectId,
4       createdAt
5     }
6   }
```

결과 파스 3.8.0

```graphql
1   {
2     "data": {
3       "createHero": {
4         "objectId": "tUEcddcgno",
5         "createdAt": "2019-11-04T12:44:10.951Z"
6       }
7     }
8   }
```
:::
::::

::::ExpandableHeading{isOpen="true"}
**파스 서버 3.7.2**

**일반 변형:**

:::CodeblockTabs
파스 서버 3.7.2

```graphql
1   mutation CreateObject {
2     objects {
3       create(className: "Hero", fields: { name: "Luke Skywalker" }) {
4         objectId,
5         createdAt
6       }
7     }
8   }
```

결과 파스 3.7.2

```graphql
1   {
2     "data": {
3       "objects": {
4         "create": {
5           "objectId": "Kr9aqnzfui",
6           "createdAt": "2019-07-15T01:25:20.875Z"
7         }
8       }
9     }
10  }
```
:::

**클래스 변형:**

:::CodeblockTabs
파스 서버 3.7.2

```graphql
1   mutation CreateHero {
2     objects {
3       createHero(fields: { name: "R2-D2" }) {
4         objectId,
5         createdAt
6       }
7     }
8   }
```

결과 파스 3.7.2

```graphql
1   {
2     "data": {
3       "objects": {
4         "createHero": {
5           "objectId": "jJH0aQQjfs",
6           "createdAt": "2019-07-15T02:22:04.982Z"
7         }
8       }
9     }
10  }
```
:::
::::

