-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 17515 graphql reserved names for certain types (#17989)
* #17515 determine if field name and type will clash with graphql inherited fields * #17515 better comment * #17515 add integration tests * #17515 more test cases * #17515 codacy and code-review
- Loading branch information
Showing
8 changed files
with
340 additions
and
55 deletions.
There are no files selected for viewing
304 changes: 266 additions & 38 deletions
304
dotCMS/src/integration-test/java/com/dotcms/contenttype/business/FieldAPITest.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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
32 changes: 30 additions & 2 deletions
32
dotCMS/src/main/java/com/dotcms/graphql/util/GraphQLUtil.java
This file contains 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 |
---|---|---|
@@ -1,11 +1,39 @@ | ||
package com.dotcms.graphql.util; | ||
|
||
import com.dotcms.contenttype.model.field.Field; | ||
import com.dotcms.graphql.InterfaceType; | ||
import com.dotmarketing.business.APILocator; | ||
import graphql.schema.GraphQLList; | ||
import graphql.schema.GraphQLType; | ||
import java.util.Set; | ||
|
||
public class GraphQLUtil { | ||
|
||
public static Set<String> getFieldReservedWords() { | ||
return InterfaceType.RESERVED_GRAPHQL_FIELD_NAMES; | ||
public static boolean isVariableGraphQLCompatible(final Field field) { | ||
// first let's check if there's an inherited field with the same variable | ||
if(InterfaceType.getContentletInheritedFields().containsKey(field.name())) { | ||
// now let's check if the graphql types are compatible | ||
|
||
// get inherited field's graphql type | ||
final GraphQLType inheritedFieldGraphQLType = InterfaceType.getContentletInheritedFields() | ||
.get(field.name()).getType(); | ||
|
||
// get new field's type | ||
final GraphQLType fieldGraphQLType = APILocator.getGraphqlAPI() | ||
.getGraphqlTypeForFieldClass(field.type(), field); | ||
|
||
// if at least one of them is a custom type, they need to be equal to be compatible | ||
return (!isCustomFieldType(inheritedFieldGraphQLType) | ||
&& !isCustomFieldType(fieldGraphQLType)) | ||
|| inheritedFieldGraphQLType.equals(fieldGraphQLType); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static boolean isCustomFieldType(final GraphQLType type) { | ||
return type instanceof GraphQLList ? APILocator.getGraphqlAPI().getCustomFieldTypes() | ||
.contains(((GraphQLList) type).getWrappedType()) | ||
: APILocator.getGraphqlAPI().getCustomFieldTypes().contains(type); | ||
} | ||
} |