I have a GraphQL schema called Car Manufacturer which has two fields, id
and name
. 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.
Is there a way to insert a desired value on the id
field?
Why you want to modify the id
? For using them as indexes? Like id: 1
, id: 2
an so on? If is that so, you should have something like globalIdField
from graphql-relay
in my opinion. Not mutate these ids
yourself. 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.
If you want to change this values for whatever other reason, you have to create Mutations
just like @arian said
I hope that I helped you someway :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.