简体   繁体   English

id字段上的GraphQL突变

[英]GraphQL mutation on id field

I have a GraphQL schema called Car Manufacturer which has two fields, id and name . 我有一个名为Car Manufacturer的GraphQL模式,其中有两个字段, idname What I am trying to accomplish via GraphiQL is to insert several data into the schema but I need to mutate both the mentioned fields. 我试图通过GraphiQL完成的工作是在模式中插入几个数据,但是我需要对两个上述字段进行突变。

Is there a way to insert a desired value on the id field? 有没有一种方法可以在id字段中插入所需的值?

Why you want to modify the id ? 为什么要修改id For using them as indexes? 使用它们作为索引? Like id: 1 , id: 2 an so on? id: 1id: 2等等? If is that so, you should have something like globalIdField from graphql-relay in my opinion. 如果是这样,我认为您应该从graphql-relay中获得诸如globalIdField东西。 Not mutate these ids yourself. 不要自己更改这些ids For example: 例如:

import { GraphQLObjectType, GraphQLFloat } from 'graphql';
import { globalIdField } from 'graphql-relay';

export default new GraphQLObjectType({
  name: 'Car anufacturer',
  description: 'desc',
  fields: () => ({
    id: globalIdField('CarManufacturer'),
    title: {
      type: GraphQLString,
      resolve: async obj => obj.title,
    },
  }),
});

This way you will have unique ids and you can turn these ids on an ObjectId for use with MongoDB for example. 这样,您将拥有唯一的ID,例如,您可以将这些ID转换为与MongoDB一起使用的ObjectId

If you want to change this values for whatever other reason, you have to create Mutations just like @arian said 如果您出于任何其他原因想要更改此值,则必须像@arian一样创建Mutations

I hope that I helped you someway :) 希望我能对您有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在GraphQL突变中为字段分配类型 - Assigning a Type to a field in GraphQL Mutation 变量ID! 在graphql突变中仍未定义 - Variable ID! remains undefined in graphql mutation AWS Amplify GraphQL 突变未更新布尔字段 - AWS Amplify GraphQL mutation is not updating a boolean field GraphQL 用于在突变字段上映射数组的语法 - GraphQL Syntax for mapping array on mutation field 如何在 Nestjs + Graphql Mutation Args 中定义 ID 类型? - How to define ID type in Nestjs + Graphql Mutation Args? GraphQL - 如何在查询多个突变期间检索先前突变的 id - GraphQL - How retrieve id of previous mutation, during query of multiple mutations 如何在GraphQL突变中获取RDS Aurora中最后插入的行的ID - how to get id of last inserted row in RDS Aurora in GraphQL mutation 为什么Relay需要一个突变ID来协调GraphQL突变? - Why does Relay need a mutation id to reconcile GraphQL mutations? 如何在反应更新突变中访问object.id,graphql与棱镜 - How to access object.id in update mutation in react, graphql with prisma 类型为“突变”(graphql-compose)的字段上的未知参数“记录” - Unknown argument “record” on field of type “Mutation” (graphql-compose)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM