question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't set a custom ID value when inserting new item in List via GraphQL mutation query

See original GitHub issue

Bug 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

  1. Create a simple List, for example “Country”:
keystone.createList('Country', {
  fields: {
    id: { type: Text },
    name: { type: Text },
  },
});
  1. Try to insert new city via GraphQL mutation query:
mutation {
  createCountry(data: {
    id: "RU"
    name: "Russia"
  }) {
    id, name
  }
}
  1. See the error

Expected behaviour

This mutation query must create the new item with sent id value.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
emmatowncommented, Jun 30, 2022

As discussed in https://github.com/keystonejs/keystone/discussions/6034#discussioncomment-1372545, it’s an intentional decision to not support this.

1reaction
stale[bot]commented, Sep 11, 2021

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. 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found