Skip to content

Add relative uri to MenuItem#2363

Merged
jasonbahl merged 11 commits intowp-graphql:developfrom
josephfusco:fix-menu-path-for-subdirectory-ms
May 16, 2022
Merged

Add relative uri to MenuItem#2363
jasonbahl merged 11 commits intowp-graphql:developfrom
josephfusco:fix-menu-path-for-subdirectory-ms

Conversation

@josephfusco
Copy link
Copy Markdown
Member

What does this implement/fix? Explain your changes.

This fixes an issue with using wp-graphql in a WordPress multisite using subdirectories where the individual site subdirectory is included with the menu path.

Does this close any currently open issues?

#2362

Any relevant logs, error output, GraphiQL screenshots, etc?

Before
Screen Shot 2022-05-04 at 3 24 03 PM

After
Screen Shot 2022-05-04 at 3 23 49 PM

Where has this been tested?

Operating System: macOS 12.3.1
WordPress Version: 5.9.2

@justlevine
Copy link
Copy Markdown
Collaborator

justlevine commented May 4, 2022

Nice!

Would it be better to add a uri field in addition to the existing url, instead of changing the expectation (and breaking behavior) of either url (a fully qualified url) and path (the relative path on the server)?

This is how User objects do it:
image

@josephfusco
Copy link
Copy Markdown
Member Author

@justlevine I added a new uri field rather than modifying the pre-existing path as suggested.

Here's how it looks now

Screen Shot 2022-05-05 at 1 08 47 PM

@justlevine justlevine added type: enhancement Improvements to existing functionality component: multisite Relating to WordPress Multisite needs: tests Tests should be added to be sure this works as expected labels May 6, 2022
@justlevine justlevine changed the title Remove multisite subdirectory from menu path Add relative uri to MenuItem May 6, 2022
@justlevine
Copy link
Copy Markdown
Collaborator

Hey @josephfusco , I tweaked your code a bit to follow the patterns used for other uri fields. Can you confirm it still works on multisite? (It should be fine, but multisite support is still a bit spotty ).

It seems that MenuItems aren't really tested, so I'm gonna take a minute to backfill those before marking this ready.

@coveralls
Copy link
Copy Markdown

coveralls commented May 6, 2022

Coverage Status

Coverage increased (+0.3%) to 79.781% when pulling 2e0604d on josephfusco:fix-menu-path-for-subdirectory-ms into ccaf4e6 on wp-graphql:develop.

@josephfusco
Copy link
Copy Markdown
Member Author

Hey @justlevine I greatly appreciate your help with this!

After giving this more thought, I'm going to close this out add to fix to the faustwp WordPress plugin. It feels like the more appropriate place to put this seeing that faustwp is the one that is replacing the subdirectory.

@justlevine
Copy link
Copy Markdown
Collaborator

justlevine commented May 6, 2022

@josephfusco I believe this should stay open. While its true that Faust is doing a bad replace on the url, there are a lot of use cases for a relative uri, and it makes the object behave more uniformly with other Nodes that can have an associated link.

If you prefer, I can create a separate PR - lemme know!

@justlevine justlevine reopened this May 6, 2022
@justlevine justlevine force-pushed the fix-menu-path-for-subdirectory-ms branch from 4de571d to 11caf85 Compare May 6, 2022 16:38
@josephfusco
Copy link
Copy Markdown
Member Author

@justlevine Works for me! Feel free to keep it on this PR :)

@justlevine justlevine added object type: menu Relating to the Menu or MenuItem Type status: in review Awaiting review before merging or closing and removed needs: tests Tests should be added to be sure this works as expected labels May 6, 2022
@justlevine
Copy link
Copy Markdown
Collaborator

@jasonbahl not sure why the schema linter is failing 🤔

@jasonbahl
Copy link
Copy Markdown
Collaborator

@justlevine looks probably related with this latest release of the schema linter: https://github.com/cjoudrey/graphql-schema-linter/releases/tag/v3.0.0

@jasonbahl
Copy link
Copy Markdown
Collaborator

looks like we'll need to explicitly install graphql in the workflow now

@jasonbahl
Copy link
Copy Markdown
Collaborator

I just fixed the Schema linter in #2368

@justlevine justlevine force-pushed the fix-menu-path-for-subdirectory-ms branch from 11caf85 to a274fd2 Compare May 6, 2022 18:46
@justlevine
Copy link
Copy Markdown
Collaborator

@jasonbahl And it's passing again 🚀. Ready for your review :)

@jasonbahl
Copy link
Copy Markdown
Collaborator

I think this looks good, but the blocker for me is that our test environments aren't setup to test in multisite at the moment.

I'll open another issue to track that. Once we have the ability to run tests in multisite, we should be able to get this properly tested and merged.

@jasonbahl
Copy link
Copy Markdown
Collaborator

Ah issue for multisite tests here: #2275

@justlevine justlevine added status: blocked Progress halted due to dependencies or issues and removed status: in review Awaiting review before merging or closing labels May 12, 2022
@jasonbahl
Copy link
Copy Markdown
Collaborator

Ok, so I got #2375 merged, so now we have tests running in multisite!

I'll work up a test for this so we can get this merged.

@justlevine
Copy link
Copy Markdown
Collaborator

I'll work up a test for this so we can get this merged.

Only thing that should be missing is an assertEquals() for $actual['data']['menuItem']['path'];

[
'description' => __( 'Navigation menu items are the individual items assigned to a menu. These are rendered as the links in a navigation menu.', 'wp-graphql' ),
'interfaces' => [ 'Node', 'DatabaseIdentifier' ],
'interfaces' => [ 'Node', 'DatabaseIdentifier', 'UniformResourceIdentifiable' ],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah, so even though the MenuItem type has a uri field, Menu Items are not actually uniquely identifiable by a URI.

If you take the MenuItem.uri field and do a nodeByUri( $uri: MenuItem.uri ) { ... } query, you will get another node (Post, Page, etc)

The MenuItem Type should not implement the UniformResourceIdentifiable interface, as a MenuItem is not identifiable by a URI. It links to other nodes that are identifiable by uri, but it by itself is not.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we look in the Schema now for the nodeByUri field, we see that it returns UniformResourceIdentifiable Interface, which now has MenuItem as a Possible Type, which is misleading, as nodeByUri will never return an object with type MenuItem

CleanShot 2022-05-13 at 16 32 49

@jasonbahl
Copy link
Copy Markdown
Collaborator

I left some notes about the uri field / UniformResourceIdentifiable Interface.

I think I'm ok with having the uri field as a non-breaking change here, but I think we should remove the UniformResourceIdentifiable interface, as this Type is not actually identifiable by a uri. The nodes that MenuItem links to are identifiable by the uri, but not the MenuItem itself.

@jasonbahl
Copy link
Copy Markdown
Collaborator

I pushed up a commit to remove UniformResourceIdentifiable from the MenuItem type

@qlty-cloud-legacy
Copy link
Copy Markdown

Code Climate has analyzed commit 2e0604d and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@jasonbahl
Copy link
Copy Markdown
Collaborator

jasonbahl commented May 13, 2022

Pushed a follow-up commit adding the uri field back to the MenuItem Type since it was removed when removing the UniformResourceIdentifiable Interface from the Type.

Now, we can query the uri field of a MenuItem, but MenuItem will not be shown as a possibleType in nodeByUri queries.

@jasonbahl
Copy link
Copy Markdown
Collaborator

I think we still might need to have a specific test where we do something like the following:

  • create a new blog in the multisite
  • switch to blog
  • create a menu with some menu items
  • assign the menu to a location (so it's public)
  • query the menu
  • assert that the blog directory is not in the uri

🤔

@jasonbahl jasonbahl merged commit d3d2328 into wp-graphql:develop May 16, 2022
@jasonbahl jasonbahl mentioned this pull request May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: multisite Relating to WordPress Multisite object type: menu Relating to the Menu or MenuItem Type status: blocked Progress halted due to dependencies or issues type: enhancement Improvements to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants