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

[RFC] ID must always serialize as String would #1086

Merged
merged 1 commit into from Mar 20, 2024

Conversation

benjie
Copy link
Member

@benjie benjie commented Mar 20, 2024

I believe the intention was for this should to have been an RFC2119 must and the should is just an English language issue.

I've marked this RFC0, but really I think it's editorial because we already state in multiple places that ID is serialized as String:

The ID type is serialized in the same way as a String; however, it is not intended to be human-readable.

Statement of fact: ID is serialized as a String

While it is often numeric, it should always serialize as a String.

The should here doesn't override the fact above: not only should it serialize as a string, but it does serialize as a string.

GraphQL is agnostic to ID format, and serializes to string to ensure consistency across many formats ID could represent, from small auto-increment numbers, to large 128-bit random numbers, to base64 encoded values, or string values of a format like GUID.

Again: statement of fact: ID serializes to string.

cc @graphql/tsc

@benjie benjie added the 💭 Strawman (RFC 0) RFC Stage 0 (See CONTRIBUTING.md) label Mar 20, 2024
Copy link

netlify bot commented Mar 20, 2024

Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit a3e3b53
🔍 Latest deploy log https://app.netlify.com/sites/graphql-spec-draft/deploys/65fabf6a7320180008b37b97
😎 Deploy Preview https://deploy-preview-1086--graphql-spec-draft.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Keweiqu Keweiqu merged commit a5da8bb into graphql:main Mar 20, 2024
9 checks passed
@benjie benjie deleted the id-must-be-string branch March 20, 2024 23:13
@benjie benjie added ✏️ Editorial PR is non-normative or does not influence implementation and removed 💭 Strawman (RFC 0) RFC Stage 0 (See CONTRIBUTING.md) labels Mar 20, 2024
@benjie
Copy link
Member Author

benjie commented Apr 5, 2024

For those following along at home, @michaelstaib raised an important point in last night's WG: though ID will always serialize as a string (as this PR helps enforce), for input coercion integers are also accepted to make writing a query where IDs have numeric values more convenient. Thus in TypeScript the type of ID! that you'd receive from GraphQL will be string but the input type of an ID! value you send to GraphQL can be string | number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Editorial PR is non-normative or does not influence implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants