-
Notifications
You must be signed in to change notification settings - Fork 119
Missing GraphQL filters + tests #1754
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
Open
plyhun
wants to merge
11
commits into
hotfix-3.1.x
Choose a base branch
from
hotfix-3.1.x-sup-19716
base: hotfix-3.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d21a9c9
Missing GraphQL filters + tests
plyhun 086bfa2
Nested tags sorting fixed
plyhun b86d0c2
Changelog
plyhun d082136
Fix for the failing whole GraphQL endpoint, if the schema has no fields
plyhun 0a8cd7c
Update dependencies
npomaroli 7aae983
Remove the fix for noIndex flag triggering migration
plyhun e978c89
Merge remote-tracking branch 'origin/hotfix-3.1.x-sup-19781' into hot…
plyhun 2768d84
Test fix
plyhun 3fd47e6
More (micro)schema fields to server over GraphQL
plyhun 96dff3c
Regression fix
plyhun 381d045
Revert the changes for localized message
plyhun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| GraphQL: Filtering has been enabled for the selected entities: schemas, microschemas, tags, tag families. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| microschemas { | ||
| elements { | ||
| uuid | ||
| isNoIndex | ||
| } | ||
| } | ||
| } | ||
|
|
||
17 changes: 17 additions & 0 deletions
17
tests/tests-core/src/main/resources/graphql/microschemas-query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| microschemas (filter: {name: {oneOf: ["vcard", "whatever"]}}, sort: {name: ASCENDING}) { | ||
| # [$.data.microschemas.totalCount=1] | ||
| totalCount | ||
| elements { | ||
| # [$.data.microschemas.elements[0].name=vcard] | ||
| name | ||
| # [$.data.microschemas.elements[0].uuid=<is-uuid>] | ||
| uuid | ||
| # [$.data.microschemas.elements[0].isNoIndex=<is-null>] | ||
| isNoIndex | ||
| # [$.data.microschemas.elements[0].isEmpty=false] | ||
| isEmpty | ||
| } | ||
| } | ||
| } | ||
| # [$.errors=<is-undefined>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| schemas (filter: {name: {oneOf: ["content", "whatever"]}}, sort: {name: ASCENDING}) { | ||
| # [$.data.schemas.totalCount=1] | ||
| totalCount | ||
| elements { | ||
| # [$.data.schemas.elements[0].name=content] | ||
| name | ||
| # [$.data.schemas.elements[0].uuid=<is-uuid>] | ||
| uuid | ||
| # [$.data.schemas.elements[0].isNoIndex=<is-null>] | ||
| isNoIndex | ||
| # [$.data.schemas.elements[0].isEmpty=false] | ||
| isEmpty | ||
| # [$.data.schemas.elements[0].isAutoPurge=<is-null>] | ||
| isAutoPurge | ||
| } | ||
| } | ||
| } | ||
| # [$.errors=<is-undefined>] |
21 changes: 21 additions & 0 deletions
21
tests/tests-core/src/main/resources/graphql/tagfamilies-query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| tagFamilies (filter: {name: {oneOf: ["colors", "basic", "whatever"]}}, sort: {name: DESCENDING}) { | ||
| # [$.data.tagFamilies.totalCount=2] | ||
| totalCount | ||
| elements { | ||
| # [$.data.tagFamilies.elements[0].name=colors] | ||
| name | ||
| # [$.data.tagFamilies.elements[0].uuid=<is-uuid>] | ||
| uuid | ||
| tags (sortBy: "name", sortOrder: ASCENDING) { | ||
| # [$.data.tagFamilies.elements[0].tags.totalCount=3] | ||
| totalCount | ||
| elements { | ||
| # [$.data.tagFamilies.elements[0].tags.elements[0].name=blue] | ||
| name | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| # [$.errors=<is-undefined>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| tags (filter: {name: {oneOf: ["red", "jeep", "whatever"]}, tagFamily: {name: {oneOf: ["colors"]}}}, sort: {name: ASCENDING}) { | ||
| # [$.data.tags.totalCount=1] | ||
| totalCount | ||
| elements { | ||
| # [$.data.tags.elements[0].name=red] | ||
| name | ||
| # [$.data.tags.elements[0].uuid=<is-uuid>] | ||
| uuid | ||
| } | ||
| } | ||
| } | ||
| # [$.errors=<is-undefined>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
verticles/graphql/src/main/java/com/gentics/mesh/graphql/filter/TagFamilyFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.gentics.mesh.graphql.filter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import com.gentics.graphqlfilter.filter.FilterField; | ||
| import com.gentics.mesh.ElementType; | ||
| import com.gentics.mesh.core.data.tagfamily.HibTagFamily; | ||
|
|
||
| /** | ||
| * Filters tag families in GraphQl. This filter should be used whenever a list of tag families is returned. | ||
| */ | ||
| public class TagFamilyFilter extends EntityFilter<HibTagFamily> { | ||
|
|
||
| private static final ElementType ELEMENT = ElementType.TAGFAMILY; | ||
| private static final String NAME = "TagFamilyFilter"; | ||
|
|
||
| private static TagFamilyFilter instance; | ||
|
|
||
| public static synchronized TagFamilyFilter filter() { | ||
| if (instance == null) { | ||
| instance = new TagFamilyFilter(); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| private TagFamilyFilter() { | ||
| super(NAME, "Filters tag families", Optional.of(ELEMENT.name())); | ||
| } | ||
|
|
||
| @Override | ||
| protected List<FilterField<HibTagFamily, ?>> getFilters() { | ||
| String owner = ELEMENT.name(); | ||
| List<FilterField<HibTagFamily, ?>> filters = new ArrayList<>(); | ||
| filters.add(CommonFields.hibNameFilter(owner)); | ||
| filters.add(CommonFields.hibUuidFilter(owner)); | ||
| filters.addAll(CommonFields.hibUserTrackingFilter(owner)); | ||
| return filters; | ||
| } | ||
|
|
||
| @Override | ||
| protected ElementType getEntityType() { | ||
| return ELEMENT; | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
verticles/graphql/src/main/java/com/gentics/mesh/graphql/filter/TagFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.gentics.mesh.graphql.filter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import com.gentics.graphqlfilter.filter.DateFilter; | ||
| import com.gentics.graphqlfilter.filter.FilterField; | ||
| import com.gentics.graphqlfilter.filter.MappedFilter; | ||
| import com.gentics.graphqlfilter.filter.operation.JoinPart; | ||
| import com.gentics.mesh.ElementType; | ||
| import com.gentics.mesh.core.data.tag.HibTag; | ||
| import com.gentics.mesh.core.data.user.HibUserTracking; | ||
|
|
||
| import graphql.util.Pair; | ||
|
|
||
| /** | ||
| * Filters tags in GraphQl. This filter should be used whenever a list of tags is returned. | ||
| */ | ||
| public class TagFilter extends EntityFilter<HibTag> { | ||
|
|
||
| private static final ElementType ELEMENT = ElementType.TAG; | ||
| private static final String NAME = "TagFilter"; | ||
|
|
||
| private static TagFilter instance; | ||
|
|
||
| public static synchronized TagFilter filter() { | ||
| if (instance == null) { | ||
| instance = new TagFilter(); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| private TagFilter() { | ||
| super(NAME, "Filters tags", Optional.of(ELEMENT.name())); | ||
| } | ||
|
|
||
| @Override | ||
| protected List<FilterField<HibTag, ?>> getFilters() { | ||
| String owner = ELEMENT.name(); | ||
| List<FilterField<HibTag, ?>> filters = new ArrayList<>(); | ||
| filters.add(CommonFields.hibNameFilter(owner)); | ||
| filters.add(CommonFields.hibUuidFilter(owner)); | ||
| filters.addAll(CommonFields.hibUserTrackingFilter(owner)); | ||
| filters.add(new MappedFilter<>(owner, "tagFamily", "Filters by creator", TagFamilyFilter.filter(), HibTag::getTagFamily, Pair.pair("tagFamily", new JoinPart(ElementType.USER.name(), "uuid")))); | ||
| return filters; | ||
| } | ||
|
|
||
| @Override | ||
| protected ElementType getEntityType() { | ||
| return ELEMENT; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -598,16 +598,29 @@ protected PagingParameters getPagingInfo(DataFetchingEnvironment env) { | |
| parameters.setPerPage(perPage); | ||
| } | ||
| String sortBy = env.getArgument("sortBy"); | ||
| SortOrder sortOrder = env.getArgument("sortOrder"); | ||
| Sorting sortOrder = env.getArgument("sortOrder"); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong type cast. |
||
| if (StringUtils.isNotBlank(sortBy) && sortOrder != null) { | ||
| parameters.putSort(sortBy, sortOrder); | ||
| parameters.putSort(sortBy, fromGraphQl(sortOrder)); | ||
| } | ||
| Map<String, ?> sortArgument = env.getArgument("sort"); | ||
| parameters.putSort(parseGraphQlSort(sortArgument, Optional.empty())); | ||
| parameters.validate(); | ||
| return parameters; | ||
| } | ||
|
|
||
| private static SortOrder fromGraphQl(Sorting sorting) { | ||
| if (sorting == null) { | ||
| return null; | ||
| } | ||
| switch (sorting) { | ||
| case ASCENDING: | ||
| return SortOrder.ASCENDING; | ||
| case DESCENDING: | ||
| return SortOrder.DESCENDING; | ||
| } | ||
| return SortOrder.UNSORTED; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static final Map<String, SortOrder> parseGraphQlSort(Map<String, ?> sort, Optional<String> prefix) { | ||
| if (sort == null) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as
autoPurgeflag above, we serve here tri-state value, true, false and null, just for the consistency.