-
How to change default primary ke 'id' to a custom keyname? I am using 'JSON Schema' way to get data from a restful api from backend. But the 'id' field key of data is not unique. Then when I using it in a react project, it has a bug: when the data has the same id, it will replace anther in the Object in react. I renamed 'id' to anther name, it be fixed. But, I want to konw is here anyway to change te default primary key's name? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
So do you want to rename the field? |
Beta Was this translation helpful? Give feedback.
-
@ardatan Thanks. Rename 'id' field to anthor name will fix it. I want to know that Can I assign a field as a primary key instead of renaming? |
Beta Was this translation helpful? Give feedback.
-
@ardatan For Example:type A {
|
Beta Was this translation helpful? Give feedback.
@ardatan
Thank you again.
For Example:
type A {
id: String // This field is not unique
bundleId: String // This field is unique
}
When I got an array data of A from api request like:
[
{id: "123", bundleId: "com.abc"},
{id: "123", bundleId: "com.abcdefghijklmn"},
]
'@apollo/client' will get me an array in javascript like
[
{id: "123", bundleId: "com.abc"},
{id: "123", bundleId: "com.abc"},
]
If i change name id to anther, it will be OK, I got
[
{theId: "123", bundleId: "com.abc"},
{theId: "123", bundleId: "com.abcdefghijklmn"},
]
If I don't want to rename id field, How can I tell '@apollo/client' set bundleId to primary key, inside of 'id'