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

Custom query on relationship is not called when Query returns Union type #970

Merged
merged 2 commits into from
Jan 17, 2023

Conversation

edgarsn
Copy link
Contributor

@edgarsn edgarsn commented Jan 15, 2023

Summary

When GraphQL query returns Union Type, it doesn't call custom query on relationship field.

Issue here - #900

As I discussed with @mfn I'm a bit confused how to solve this bug. From my initial observations, it looks like it may involve major code rewrites to fix it, but I could be wrong. I don't have that much knowledge how this package works under the hood, the least I can help with is add tests showing the bug.

I'll appreciate anyone who might want to look at this.

Context

PostType.php

This should only query comments where title column value is lorem.

'comments' => [
	'type' => Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type('Comment')))),
	'query' => function (array $args, $query, $ctx) {
		$query->where('title', 'like', 'lorem');
	},
],

SearchUnionTest.php

  • On line 35, we create a comment for a post with title lorem.
  • On line 36, we create a comment for a post with title ipsum. This should not be included in results.

But it returns both comments.


Type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Misc. change (internal, infrastructure, maintenance, etc.)

Checklist:

  • Existing tests have been adapted and/or new tests have been added
  • Add a CHANGELOG.md entry
  • Update the README.md
  • Code style has been fixed via composer fix-style

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

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

Nice, thanks, that's all we need for now!

I've fixed the remaining code style issue in #971 and also added the (wrong) 2nd comment to the assertion and documented what the problem with it is.

Even though there's no ETA for working on a fix, at least now we've a test documenting the current wrong behaviour and if it gets eventually fixed, we already have a test which is expected to flip!

@mfn mfn marked this pull request as ready for review January 17, 2023 21:46
@mfn mfn merged commit 4e9e3ab into rebing:master Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants