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

string ID types? #41

Closed
buchanae opened this issue Mar 7, 2018 · 3 comments
Closed

string ID types? #41

buchanae opened this issue Mar 7, 2018 · 3 comments
Labels

Comments

@buchanae
Copy link

buchanae commented Mar 7, 2018

Would it be possible to generate code using string as the underlying type of GQL ID? Currently it is generated as int, which is more cumbersome for my databases.

@vektah
Copy link
Collaborator

vektah commented Mar 8, 2018

They should be already?

eg https://github.com/vektah/gqlgen/blob/master/example/chat/schema.graphql#L7

type Message {
    id: ID!
    text: String!
    createdBy: String!
    createdAt: Time!
}

results in
https://github.com/vektah/gqlgen/blob/master/example/chat/models_gen.go#L10

type Message struct {
	ID        string
	Text      string
	CreatedBy string
	CreatedAt time.Time
}

@vektah vektah added the question label Mar 8, 2018
@ereyes01
Copy link

ereyes01 commented Mar 9, 2018

Yes, as a matter of fact I was trying to do the opposite- use an int as the ID type in my own mapped type, but gqlgen fails with this error:

type mismatch on Org.id, expected string got int

But it looks like this is the correct behavior, according to the graphql docs:

ID: The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable.

@vektah
Copy link
Collaborator

vektah commented Mar 16, 2018

You could define your own ID type if you want to use ints, see the example.

@vektah vektah closed this as completed Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants