Return latest revision of content

Created on 13 May 2024, 7 months ago
Updated 11 June 2024, 6 months ago

Problem/Motivation

Provide the ability to retrieve the latest revision of the content being queried through a `node` or `media` query. There are situations in which the revision id or node preview path are not known which will prevent using the path approach.

Additionally, providing a way retrieve the latest revision brings feature parity with JSON:API ( https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi... β†’ )

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Expose a parameter to allow for a revision version (latest, working-copy, or revision id) to be provided to the query

Data model changes

TBD - There might be a need to provide the revision id within the base fields for an entity

✨ Feature request
Status

Fixed

Version

2.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bstan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @bstan
  • Pipeline finished with Success
    7 months ago
    Total: 421s
    #172462
  • Pipeline finished with Failed
    7 months ago
    Total: 499s
    #172578
  • Pipeline finished with Failed
    7 months ago
    Total: 501s
    #172593
  • Pipeline finished with Failed
    7 months ago
    Total: 490s
    #172613
  • πŸ‡ΊπŸ‡ΈUnited States bstan

    bstan β†’ changed the visibility of the branch 2.2.x to hidden.

  • Pipeline finished with Failed
    7 months ago
    Total: 497s
    #172729
  • Pipeline finished with Failed
    7 months ago
    Total: 493s
    #172732
  • Pipeline finished with Failed
    7 months ago
    Total: 445s
    #172761
  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί

    Apologies for the 2.2.x dev spam, fumbling around in CI to get Drupal 11 support tested.

    Please assign me in gitlab for a review once you're happy with it.

  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί
  • Pipeline finished with Failed
    7 months ago
    Total: 340s
    #173349
  • Pipeline finished with Failed
    7 months ago
    Total: 254s
    #173402
  • Pipeline finished with Failed
    7 months ago
    Total: 252s
    #173409
  • Pipeline finished with Failed
    7 months ago
    Total: 254s
    #173445
  • Pipeline finished with Failed
    7 months ago
    Total: 225s
    #173455
  • Pipeline finished with Success
    7 months ago
    Total: 210s
    #173460
  • πŸ‡ΊπŸ‡ΈUnited States bstan

    @almunnings I dont seem to have the ability to add a reviewer, but this MR is ready for review.

  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί

    Just a hunch, but I suspect people might get a bit more use out of this with opening up the input to be a String, rather than an Enum.

    We could load in by revision ID then.

    WORKING_COPY also seems redundant, as it's the same as providing no value.

    So I'm kind of leaning into:

    - Change input arg to String
    - Remove Enum
    - Rename "Version" to "EntityRevision"
    - Check for "latest" or attempt to load revision by arg value.
    - Integrate graphql Buffer `EntityRevisionBuffer` to do the loading

    If you're cool with that, I can have a refactor this weekend.

  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί

    almunnings β†’ changed the visibility of the branch 2.2.x to active.

  • Merge request !80Return latest revision of content β†’ (Merged) created by almunnings
  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί

    almunnings β†’ changed the visibility of the branch 2.2.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States bstan

    Yeah, this works for me, I went back-and-forth on the Enum versus String but went the Enum route since it allow for input to be "fixed" to 2 options.

    With that said, I would prefer to keep a value to just get the working copy in the event the revision id is not available. This helps logically with a decoupled frontend, for example:

    // Next.js 
    const { isEnabled } = draftMode()
    
    const query = gql`
    query($id: String, $revision: String) {
      node(id: $id, revision: $revision) {
          ....
      }
    }
    `
    
    await someGraphQLClient.query({
      query,
      variables: {
        id,
       revision: isEnabled ? 'working-copy' : ''
      }
    
  • Status changed to Needs review 7 months ago
  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί

    @bstan Did you want to run your eyes over https://git.drupalcode.org/project/graphql_compose/-/merge_requests/80 please

    I think it'll cover your use case.

    Added in some junk code, but it'll do nicely:

    
    
    
      /**
       * The latest revision identifiers.
       */
      const REVISION_LATEST = [
        'latest',
        'newest',
        'working',
        'working-copy',
      ];
    
      /**
       * The current revision identifiers.
       */
      const REVISION_CURRENT = [
        'active',
        'current',
        'default',
      ];
    

    So you should be able to do:

    node(id: 123, revision: 'working-copy') {} // or latest, newest, working
    node(id: 123, revision: 'current') {} // or active, default
    node(id: 123, revision: 456) {}
    node(id: 123) {}
    

    Have a go, let me know!

  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί

    I’ll take it onboard though. It can be reworked to only request once.

  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί

    I guess we need to make a decision.

    If lang code is requested, and latest is requested, and there is no latest revision for that language… null ok?

    Seems logical

    Although we might not even make it here, as the entity load with language could also fail if there was no revision.

    I might make a test today and just set this in stone

  • Status changed to Fixed 7 months ago
  • πŸ‡¦πŸ‡ΊAustralia almunnings Melbourne, πŸ‡¦πŸ‡Ί

    Merged into 2.2-dev, no plans to back port at this stage.

    Thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024