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

Update the relay specific specifications to consider them generic best practices and not purely a relay spec #2603

Closed
wants to merge 3 commits into from

Conversation

orta
Copy link
Contributor

@orta orta commented Jan 11, 2019

Better late than never, roughly a year ago in the GraphQL Working Group 3 we took it on Artsy to start moving the Relay specs to be considered "GraphQL Best Practices" (link)

This starts that, beginning with first minimizing the use of Relay as being the sole client that conforms to the connection and object identifier spec.

Main notes:

  • When referring to relay on the client I switched "Relay" to "Spec-compliant client" or "client"
  • When referring to relay's compatibility on the server side, I oriented it to just be "spec-compliant"
  • I mostly left the Mutation input spec alone, now that it's only for Relay classic and is close to being removed completely from Relay Remove the clientMutationId requirement by creating a new root id for each executed mutation #2349
  • This is step one, once this is merged then I'd like to move both object identification and connection to be on the graphql repos instead of relay and I can handle link updating etc

Happy to change wording etc

/cc @leebyron in case you don't watch this repo too closely.

* Minimize the 'These specs are only for Relay' wording for the connection/mutation/objectidentification spec
mutation fields in a standardized way. These mutations accept and emit a
identifier string, which allows Relay to track mutations and responses.
identifier string, which allows Relay Classic to track mutations and responses.
Copy link
Contributor

@alloy alloy Jan 11, 2019

Choose a reason for hiding this comment

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

While this was a stated intent for Modern, the identifier string (clientMutationId) hasn't actually been removed yet. Not that I disagree with the removal in the spec, but just noting that there will be a mismatch that should be resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it used though? If the functionality still existing in the codebase but isn't a part of how you have to do mutations then it should be fine

Copy link
Contributor

Choose a reason for hiding this comment

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

There's nothing in Relay Modern that expects clientMutationId to be there. It's just one possible workaround to fix the issue described here: #1734 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh ok, I misremembered. Cool, yeah then it can stay as-is 👍

@jstejada
Copy link
Contributor

@orta, just to clarify, are you saying that connections and object identifier are becoming part of the graphql spec? Is that documented somewhere? or is it just officially deemed a "best practice" by graphql? cc @josephsavona

@alloy
Copy link
Contributor

alloy commented Jan 12, 2019

@jstejada The latter. This PR is the first step towards detaching these specs from “Relay”. This original comment might provide some more context graphql/graphql-spec#131 (comment)

@josephsavona
Copy link
Contributor

@alloy that is closed though - is there any actual GraphQL docs that mention these as best practices?

@orta
Copy link
Contributor Author

orta commented Jan 14, 2019

No, there aren't any docs that specify that - as of right now, these Specs are totally considered relay specific.

The term best practices could be switched with "GraphQL Schema Extensions" or something among those lines. However, that best practices was the term we used in the meeting a year ago, but can definitely change. The idea being that they are not a part of the spec, but represent a consolidated approach to problems that can/should be adopted in most schemas.

@josephsavona
Copy link
Contributor

Yeah, I agree that these should be considered best practices, but it would be great if we could have similar messaging on GraphQL docs themselves. Hmm.

@leebyron
Copy link
Contributor

This looks great to me as a first step.

I'd actually suggest the terminology "Common Patterns" instead of "Best Practices" since what we're trying to do with docs like these is capture common problems people encounter when building GraphQL APIs and the best working patterns to apply to those problems.

This isn't really an extension of the schema or spec since these all fit well within the existing spec, they aren't suggesting any additional extensions beyond what GraphQL defines. GraphQL spec just defines the mechanisms by which it works, and the spec itself isn't a great place for trying to codify API patterns like this. However I think the official graphql website docs are a great place for that

As a next step, I would suggest opening a PR on the graphql.org website (https://github.com/graphql/graphql.github.io) which updates https://graphql.org/learn/ to contain a new third header on the side bar "Common Patterns" with a document for each of these api patterns.

The graphql site also uses markdown for docs, so hopefully porting them over is pretty easy to do.

Then, I think it would be helpful to replace the docs on the relay site with a much shorter statement that, if you use these common patterns, Relay leverages them to enable more sophisticated behavior like automatic pagination and smarter caching

@orta
Copy link
Contributor Author

orta commented Jan 24, 2019

Perfect, thanks! I'll get on with this, agree on terminology

Copy link
Contributor

@jstejada jstejada left a comment

Choose a reason for hiding this comment

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

lgtm barring any change in terminology, cc @josephsavona

@josephsavona
Copy link
Contributor

josephsavona commented Jan 28, 2019

I disagree that "common patterns" is appropriate terminology for pagination: "best practice" is the standard terminology to describe a recommended approach to solving a particular problem. The Relay connection spec is the recommended way to implement pagination in GraphQL - per graphql.org, which already includes an informal description of it in the best practices section. We should update that section to include (or link to) the more formal version of the connection spec, and then link to it from the Relay docs as a best practice.

these all fit well within the existing spec

Object identity is a different case - it's a fundamental part of the problem domain that should be covered by the GraphQL spec; the intentional exclusion of this from the spec has led to serious fragmentation in the ecosystem. Relay/Facebook's Node interface is a reasonable workaround to this deficiency in the spec, but other approaches are equally reasonable. Including Relay's approach to object identity as a "common pattern" on graphql.org/learn seems like a good compromise.

So to clarify, the steps are:

  • Send a PR to graphql.org to change https://graphql.org/learn/pagination/ to include or link to the formal version of Relay's connection spec (with naming changed to "GraphQL Connection Spec" or similar). Then update Relay docs to remove the local version and link to the graphql.org one.
  • Send a PR to graphql.org to add a "Common Patterns" section of the /learn page and with an informal description of Relay's approach to object identity with a link to the formal spec, w name changed to "GraphQL Object Identity Spec" or similar. Then update Relay docs to remove the local version and link to the graphql.org one.
  • Longer-term: change the GraphQL spec to include an official approach to object identity.

@orta Interested in updating this PR along those lines and sending PRs to graphql.org?

@orta
Copy link
Contributor Author

orta commented Feb 2, 2019

Yep this makes sense @josephsavona 👍 - if I get time tomorrow I'll move this in that direction

@leebyron
Copy link
Contributor

leebyron commented Feb 2, 2019

I disagree that "common patterns" is appropriate terminology for pagination: "best practice" is the standard terminology

I don’t feel strongly about this either way, so I’ll leave it to your judgement @orta since you’re graciously doing the work. My only recommendation is that the connection pattern and the node/id pattern are near each other, rather than in separate sections, since we typically recommend using them both with equal vigor and we should help make sure readers that find one easily find the other (or others as we expand docs)

Longer-term: change the GraphQL spec to include an official approach to object identity.

I believe we’ve worked through this a couple times and reached an unfulfilling dead end each time, but I’m happy to work through future proposals since I stilll agree it’s a worthy goal

@orta
Copy link
Contributor Author

orta commented Nov 18, 2019

Hey folks, either this week or next (this week is pretty busy for me) - I'm going to update all these PRs including graphql/graphql.github.io#665 and graphql/graphql.github.io#666

Then for the graphQL website side, I'm going to give a week for them to settle then merge the PRs so that from that side the relay specs are recommended as best practices

@orta
Copy link
Contributor Author

orta commented Dec 4, 2019

OK, I think this is everything - all of the GraphQL website side is ready and in production. I've updated this PR and included links to the graphql pages.

Identification lives in: https://graphql.org/learn/global-object-identification/

The Connection spec still lives on Relay, but it is now linked to from the graphQL site: https://graphql.org/learn/pagination/#connection-specification

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@jstejada has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@jstejada merged this pull request in 0cd681e.

jstejada pushed a commit that referenced this pull request Dec 19, 2019
…t practices and not purely a relay spec (#2603)

Summary:
Better late than never, roughly a year ago in the GraphQL Working Group 3 we took it on Artsy to start moving the Relay specs to be considered "GraphQL Best Practices" ([link](https://github.com/graphql/graphql-wg/blob/master/notes/2018-02-01.md#discuss-moving-connectionglobal-id-specs-from-relay-into-best-practices-repo))

This starts that, beginning with first minimizing the use of Relay as being the sole client that conforms to the connection and object identifier spec.

Main notes:

- When referring to relay on the client I switched "Relay" to "Spec-compliant client" or "client"
- When referring to relay's compatibility on the server side, I oriented it to just be "spec-compliant"
- I mostly left the Mutation input spec alone, now that it's only for Relay classic and is close to being removed completely from Relay #2349
- This is step one, once this is merged then I'd like to move both object identification and connection to be on the graphql repos instead of relay and I can handle link updating etc

Happy to change wording etc

/cc leebyron in case you don't watch this repo too closely.
Pull Request resolved: #2603

Reviewed By: josephsavona

Differential Revision: D19071019

Pulled By: jstejada

fbshipit-source-id: cf5a7dfb93cfd565d4f178a51cdff7cd0caec1a0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants