-
Notifications
You must be signed in to change notification settings - Fork 96
Bug Fix- list of input types #107
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a2921a1
fixing bug- list of input types does not work in query
yarinvak be3f769
tests fixes
yarinvak 44ca1f9
tests fixes
yarinvak ef508e1
fix build
yarinvak 8ce1b09
more accurate condition
yarinvak 272b7ed
support recursive lists
yarinvak 3d50501
put braces in if
yarinvak d901525
handle list of input object types as a field of an input type object
yarinvak 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
|
@@ -16,24 +16,8 @@ | |
|
||
import graphql.TypeResolutionEnvironment; | ||
import graphql.relay.Relay; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import graphql.schema.DataFetchingEnvironmentImpl; | ||
import graphql.schema.FieldDataFetcher; | ||
import graphql.schema.GraphQLArgument; | ||
import graphql.schema.GraphQLFieldDefinition; | ||
import graphql.schema.GraphQLInputObjectField; | ||
import graphql.schema.GraphQLInputObjectType; | ||
import graphql.schema.GraphQLInputType; | ||
import graphql.schema.GraphQLInterfaceType; | ||
import graphql.schema.GraphQLList; | ||
import graphql.schema.*; | ||
import graphql.schema.GraphQLNonNull; | ||
import graphql.schema.GraphQLObjectType; | ||
import graphql.schema.GraphQLOutputType; | ||
import graphql.schema.GraphQLTypeReference; | ||
import graphql.schema.GraphQLUnionType; | ||
import graphql.schema.PropertyDataFetcher; | ||
import graphql.schema.TypeResolver; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
|
@@ -209,7 +193,6 @@ private static Boolean isGraphQLField(AnnotatedElement element) { | |
* breadthFirst parental ascent looking for closest method declaration with explicit annotation | ||
* | ||
* @param method The method to match | ||
* | ||
* @return The closest GraphQLField annotation | ||
*/ | ||
private boolean breadthFirstSearch(Method method) { | ||
|
@@ -251,7 +234,6 @@ private boolean breadthFirstSearch(Method method) { | |
* direct parental ascent looking for closest declaration with explicit annotation | ||
* | ||
* @param field The field to find | ||
* | ||
* @return The closest GraphQLField annotation | ||
*/ | ||
private boolean parentalSearch(Field field) { | ||
|
@@ -459,7 +441,7 @@ protected GraphQLFieldDefinition getField(Field field) throws GraphQLAnnotations | |
|
||
private DataFetcher constructDataFetcher(String fieldName, GraphQLDataFetcher annotatedDataFetcher) { | ||
final String[] args; | ||
if ( annotatedDataFetcher.firstArgIsTargetName() ) { | ||
if (annotatedDataFetcher.firstArgIsTargetName()) { | ||
args = Stream.concat(Stream.of(fieldName), stream(annotatedDataFetcher.args())).toArray(String[]::new); | ||
} else { | ||
args = annotatedDataFetcher.args(); | ||
|
@@ -554,8 +536,12 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio | |
graphql.schema.GraphQLType graphQLType = finalTypeFunction.buildType(t, parameter.getAnnotatedType()); | ||
if (graphQLType instanceof GraphQLObjectType) { | ||
GraphQLInputObjectType inputObject = getInputObject((GraphQLObjectType) graphQLType, "input"); | ||
inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); | ||
graphQLType = inputObject; | ||
} else if (graphQLType instanceof GraphQLList) { | ||
graphQLType = handleGraphQLList(graphQLType); | ||
} | ||
|
||
return getArgument(parameter, graphQLType); | ||
}).collect(Collectors.toList()); | ||
|
||
|
@@ -616,6 +602,26 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio | |
return new GraphQLFieldDefinitionWrapper(builder.build()); | ||
} | ||
|
||
|
||
private Stack<graphql.schema.GraphQLType> getWrappedTypesStack(graphql.schema.GraphQLType graphQLType, Stack<graphql.schema.GraphQLType> stack) { | ||
stack.push(graphQLType); | ||
if (graphQLType instanceof GraphQLList) { | ||
return getWrappedTypesStack(((GraphQLList) graphQLType).getWrappedType(), stack); | ||
} else { | ||
return stack; | ||
} | ||
} | ||
|
||
private graphql.schema.GraphQLType getOrPutInRegistry(graphql.schema.GraphQLType graphQLType) { | ||
graphql.schema.GraphQLType typeFromRegistry = typeRegistry.get(graphQLType.getName()); | ||
if (typeFromRegistry != null) { | ||
return typeFromRegistry; | ||
} else { | ||
typeRegistry.put(graphQLType.getName(), graphQLType); | ||
} | ||
return graphQLType; | ||
} | ||
|
||
protected static GraphQLFieldDefinition field(Method method) throws InstantiationException, IllegalAccessException { | ||
return getInstance().getField(method); | ||
|
||
|
@@ -631,6 +637,8 @@ public GraphQLInputObjectType getInputObject(GraphQLObjectType graphQLType, Stri | |
GraphQLInputType inputType; | ||
if (type instanceof GraphQLObjectType) { | ||
inputType = getInputObject((GraphQLObjectType) type, newNamePrefix); | ||
} else if (type instanceof GraphQLList) { | ||
inputType = handleGraphQLList(type); | ||
} else { | ||
inputType = (GraphQLInputType) type; | ||
} | ||
|
@@ -640,6 +648,26 @@ public GraphQLInputObjectType getInputObject(GraphQLObjectType graphQLType, Stri | |
collect(Collectors.toList())); | ||
} | ||
|
||
private GraphQLInputType handleGraphQLList(graphql.schema.GraphQLType type) { | ||
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. I think it is better that the function get a GraphQLList as an input |
||
GraphQLInputType inputType; | ||
Stack<graphql.schema.GraphQLType> typesStack = new Stack<>(); | ||
typesStack = getWrappedTypesStack(type, typesStack); | ||
graphql.schema.GraphQLType wrappedType = typesStack.pop(); | ||
if (wrappedType instanceof GraphQLObjectType) { | ||
GraphQLInputObjectType inputObject = getInputObject((GraphQLObjectType) wrappedType, "input"); | ||
inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); | ||
inputType = inputObject; | ||
while (!typesStack.isEmpty()) { | ||
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. extract to different method |
||
inputType = new GraphQLList(inputType); | ||
typesStack.pop(); | ||
} | ||
|
||
} else { | ||
inputType = (GraphQLInputType) type; | ||
} | ||
return inputType; | ||
} | ||
|
||
public static GraphQLInputObjectType inputObject(GraphQLObjectType graphQLType, String newNamePrefix) { | ||
return getInstance().getInputObject(graphQLType, newNamePrefix); | ||
} | ||
|
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
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.
rename method