Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make a custom field: id? #130

Closed
Dugnist opened this issue Aug 10, 2016 · 10 comments
Closed

How to make a custom field: id? #130

Dugnist opened this issue Aug 10, 2016 · 10 comments

Comments

@Dugnist
Copy link

Dugnist commented Aug 10, 2016

As i understand - now my "id" generated from mongoose "_id" field, but how to make it custom?

@tothandras
Copy link
Contributor

tothandras commented Aug 10, 2016

@Dugnist You need to create another field. id is used by Relay and it encodes the resource type along with the mongoose _id.

@Dugnist
Copy link
Author

Dugnist commented Aug 10, 2016

@tothandras ok, as then i can create unique field or rewrite _id during create new document?

@Dugnist
Copy link
Author

Dugnist commented Aug 10, 2016

@tothandras i try use "unique: true" in mongo schema and it did not working...(

@tothandras
Copy link
Contributor

@Dugnist for what do you need a custom id?

@tothandras
Copy link
Contributor

does this work or not?

new Schema({
    identifier: { type: String, index: { unique: true } }
})

@Dugnist
Copy link
Author

Dugnist commented Aug 10, 2016

@tothandras i need to create a full object that include field "id" on the client-side and then push them on server...

@tothandras
Copy link
Contributor

@Dugnist hmmm.. why not just use the ids you get back when inserting objects with a mutation? so you can have the ids on the client side too for new objects

@Dugnist
Copy link
Author

Dugnist commented Aug 10, 2016

@tothandras yes - index: { unique: true } is working. Thank you. Maybe you know some trick how can circumvent restriction with "id" field? The policy of my project require creating unique id on the client...(

@Dugnist
Copy link
Author

Dugnist commented Aug 10, 2016

@tothandras unfortunately i cannot do any request with my custom field "ID" without default field "id"...(

This mutation not working... I know why and it sadly...(

mutation {
  updateDocument( input: {
    name: "Name of Document",
    ID : "123",
    clientMutationId: "1"
  }) {
    changedDocument {
      ID
    }
  }
}

@tothandras
Copy link
Contributor

@Dugnist To be honest I've never heard unique id and client side in the same sentence. :) As the user has full control over the sent object, you eventually need to validate it server side.
What you can try is to use a plural query with the ID and then you can get the actual id to do the mutation.. it's something

@Dugnist Dugnist closed this as completed Aug 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants