GraphQL Cookbook
객체 생성
8 분
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는 이를 저장할 뿐만 아니라 학습하고, 애플리케이션의 스키마에 새로운 클래스를 자동으로 생성합니다 따라서 객체의 create create 일반 변형은 객체의 클래스를 이미 생성하지 않은 경우 새 객체를 생성하는 데 사용해야 하는 방법입니다 기존 클래스의 객체를 생성하는 데도 이 변형을 사용할 수 있지만, 이러한 경우에는 클래스 변형 https //www back4app com/docs/parse graphql/graphql mutation create object#mutation class 을 사용하는 것이 좋습니다 클래스 request #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 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 } 객체 request 1 mutation createobject{ 2 createhero(input {fields {name "luke skywalker"}}){ 3 hero{ 4 id 5 name 6 } 7 } 8 } response 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에 이 클래스의 새 객체를 생성하기 위한 create\<classname> create\<classname> 변형을 추가합니다 따라서 객체의 클래스 변형은 이미 객체의 클래스를 생성한 경우 새 객체를 생성하는 데 권장되는 방법입니다 이 변형은 클래스의 데이터를 알고 있으므로 코드 자동 완성 및 유효성 검사와 같은 추가 기능을 자동으로 사용할 수 있습니다 또한 클래스 생성 변형을 통해 날짜, 포인터, 관계, 파일, 지리적 포인트, 다각형 또는 바이트를 전송할 때 데이터 유형을 지정할 필요가 없습니다 이 예제는 객체의 클래스를 이미 생성한 경우에만 작동합니다 클래스를 생성하려면 일반 변형 을 사용하십시오 request 1 mutation createobject{ 2 createhero(input {fields {name "r2 d2"}}){ 3 hero{ 4 id 5 createdat 6 } 7 } 8 } response #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 서버 버전 파스 서버 3 9 0 일반 변형 클래스 요청 #파스 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 } 응답 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 } 객체 요청 #그리고 객체를 생성합니다 \#파스 3 9 0에서는 먼저 클래스를 생성해야 합니다 1 mutation createobject{ 2 createhero(fields { 3 name "루크 스카이워커" 4 }){ 5 id 6 createdat 7 } 8 } 응답 1 { 2 "data" { 3 "createhero" { 4 "id" "ckhurmmjzw", 5 "createdat" "2019 11 04t12 37 22 462z" 6 } 7 } 8 } 클래스 변형 파스 서버 3 9 0 1 mutation createobject{ 2 createhero(fields { 3 name "r2 d2" 4 }){ 5 id 6 createdat 7 } 8 } 결과 파스 3 9 0 1 { 2 "data" { 3 "createhero" { 4 "id" "n5grpei0il", 5 "createdat" "2019 11 04t12 45 00 882z" 6 } 7 } 8 } 파스 서버 3 8 0 일반 변형 파스 서버 3 8 0 1 mutation createobject { 2 create(classname "hero" fields { 3 name "luke skywalker" 4 }){ 5 objectid 6 createdat 7 } 8 } 결과 파스 3 8 0 1 { 2 "data" { 3 "objects" { 4 "create" { 5 "objectid" "ffyobotk85", 6 "createdat" "2019 07 15t01 25 20 875z" 7 } 8 } 9 } 10 } 클래스 변형 파스 서버 3 8 0 1 mutation createhero { 2 createhero(fields { name "r2 d2" }) { 3 objectid, 4 createdat 5 } 6 } 결과 파스 3 8 0 1 { 2 "data" { 3 "createhero" { 4 "objectid" "tuecddcgno", 5 "createdat" "2019 11 04t12 44 10 951z" 6 } 7 } 8 } 파스 서버 3 7 2 일반 변형 파스 서버 3 7 2 1 mutation createobject { 2 objects { 3 create(classname "hero", fields { name "luke skywalker" }) { 4 objectid, 5 createdat 6 } 7 } 8 } 결과 파스 3 7 2 1 { 2 "data" { 3 "objects" { 4 "create" { 5 "objectid" "kr9aqnzfui", 6 "createdat" "2019 07 15t01 25 20 875z" 7 } 8 } 9 } 10 } 클래스 변형 파스 서버 3 7 2 1 mutation createhero { 2 objects { 3 createhero(fields { name "r2 d2" }) { 4 objectid, 5 createdat 6 } 7 } 8 } 결과 파스 3 7 2 1 { 2 "data" { 3 "objects" { 4 "createhero" { 5 "objectid" "jjh0aqqjfs", 6 "createdat" "2019 07 15t02 22 04 982z" 7 } 8 } 9 } 10 }