graphql / graphql-spec

GraphQL is a query language and execution engine tied to any backend service.
https://spec.graphql.org
14.29k stars 1.12k forks source link

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

Closed benjie closed 6 months ago

benjie commented 6 months ago

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

netlify[bot] commented 6 months ago

Deploy Preview for graphql-spec-draft ready!

Name Link
Latest commit a3e3b53f2bad2d0d8fc055fb03ee82c039823fa2
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.

benjie commented 6 months ago

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.