Skip to content

Support aliases for selection set and arguments for scalar selected fields. #15

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

Closed
wants to merge 1 commit into from

Conversation

actionm
Copy link
Contributor

@actionm actionm commented Sep 4, 2019

mghoneimy/php-graphql-oqm#1 (comment)

The ability to set arguments for scalar selected fields.

selectField($selectedField, string $alias = null, array $arguments = [])

Example:

selectField('field_one', 'fieldAlias', ['param1' => 'val1', 'param2' => 'val2' ]);

Support aliases and arguments for selection set.

setSelectionSet(array $selectionSet)

Example:

setSelectionSet([
             'aliasId:first_field' => ['param1' => 'val1', 'param2' => 'val2' ],
             'second_field' => ['param1' => 'val1', 'param2' => 'val2' ]
        ])

fix: pass tests on windows PHP_EOL.

Add the ability to set arguments for scalar selected fields.
fix: pass tests on windows PHP_EOL.
@actionm actionm marked this pull request as ready for review September 4, 2019 13:49
@mghoneimy
Copy link
Owner

mghoneimy commented Sep 7, 2019

@actionm Two comments on the design here:

  1. The change your made to how setSelectionSet works will break backward-compatibility. People who set the array with values directly will have their code break now because it expects the selected field name to be in the key, not value.
  2. How will this work with nested selection sets? (i.e. nested query objects) With the current implementation, you will need to set the query object as the array index, which will not work.

@mghoneimy
Copy link
Owner

@actionm Actually, I was wrong on point (1), your change will not break backward-compatibility. We just need to discuss point (2). I'm going over the code in details now as well.


if (is_array($arguments) && count($arguments)) {

$params = '';
Copy link
Owner

Choose a reason for hiding this comment

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

@actionm We already have a method that converts an arguments array into a string representation, we should figure out how to re-use it here rather than duplicate it. It's in the Query class.

if (is_array($arguments) && count($arguments)) {

$params = '';
foreach ($arguments as $k => $v) {
Copy link
Owner

Choose a reason for hiding this comment

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

@actionm Another instance of code duplication for the same functionality.

);


}
Copy link
Owner

Choose a reason for hiding this comment

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

@actionm We need tests for sub-selections (nested queries) with arguments/aliases.

(string) $builder->getQuery()
);

}
Copy link
Owner

Choose a reason for hiding this comment

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

@actionm We need a test to cover the case of usage of arguments without aliases.

@@ -22,14 +22,35 @@ trait FieldTrait
public function setSelectionSet(array $selectionSet)
Copy link
Owner

Choose a reason for hiding this comment

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

@actionm I kind of don't understand why this change is necessary? 🤔
Is it because you want to add the feature of selecting fields with aliases and arguments through the Query class? It's not required for selecting one field through the AbstractQueryBuilder as it converts all selected fields into string before the selection set is set in the query class. Or maybe I'm missing something here.

@mghoneimy
Copy link
Owner

@actionm My suggestion to overcoming the nested Query problem would be to add an $alias property to the query class and add an optional parameter to the Query::__construct that sets that alias. If the alias is available it should be set in the query, therefore appearing in the nested selection, otherwise, everything will go as normal.

@mghoneimy mghoneimy closed this Sep 18, 2020
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