如何创建具有 3 个或更多嵌套关系的突变?
How to create mutation with 3 or more nested relationships?
我正在创建一个基于我研究过的业务的智能 CRUD。问题是我尝试进行嵌套突变,如 lighthouse docs 所示
但由于{客户有很多联系人,联系人有很多电子邮件}
,关系的深度分为三个层次
我在 schema.graphql 中执行以下操作:
type Mutation {
createClient (input: createClientInput! @spread): Client @create
}
input createClientInput {
name: String!
address: String!
NIT: String
...
contracts: CreateContactsRelation
}
input CreateContactsRelation {
create: [CreateContactInput!]
}
input CreateContactInput {
name: String
position: String
emails: CreateEmailRelation # this does'n work
}
input CreateEmailRelation {
create: [CreateEmailInput!]
}
input CreateEmailInput {
email: String!
}
运行突变
mutation{
crearCliente(input: {
nombre: "prueba graphql crear 4"
direccion: "prueba"
NIT: "3225"
abreviatura: "asas"
OSDE: "prub"
organismo: "asas"
observaciones: "con contacto"
contactos: {
create: [
{
nombre: "periqito peres"
cargo: "director"
correos: {
create: [
{
email: "perez@gmail.com"
}
{
email: "perez@enet.cu"
}
]
}
}
{
nombre: "joaqin gomez"
cargo: "contador"
correos: {
create: [
{
email: "joaqin@gmail.com"
}
{
email: "joaqin@enet.cu"
}
]
}
}
]
}
}){
id
nombre
contactos{
id
nombre
cargo
correos{
id
email
}
}
}
}
输出为
{
"data": {
"crearCliente": {
"id": "53",
"nombre": "prueba graphql crear 4",
"contactos": [
{
"id": "46",
"nombre": "periqito peres",
"cargo": "director",
"correos": [] <--------------not email
},
{
"id": "47",
"nombre": "joaqin gomez",
"cargo": "contador",
"correos": [] <--------------not email
}
]
}
}
}
如您所见,没有创建电子邮件。有人知道怎么解决吗?
您必须将每个 table 关系与我创建此示例的 id 联系起来,以便您理解这一点:
我正在创建一个基于我研究过的业务的智能 CRUD。问题是我尝试进行嵌套突变,如 lighthouse docs 所示 但由于{客户有很多联系人,联系人有很多电子邮件}
,关系的深度分为三个层次我在 schema.graphql 中执行以下操作:
type Mutation {
createClient (input: createClientInput! @spread): Client @create
}
input createClientInput {
name: String!
address: String!
NIT: String
...
contracts: CreateContactsRelation
}
input CreateContactsRelation {
create: [CreateContactInput!]
}
input CreateContactInput {
name: String
position: String
emails: CreateEmailRelation # this does'n work
}
input CreateEmailRelation {
create: [CreateEmailInput!]
}
input CreateEmailInput {
email: String!
}
运行突变
mutation{
crearCliente(input: {
nombre: "prueba graphql crear 4"
direccion: "prueba"
NIT: "3225"
abreviatura: "asas"
OSDE: "prub"
organismo: "asas"
observaciones: "con contacto"
contactos: {
create: [
{
nombre: "periqito peres"
cargo: "director"
correos: {
create: [
{
email: "perez@gmail.com"
}
{
email: "perez@enet.cu"
}
]
}
}
{
nombre: "joaqin gomez"
cargo: "contador"
correos: {
create: [
{
email: "joaqin@gmail.com"
}
{
email: "joaqin@enet.cu"
}
]
}
}
]
}
}){
id
nombre
contactos{
id
nombre
cargo
correos{
id
email
}
}
}
}
输出为
{
"data": {
"crearCliente": {
"id": "53",
"nombre": "prueba graphql crear 4",
"contactos": [
{
"id": "46",
"nombre": "periqito peres",
"cargo": "director",
"correos": [] <--------------not email
},
{
"id": "47",
"nombre": "joaqin gomez",
"cargo": "contador",
"correos": [] <--------------not email
}
]
}
}
}
如您所见,没有创建电子邮件。有人知道怎么解决吗?
您必须将每个 table 关系与我创建此示例的 id 联系起来,以便您理解这一点: