Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bingo
ApiQL
Commits
0e426b30
Commit
0e426b30
authored
5 years ago
by
Виктор Волков
Browse files
Options
Download
Plain Diff
Merge branch 'develop' into 'master'
Develop See merge request
!1
parents
bfaa11c4
a5c73aaa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
18 deletions
+50
-18
src/ApiQL.php
src/ApiQL.php
+11
-3
tests/Integration/ApiTest.php
tests/Integration/ApiTest.php
+39
-15
No files found.
src/ApiQL.php
View file @
0e426b30
...
...
@@ -38,9 +38,17 @@ class ApiQL extends AbstractLanguage
*/
private
function
executeFields
()
{
$isProjection
=
false
;
if
(
array_key_exists
(
'fields'
,
$this
->
expression
))
{
$fields
=
!
is_array
(
$this
->
expression
[
'fields'
])
?
explode
(
','
,
$this
->
expression
[
'fields'
])
:
$this
->
expression
[
'fields'
];
$isProjection
=
true
;
$fieldsName
=
'fields'
;
}
elseif
(
array_key_exists
(
'select'
,
$this
->
expression
))
{
$isProjection
=
true
;
$fieldsName
=
'select'
;
}
if
(
$isProjection
)
{
$fields
=
!
is_array
(
$this
->
expression
[
$fieldsName
])
?
explode
(
','
,
$this
->
expression
[
$fieldsName
])
:
$this
->
expression
[
$fieldsName
];
if
(
!
empty
(
$fields
))
{
foreach
(
$fields
as
$field
)
{
self
::
$builder
->
addSelect
(
$field
);
...
...
@@ -48,7 +56,7 @@ class ApiQL extends AbstractLanguage
}
else
{
self
::
$builder
->
addSelect
(
'*'
);
}
unset
(
$this
->
expression
[
'
fields
'
]);
unset
(
$this
->
expression
[
$
fields
Name
]);
}
else
{
self
::
$builder
->
addSelect
(
'*'
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/Integration/ApiTest.php
View file @
0e426b30
...
...
@@ -779,21 +779,37 @@ final class ApiTest extends TestCase
public
function
testDynamicFields
()
{
//arrange
$payload
=
[
"spec"
=>
"not_in"
,
"b"
=>
[
2
,
5
,
7
],
"fields"
=>
[
"a"
,
"c"
]];
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertArrayHasKey
(
"a"
,
$data
[
0
]
);
//assert
$this
->
assertArrayHasKey
(
"c"
,
$data
[
0
]
);
//arrange
$payload
=
[
"spec"
=>
"not_in"
,
"b"
=>
[
2
,
5
,
7
],
"fields"
=>
[
"a"
,
"c"
]];
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertArrayHasKey
(
"a"
,
$data
[
0
]
);
//assert
$this
->
assertArrayHasKey
(
"c"
,
$data
[
0
]
);
//arrange
$payload
=
[
"spec"
=>
"not_in"
,
"b"
=>
[
2
,
5
,
7
],
"select"
=>
[
"a"
,
"c"
]];
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertArrayHasKey
(
"a"
,
$data
[
0
]
);
//assert
$this
->
assertArrayHasKey
(
"c"
,
$data
[
0
]
);
//arrange
$payload
=
[
"spec"
=>
"not_in"
,
"b"
=>
"2,5,7"
,
"fields"
=>
[
"a"
,
"c"
]];
...
...
@@ -1333,6 +1349,7 @@ final class ApiTest extends TestCase
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertCount
(
3
,
$data
...
...
@@ -1343,6 +1360,7 @@ final class ApiTest extends TestCase
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertCount
(
3
,
$data
...
...
@@ -1354,6 +1372,7 @@ final class ApiTest extends TestCase
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertCount
(
2
,
$data
...
...
@@ -1364,6 +1383,7 @@ final class ApiTest extends TestCase
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertCount
(
2
,
$data
...
...
@@ -1374,6 +1394,7 @@ final class ApiTest extends TestCase
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertCount
(
2
,
$data
...
...
@@ -1394,6 +1415,7 @@ final class ApiTest extends TestCase
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertCount
(
2
,
$data
...
...
@@ -1404,6 +1426,7 @@ final class ApiTest extends TestCase
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertCount
(
2
,
$data
...
...
@@ -1414,6 +1437,7 @@ final class ApiTest extends TestCase
$repo
=
new
ApiRepository
(
self
::
$cnx
);
//act
$data
=
$repo
->
get
(
$payload
);
//assert
$this
->
assertCount
(
2
,
$data
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment