Skip to content

Define Data Collections used in the spec #1102

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

Merged
merged 4 commits into from
Jul 1, 2025
Merged

Define Data Collections used in the spec #1102

merged 4 commits into from
Jul 1, 2025

Conversation

benjie
Copy link
Member

@benjie benjie commented Jul 1, 2024

The spec uses the terms "set", "list" and "map" in many places. This PR defines these terms and their conformance requirements.

This is a change extracted from #1063 as discussed at last night's WG meeting

This is PR 1 of 3 in the "data collections" trilogy stack; next are:

  1. Recommend that order of unordered collections is maintained where possible #1092
  2. [RFC] Type system ordering of: object interfaces, directive arguments, input object fields, enum values #1063

cc @graphql/tsc

(Replacement of #1091; to do PR stack with #1092 and #1063)

Copy link

netlify bot commented Jul 1, 2024

Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit 68bc42a
🔍 Latest deploy log https://app.netlify.com/projects/graphql-spec-draft/deploys/68635e6c6af4e600082623ed
😎 Deploy Preview https://deploy-preview-1102--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 project configuration.

Copy link
Contributor

@andimarek andimarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one logical consistent way to describe these data structures is with a minimal amount of predefined terms would be:

  1. Everything is a collection. A collection is a finite group of elements that can be iterated over. The encounter order during iteration is not necessarily stable.

  2. A List is a specific collection where each element can be accessed via a stable Integer >= 0, called index and the encounter order is stable. A List allows for duplicate elements.

  3. A set is a specific collection where the elements are guaranteed to be unique. The encounter is not necessary stable ("unordered set"), but can be ("ordered set")
    (If we need to define unordered set vs ordered)

  4. A Map is a specific collection of elements, where each element is a pair (called "entry") made of a key and a value. All keys are a set, while all values is just a collection.
    The encounter order of a Map can be stable ("ordered Map") or not ("unordered Map")
    (If we need to define unordered Map vs ordered)

@benjie
Copy link
Member Author

benjie commented Apr 1, 2025

Hopefully my latest edit factors in @andimarek and @martinbonnin's feedback.


## Data Collections

A data collection is a finite, iterable aggregation of elements whose iteration
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 'aggregation'?

  • collection: tautology - "a data collection is a collection"
  • set: we define "set" below, so using set here would introduce ambiguity
  • group: evokes group theory, best avoided
  • assembly: technically correct, but feels unnatural

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this in editorial.

My thinking is that any reader of this spec does not need to learn what a data collection is in general (though fwiw, wikipedia does use the term "group").

What is important for us to clearly state is what aspects of that data collection is normative

@benjie benjie added the 🚀 Next Stage? This RFC believes it is ready for the next stage label Jun 26, 2025
@leebyron leebyron added 🏁 Accepted (RFC 3) RFC Stage 3 (See CONTRIBUTING.md) and removed 📄 Draft (RFC 2) RFC Stage 2 (See CONTRIBUTING.md) 🚀 Next Stage? This RFC believes it is ready for the next stage labels Jun 26, 2025
spec/GraphQL.md Outdated
Comment on lines 95 to 102
implementations. Similarly, data collections such as _list_, _set_ and _map_
also introduce conformance requirements. Implementers are free to use
alternative data collections as long as the perceived result remains equivalent.

See [Appendix A](#sec-Appendix-Notation-Conventions) for more details about the
definition of algorithms and other notational conventions used in this document.
definition of algorithms and other notational conventions used in this document,
and [Appendix A: Data Collections](#sec-Data-Collections) for specifics of data
collections and their ordering.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to lee: simplify this addition a bit before merge

@leebyron leebyron force-pushed the data-collections branch 3 times, most recently from 57e8376 to 9b51301 Compare July 1, 2025 04:02
@leebyron leebyron force-pushed the data-collections branch from 9b51301 to 68bc42a Compare July 1, 2025 04:04
@leebyron leebyron merged commit ccf23e3 into main Jul 1, 2025
9 checks passed
@leebyron leebyron deleted the data-collections branch July 1, 2025 04:07
@github-project-automation github-project-automation bot moved this from Needs my work to Done in Benjie's GraphQL tasks Jul 1, 2025
Copy link
Member Author

@benjie benjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the simplification; looks good! We did drop the "zero or more" terminology which has been questioned before, but I think that's okay - most programmers know that an empty list, set or map can exist and wouldn't question it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏁 Accepted (RFC 3) RFC Stage 3 (See CONTRIBUTING.md)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants