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

Fixed the custom query not being handled by interface's relations #486

Merged

Conversation

EdwinDayot
Copy link
Contributor

Fixes the #421

An Interface requires a public function types returning an array of GraphQL::type() if it contains a relation with a custom query

Still, I'm not a huge fan of this method, so every new idea is appreciated!

@EdwinDayot
Copy link
Contributor Author

Found out that interfaces public function types were useless

@mfn
Copy link
Collaborator

mfn commented Oct 12, 2019

Phu, the changes seem quite complex… I mean, on one side it looks like you just moved stuff around into a dedicated method, but hard to say.

Btw, this one test is failing; what is your test expectation here?

I'm a bit unsure if this change / added complexity is worth it, in its current form (no better suggestion though yet).

@EdwinDayot
Copy link
Contributor Author

The changes are pretty simple actually. Instead of executing all the code before any database request, in the case of an interface's relation, it is executed on the relation's query, as we don't know what model will be requested. Maybe this solution is better than nothing, and if anyone complains about the complexity, or anything, maybe someone will PR something else?

Anyway, if anyone has something better in mind...

@mfn
Copy link
Collaborator

mfn commented Oct 13, 2019

Ok, thx for the info.

I will take a closer look for the review, but that might take a while. If you want to add more details to the source changes (i.e. via github inline comments) to guide the reviewers, that would be much appreciated.

Copy link
Contributor Author

@EdwinDayot EdwinDayot left a comment

Choose a reason for hiding this comment

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

Added some comments

src/Support/InterfaceType.php Show resolved Hide resolved
src/Support/SelectFields.php Outdated Show resolved Hide resolved
src/Support/SelectFields.php Show resolved Hide resolved
src/Support/SelectFields.php Show resolved Hide resolved
@mfn mfn self-requested a review October 17, 2019 18:30
@mfn
Copy link
Collaborator

mfn commented Nov 5, 2019

Thanks for your effort and your patience so far, really appreciated.

I took a longer look today and, whilst not easy, the approach seems 👍 to me!

But my feeling is that it's lacking tests. Only one existing test adapt (which I remember was added in advance for exactly this moment) isn't much.
\Rebing\GraphQL\Support\SelectFields::handleInterfaceFields also seems to have some uncovered parts in the area of if (isset($newParentType->config['types'])) {.

My suggestion would be these steps in order:

  • please add much tests as you can think of / possible
  • invite others to also give feedback; currently thinking about @crissi as being also quite active lately
  • final review and 🤞 merge

How does that sound for your?

PS: without getting ahead, handleInterfaceFields seems like it could use more specific PHP types on the function arguments?

Thanks!

@EdwinDayot EdwinDayot force-pushed the fix/custom-query-relation-field-on-interface branch 2 times, most recently from 285c7c8 to bc6e445 Compare November 8, 2019 15:35
@mfn
Copy link
Collaborator

mfn commented Nov 12, 2019

@EdwinDayot I see so often that you've to make micro commits for the StyleCI violations: it should be rather easy => just click on the "Details" and download / apply the patch.

Good news: we want to switch to something else which allows devs to simply run php cs fixer locally, but it's not yet done => #502

@EdwinDayot
Copy link
Contributor Author

EdwinDayot commented Nov 12, 2019

Could not find the issue with Laravel 5.5 for the moment, if anyone has an idea...

EDIT:
A bit of context:

I'm querying

{
  userQuery {
    id
    likes{
      likable{
        id
        title
        likes{
          id
        }
      }
    }
  }
}

the likable field is an interface implemented by Post and Comment types. As you can see, I just want to select the id and title of these, but for some reason - on Laravel 5.5 - it selects * instead

@EdwinDayot
Copy link
Contributor Author

@EdwinDayot I see so often that you've to make micro commits for the StyleCI violations: it should be rather easy => just click on the "Details" and download / apply the patch.

Good news: we want to switch to something else which allows devs to simply run php cs fixer locally, but it's not yet done => #502

Yeah, that's what I am doing. I wasn't aware of this feature at the beginning, but now, I'm using it :)

@mfn mfn removed their request for review November 12, 2019 20:47
@EdwinDayot
Copy link
Contributor Author

Help wanted

@mfn
Copy link
Collaborator

mfn commented Nov 14, 2019

Ops, the StyleCI integration is still active. On it!

@mfn
Copy link
Collaborator

mfn commented Nov 21, 2019

Help wanted

I believe there's single "fix" for this problem: Laravel 5.5 simply generates a different query and I've adapted to test to consider a different assertion 🤷‍♀️

Tests are all green now (ignore StyleCI…)

Is this PR ready for review?

I just noticed a lot of whitespace changes on phpdoc in SelectFields and many other kinds of formatting changes => can you please undo this and make "as clean PR as possible"?

@EdwinDayot
Copy link
Contributor Author

The PHPDoc has been fixed

@mfn mfn force-pushed the fix/custom-query-relation-field-on-interface branch from 5980885 to 703b30e Compare November 23, 2019 13:23
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.

LGTM 👍

Had a long way coming ;)

I took the liberty and:

  • squashed the 155 (!) commits into one…
    I didn't see much value in this kind of history; mostly it was style fixes
  • added changelog/readme update
    Would be great if you could check them

I've leave it up for feedback of others a few days more, otherwise I plan to merge it somewhen next week.

'alias' => 'title',
],
] + $interface->getFields();
return $interface->getFields();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change actually related somehow or just a cleanup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just some cleanup :)

@EdwinDayot
Copy link
Contributor Author

Readme sounds good to me

@mfn
Copy link
Collaborator

mfn commented Nov 26, 2019

Preparing the merge now

@mfn mfn merged commit a213321 into rebing:master Nov 26, 2019
@mfn
Copy link
Collaborator

mfn commented Nov 26, 2019

Had to restart the travis jobs, thus it took longer. They were all green the first time, but the feedback loop to github didn't seem to work 🤷‍♀️ Retriggering the jobs on travis fixed it 👍

Thanks for the PR :)

@EdwinDayot
Copy link
Contributor Author

Nice :)

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.

None yet

2 participants