This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Field Arguments #56
Merged
Merged
Field Arguments #56
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d3c7aa3
Upgrade gradle and use latest common build scripts
jamesdh 3192f53
build-scan plugin no longer works w/ gradle 6+
jamesdh a839af6
Promote for reuse by fields
jamesdh 5c2d39c
This has been resolved in groovy 2.5.6+
jamesdh fc5d37e
Explicitly upcast
jamesdh 28e1755
Extract arguments into a trait
jamesdh db1ff59
Fixes static compilation issue
jamesdh 06d1392
Use arguments on properties
jamesdh b44c60c
Support building field-level arguments
jamesdh bdebdfa
Fix static compilation issues when defining custom data fetchers
jamesdh d76c360
Tests for field-level arguments
jamesdh a1cd5f1
Build on Arguable
jamesdh 6e949fb
Arguments docs
jamesdh 466f9f3
Keep original method signature
jamesdh be610e5
Fix codenarc violations
jamesdh 7173fbf
Duplicate check
jamesdh 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
2 changes: 1 addition & 1 deletion
2
...erations/arguments/ComplexArgument.groovy → ...l/entity/arguments/ComplexArgument.groovy
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
2 changes: 1 addition & 1 deletion
2
...perations/arguments/CustomArgument.groovy → ...ql/entity/arguments/CustomArgument.groovy
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
2 changes: 1 addition & 1 deletion
2
...perations/arguments/SimpleArgument.groovy → ...ql/entity/arguments/SimpleArgument.groovy
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
77 changes: 77 additions & 0 deletions
77
core/src/main/groovy/org/grails/gorm/graphql/entity/dsl/helpers/Arguable.groovy
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,77 @@ | ||
| package org.grails.gorm.graphql.entity.dsl.helpers | ||
|
|
||
| import graphql.schema.GraphQLArgument | ||
| import groovy.transform.CompileStatic | ||
| import org.grails.datastore.mapping.model.MappingContext | ||
| import org.grails.gorm.graphql.entity.arguments.ComplexArgument | ||
| import org.grails.gorm.graphql.entity.arguments.CustomArgument | ||
| import org.grails.gorm.graphql.entity.arguments.SimpleArgument | ||
| import org.grails.gorm.graphql.types.GraphQLTypeManager | ||
|
|
||
| /** | ||
| * Decorates a class with a description property and builder method. | ||
| * | ||
| * @param <T> The implementing class | ||
| * @author James Kleeh | ||
| * @since 1.0.0 | ||
| */ | ||
| @CompileStatic | ||
| trait Arguable<T> extends ExecutesClosures { | ||
|
|
||
| List<CustomArgument> arguments = [] | ||
|
|
||
| private void handleArgumentClosure(CustomArgument argument, Closure closure) { | ||
| withDelegate(closure, (Object)argument) | ||
| argument.validate() | ||
| arguments.add(argument) | ||
| } | ||
|
|
||
| List<GraphQLArgument> getArguments(GraphQLTypeManager typeManager, MappingContext mappingContext) { | ||
| arguments.collect { | ||
| it.getArgument(typeManager, mappingContext).build() | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates an argument to the operation that is a list of a simple type. | ||
| * The list can not have more than 1 element and that element must be a class. | ||
| * | ||
| * @param name The name of the argument | ||
| * @param type The returnType of the argument | ||
| * @param closure To provide additional data about the argument | ||
| * @return The operation in order to chain method calls | ||
| */ | ||
| T argument(String name, List<Class<?>> type, @DelegatesTo(value = SimpleArgument, strategy = Closure.DELEGATE_ONLY) Closure closure = null) { | ||
| CustomArgument argument = new SimpleArgument().name(name).returns(type) | ||
| handleArgumentClosure(argument, closure) | ||
| (T)this | ||
| } | ||
|
|
||
| /** | ||
| * Creates an argument to the operation that is of the returnType provided. | ||
| * | ||
| * @param name The name of the argument | ||
| * @param type The returnType of the argument | ||
| * @param closure To provide additional data about the argument | ||
| * @return The operation in order to chain method calls | ||
| */ | ||
| T argument(String name, Class<?> type, @DelegatesTo(value = SimpleArgument, strategy = Closure.DELEGATE_ONLY) Closure closure = null) { | ||
| CustomArgument argument = new SimpleArgument().name(name).returns(type) | ||
| handleArgumentClosure(argument, closure) | ||
| (T)this | ||
| } | ||
|
|
||
| /** | ||
| * Creates an argument to the operation that is a custom type. | ||
| * | ||
| * @param name The name of the argument | ||
| * @param closure To provide additional data about the argument | ||
| * @return The operation in order to chain method calls | ||
| */ | ||
| T argument(String name, String typeName, @DelegatesTo(value = ComplexArgument, strategy = Closure.DELEGATE_ONLY) Closure closure) { | ||
| CustomArgument argument = new ComplexArgument().name(name).typeName(typeName) | ||
| handleArgumentClosure(argument, closure) | ||
| (T)this | ||
| } | ||
|
|
||
| } | ||
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
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.
Similar, in that when the implementing GORM entity used @GrailsCompileStatic, this would result in a static compilation error without the generic wildcard.