New validation rules about type, field, argument#1955
Conversation
256cb9a to
a90e4e3
Compare
andimarek
left a comment
There was a problem hiding this comment.
Thanks a lot for these new rules.
Please have a look at my comments.
|
|
||
| private boolean isScalarOrIntrospectionTypes(GraphQLNamedType type) { | ||
| if (type instanceof GraphQLScalarType && ( | ||
| type.getName().equals("Int") || type.getName().equals("Float") || type.getName().equals("String") || |
There was a problem hiding this comment.
we should only treat the build-in scalar types (Int, Float, String, Boolean and ID) in a special way. The others are not really special and should be treated as every other custom scalar.
We also have a helper method in Scalars (I believe) to determine if the type is a build-in one or not
There was a problem hiding this comment.
Thanks for your suggestion.
| return; | ||
| } | ||
|
|
||
| List<Type> memberTypes = definition.getMemberTypes(); |
There was a problem hiding this comment.
we should not need to check the AST definition here. Just getting the members of the type should be enough.
There was a problem hiding this comment.
types in GraphQLUnionType.Builder is a Map(code link), which will lost the type with duplicated name.
Maybe it will be better to move unique member check to SchemaTypeChecker.
There was a problem hiding this comment.
I will followed your suggestion instead of removed it, because types definied in GraphQLUnionType is list after all.
Then I will add unique member check to SchemaTypeChecker in another PR.
Is that appropriate?
| } | ||
| } | ||
|
|
||
| private void validateObject(GraphQLObjectType type, SchemaValidationErrorCollector errorCollector) { |
There was a problem hiding this comment.
can we combine validateObject and validateInterface?
I would also suggest a more prescriptive name like validateContainsField or so.
There was a problem hiding this comment.
Thanks for your suggestion.
| return true; | ||
| } | ||
|
|
||
| if (type instanceof GraphQLObjectType && ( |
There was a problem hiding this comment.
IntrospectionQuery is not a special type at all (it is just a name).
There was a problem hiding this comment.
graphql-java framework contains a type named IntrospectionQuery, which contains fields start with '__', and is used for introspection.
I add a method named isIntrospectionTypes(), which is used in filterBuiltInTypes(). details in new commit.
| return graphQLNamedTypes.stream().filter(type -> !isScalarOrIntrospectionTypes(type)).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private boolean isScalarOrIntrospectionTypes(GraphQLNamedType type) { |
There was a problem hiding this comment.
could this whole method just check for __ prefix?
There was a problem hiding this comment.
Replace it by filterBuiltInTypes, which aimed to filter Built-In Types.
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| return graphQLNamedTypes.stream().filter(type -> !isScalarOrIntrospectionTypes(type)).collect(Collectors.toList()); |
There was a problem hiding this comment.
We have static util methods (in FpKit I believe), please use them instead of using directly filter etc.
There was a problem hiding this comment.
Thanks for your suggestion.
| class TypeAndFieldRuleTest extends Specification { | ||
|
|
||
|
|
||
| def "type must define one or more fields."() { |
There was a problem hiding this comment.
we should add tests for Interfaces here as well.
There was a problem hiding this comment.
Thanks for your suggestion.
| errorCollector.addError(validationError); | ||
| } | ||
|
|
||
| List<String> typeNames = new ArrayList<>(); |
There was a problem hiding this comment.
I think a Set is better here as track just the names we already saw.
There was a problem hiding this comment.
Thanks for your suggestion.
a23d7e4 to
59a1377
Compare
59a1377 to
9ff53d2
Compare
|
hi @andimarek , appreciate your time for this. is there any thing else I need to do for this PR? I think is is pretty important to improve schema validation in future release version. |
|
Hi, is there any way to help in review of this PR? |
* Fixed test to include a field because validation in graphql now requires ypes to have one or more fields ( graphql-java/graphql-java#1955 ) * Removed references to arguments when recreation ExecutionStrategyParameters because arguments field was dropped in graphql-java ( https://github.com/graphql-java/graphql-java/pull/2023/files#diff-d31b54bc13a6051c43027e76627c6e99de28f64adfcfcfb275856ec00890cc4fL44 ) * Updated tests to work with immutable structures that graphql-java has moved to ( https://github.com/graphql-java/graphql-java/pull/2086/files#diff-9fed7fa709720e6a47a80119bb991def6fa752f8933d9f5e3dfcede5520c07d6R134 )
The validation about GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLScalarType.
Details in specification: TypeSystem