Skip to content

Repeatable directives support#2015

Merged
bbakerman merged 20 commits intomasterfrom
repeatable-directives-support
Nov 15, 2020
Merged

Repeatable directives support#2015
bbakerman merged 20 commits intomasterfrom
repeatable-directives-support

Conversation

@bbakerman
Copy link
Copy Markdown
Member

@bbakerman bbakerman commented Aug 29, 2020

This is a starting branch on repeatable directives.

https://github.com/graphql/graphql-spec/pull/472/files

It supersedes the other PRs however code from them has been incorporated (via copy paste not commits) so we are grateful for those contributions

We have

  • grammar
  • AST directive definition support
  • AST directive container support
  • some tests of that
  • GraphqlXXX runtime support of getting repeatable directives
  • Introspection support for show if a directive is repeatable
  • Tests for schema building with repeatable directives

@bbakerman bbakerman added this to the 16.0 milestone Aug 29, 2020
@bbakerman
Copy link
Copy Markdown
Member Author

See #1916 and #1986

Introspection and better grammar plus GraphlXX runtime types
Comment thread src/main/java/graphql/language/InlineFragment.java
Comment thread src/main/java/graphql/schema/GraphQLEnumValueDefinition.java
* @see DirectiveDefinition#isRepeatable()
*/
@PublicApi
public interface DirectivesContainer<T extends DirectivesContainer> extends Node<T> {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This method pattern is repeated in GraphqlDirectiveContainer as well - same names - same pattern - different types

Comment thread src/main/java/graphql/language/DirectiveDefinition.java
Copy link
Copy Markdown
Contributor

@dugenkui03 dugenkui03 left a comment

Choose a reason for hiding this comment

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

There seem to be some mistake and performance problem, i left some comment for reference.

public static Map<String, GraphQLDirective> directivesByName(List<GraphQLDirective> directiveList) {
return FpKit.getByName(directiveList, GraphQLDirective::getName, FpKit.mergeFirst());

public static Map<String, GraphQLDirective> nonRepeatableDirectivesByName(List<GraphQLDirective> directives) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nonRepeatableDirectivesByName will travel directives three times. The code below seem to be faster:

    public static Map<String, GraphQLDirective> nonRepeatableDirectivesByName(List<GraphQLDirective> directives) {
        // filter the repeatable directives
        List<GraphQLDirective> singletonDirectives = directives.stream()
                .filter(d -> !d.isRepeatable()).collect(Collectors.toList());
        
        return FpKit.getByName(singletonDirectives, GraphQLDirective::getName);
    }

return true;
}

public static List<GraphQLDirective> enforceAdd(List<GraphQLDirective> targetList, GraphQLDirective newDirective) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you think this is an more efficient way to implement enforceAdd:

    public static List<GraphQLDirective> enforceAdd(List<GraphQLDirective> targetList, GraphQLDirective newDirective) {
        assertNotNull(targetList, () -> "directive list can't be null");
        assertNotNull(newDirective, () -> "directive can't be null");

        // check whether the newDirective is repeatable in advance, to avoid needless operations
        if(newDirective.isNonRepeatable()){
            Map<String, List<GraphQLDirective>> map = allDirectivesByName(targetList);
            assertNonRepeatable(newDirective, map);
        }
        targetList.add(newDirective);
        return targetList;
    }

Comment thread src/main/java/graphql/language/NodeUtil.java Outdated
…es-support

# Conflicts:
#	src/main/java/graphql/DirectivesUtil.java
#	src/main/java/graphql/execution/ConditionalNodes.java
#	src/main/java/graphql/language/DirectiveDefinition.java
#	src/main/java/graphql/language/DirectivesContainer.java
#	src/main/java/graphql/language/InlineFragment.java
#	src/main/java/graphql/language/NodeUtil.java
#	src/main/java/graphql/language/SchemaDefinition.java
#	src/main/java/graphql/schema/GraphQLDirectiveContainer.java
#	src/main/java/graphql/schema/GraphQLEnumValueDefinition.java
@dugenkui03
Copy link
Copy Markdown
Contributor

Need "isRepeatable" in IntrospectionQuery for introspection.

Comment thread build.gradle Outdated
testCompile 'org.openjdk.jmh:jmh-core:1.21'
testCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.21'

testCompile 'is.tagomor.woothee:woothee-java:1.11.0'
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is some some rubbish left over testing - this is NOT needed

…es-support

# Conflicts:
#	build.gradle
#	src/main/java/graphql/schema/idl/SchemaGenerator.java
#	src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java

not currently working
@andimarek andimarek added the breaking change requires a new major version to be relased label Nov 3, 2020
Copy link
Copy Markdown
Member

@andimarek andimarek left a comment

Choose a reason for hiding this comment

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

Great work overall!
See my comments.

Comment thread src/main/java/graphql/introspection/Introspection.java Outdated
Comment thread src/main/java/graphql/language/NodeUtil.java Outdated
Comment thread src/test/groovy/graphql/language/AstPrinterTest.groovy
…es-support

# Conflicts:
#	src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java
#	src/main/java/graphql/schema/idl/SchemaTypeChecker.java
…es-support

# Conflicts:
#	src/main/java/graphql/language/Directive.java
#	src/main/java/graphql/language/DirectiveDefinition.java
#	src/main/java/graphql/language/InlineFragment.java
#	src/main/java/graphql/language/SchemaDefinition.java
#	src/main/java/graphql/schema/GraphQLArgument.java
#	src/main/java/graphql/schema/GraphQLDirective.java
#	src/main/java/graphql/schema/GraphQLEnumType.java
#	src/main/java/graphql/schema/GraphQLFieldDefinition.java
#	src/main/java/graphql/schema/GraphQLInputObjectField.java
#	src/main/java/graphql/schema/GraphQLInputObjectType.java
#	src/main/java/graphql/schema/GraphQLObjectType.java
#	src/main/java/graphql/schema/GraphQLScalarType.java
#	src/main/java/graphql/schema/GraphQLSchema.java
#	src/main/java/graphql/schema/GraphQLUnionType.java
…es-support

# Conflicts:
#	src/main/java/graphql/schema/GraphQLUnionType.java
#	src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java
@bbakerman bbakerman merged commit ff3f691 into master Nov 15, 2020
@andimarek andimarek deleted the repeatable-directives-support branch May 4, 2021 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change requires a new major version to be relased

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants