Can't set a custom ID value when inserting new item in List via GraphQL mutation query
See original GitHub issueBug report
Describe the bug
Can’t set a custom ID value when inserting new item in List via GraphQL mutation query:
mutation {
createCountry(data: {
id: "RU"
name: "Russia"
}) {
id, name
}
}
- got the error as result:
GraphQLError: Field \"id\" is not defined by type \"CountryCreateInput\".
at ObjectField (keystone/node_modules/graphql/validation/rules/ValuesOfCorrectTypeRule.js:73:29)
at Object.enter (keystone/node_modules/graphql/language/visitor.js:323:29)
at Object.enter (keystone/node_modules/graphql/utilities/TypeInfo.js:370:25)
at visit (keystone/node_modules/graphql/language/visitor.js:243:26)
at Object.validate (keystone/node_modules/graphql/validation/validate.js:69:24)
at validate (keystone/node_modules/apollo-server-core/dist/requestPipeline.js:221:34)
at Object.<anonymous> (keystone/node_modules/apollo-server-core/dist/requestPipeline.js:118:42)
at Generator.next (<anonymous>)
at fulfilled (keystone/node_modules/apollo-server-core/dist/requestPipeline.js:5:58)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
I use the MongoDB database with MongooseAdapter, which have no problems with custom id values, here is raw query that do this thing:
> db.countries.insert({_id:"RU", "Name" : "Russia"})
WriteResult({ "nInserted" : 1 })
To Reproduce
- Create a simple List, for example “Country”:
keystone.createList('Country', {
fields: {
id: { type: Text },
name: { type: Text },
},
});
- Try to insert new city via GraphQL mutation query:
mutation {
createCountry(data: {
id: "RU"
name: "Russia"
}) {
id, name
}
}
- See the error
Expected behaviour
This mutation query must create the new item with sent id value.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Mutations and Input Types - GraphQL
It's often convenient to have a mutation that maps to a database create or update operation, like setMessage , return the same thing...
Read more >GraphQL schema basics
Your GraphQL server uses a schema to describe the shape of your available data. This schema defines a hierarchy of types with fields...
Read more >Postgres: Insert mutation | Hasura GraphQL Docs
Insert an object into Postgres using a mutation. ... Example: Insert a new article object and return the inserted article object in the...
Read more >IDs - GraphQL - Dgraph
Dgraph database provides two types of identifiers: the ID scalar type and the @id ... so you can't make an add mutation without...
Read more >How to Use GraphQL Operation Names and Variables - Shopify
Just like in that query variables pane of GraphiQL, I'm specifying an object of key ID and then the actual string that corresponds...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As discussed in https://github.com/keystonejs/keystone/discussions/6034#discussioncomment-1372545, it’s an intentional decision to not support this.
It looks like there hasn’t been any activity here in over 6 months. Sorry about that! We’ve flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contribution. 😃