From a2921a187234041249db093327d713c82ce69336 Mon Sep 17 00:00:00 2001 From: Yarin Date: Tue, 10 Oct 2017 15:17:07 +0300 Subject: [PATCH 1/8] fixing bug- list of input types does not work in query --- .../annotations/GraphQLAnnotations.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/GraphQLAnnotations.java index 94be6b19..d0a203c2 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotations.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * 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 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -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; @@ -459,7 +443,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 +538,14 @@ 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 && !(((GraphQLList) graphQLType).getWrappedType() instanceof GraphQLScalarType)) { + GraphQLInputObjectType inputObject = getInputObject((GraphQLList) graphQLType, "input"); + inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); + graphQLType = new GraphQLList(inputObject); } + return getArgument(parameter, graphQLType); }).collect(Collectors.toList()); @@ -616,11 +606,25 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio return new GraphQLFieldDefinitionWrapper(builder.build()); } + 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); } + public GraphQLInputObjectType getInputObject(GraphQLList graphQLType, String newNamePrefix) { + GraphQLObjectType object = (GraphQLObjectType) graphQLType.getWrappedType(); + return getInputObject(object, newNamePrefix); + } + @Override public GraphQLInputObjectType getInputObject(GraphQLObjectType graphQLType, String newNamePrefix) { GraphQLObjectType object = graphQLType; @@ -631,7 +635,8 @@ public GraphQLInputObjectType getInputObject(GraphQLObjectType graphQLType, Stri GraphQLInputType inputType; if (type instanceof GraphQLObjectType) { inputType = getInputObject((GraphQLObjectType) type, newNamePrefix); - } else { + } + else { inputType = (GraphQLInputType) type; } From be3f769e0d85280f7320e5fe5ab12fc2e5e31b80 Mon Sep 17 00:00:00 2001 From: Yarin Date: Tue, 10 Oct 2017 15:34:34 +0300 Subject: [PATCH 2/8] tests fixes --- .../java/graphql/annotations/GraphQLObjectTest.java | 12 ++++++------ src/test/java/graphql/annotations/RelayTest.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index bc910b21..dd2473d3 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * 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 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -74,12 +74,12 @@ String field() { } @GraphQLField - public String fieldWithArgs(@NotNull String a, @GraphQLDefaultValue(DefaultAValue.class) @GraphQLDescription("b") String b) { + public String fieldWithArgs(@GraphQLName("a") @NotNull String a, @GraphQLName("b") @GraphQLDefaultValue(DefaultAValue.class) @GraphQLDescription("b") String b) { return b; } @GraphQLField - public String fieldWithArgsAndEnvironment(DataFetchingEnvironment env, String a, String b) { + public String fieldWithArgsAndEnvironment(DataFetchingEnvironment env,@GraphQLName("a") String a, @GraphQLName("b") String b) { return a; } @@ -551,7 +551,7 @@ public TestInputArgument(HashMap args) { private static class TestObjectInput { @GraphQLField - public String test(int other, TestInputArgument arg) { + public String test(@GraphQLName("other") int other, @GraphQLName("arg") TestInputArgument arg) { return arg.a; } } diff --git a/src/test/java/graphql/annotations/RelayTest.java b/src/test/java/graphql/annotations/RelayTest.java index ca8d13ad..09c71f19 100644 --- a/src/test/java/graphql/annotations/RelayTest.java +++ b/src/test/java/graphql/annotations/RelayTest.java @@ -69,7 +69,7 @@ public Result doSomething() { return new Result(0); } @GraphQLField @GraphQLRelayMutation - public Result doSomethingElse(@GraphQLDescription("A") int a, int b) { + public Result doSomethingElse(@GraphQLName("a") @GraphQLDescription("A") int a, @GraphQLName("b") int b) { return new Result(a - b); } @GraphQLField @GraphQLRelayMutation From 44ca1f91c60cbbe7090257d0a2deebb95d4cf93c Mon Sep 17 00:00:00 2001 From: Yarin Date: Tue, 10 Oct 2017 15:38:37 +0300 Subject: [PATCH 3/8] tests fixes --- .../java/graphql/annotations/RelayTest.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/test/java/graphql/annotations/RelayTest.java b/src/test/java/graphql/annotations/RelayTest.java index 09c71f19..3bc0d727 100644 --- a/src/test/java/graphql/annotations/RelayTest.java +++ b/src/test/java/graphql/annotations/RelayTest.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * 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, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -44,7 +44,7 @@ public interface IResult { int getI(); } - public static class Result implements IResult{ + public static class Result implements IResult { private final int i; public Result(int i) { @@ -57,22 +57,28 @@ public int getI() { } public static class WrongReturnType { - @GraphQLField @GraphQLRelayMutation + @GraphQLField + @GraphQLRelayMutation public int doSomething() { return 0; } } public static class TestObject { - @GraphQLField @GraphQLRelayMutation + @GraphQLField + @GraphQLRelayMutation public Result doSomething() { return new Result(0); } - @GraphQLField @GraphQLRelayMutation + + @GraphQLField + @GraphQLRelayMutation public Result doSomethingElse(@GraphQLName("a") @GraphQLDescription("A") int a, @GraphQLName("b") int b) { return new Result(a - b); } - @GraphQLField @GraphQLRelayMutation + + @GraphQLField + @GraphQLRelayMutation public IResult doSomethingI() { return new Result(0); } From ef508e1e6d0f760863a457c66e628ae9b1eb54c2 Mon Sep 17 00:00:00 2001 From: Yarin Date: Tue, 10 Oct 2017 15:43:31 +0300 Subject: [PATCH 4/8] fix build --- src/main/java/graphql/annotations/GraphQLAnnotations.java | 8 ++++---- src/test/java/graphql/annotations/GraphQLObjectTest.java | 8 ++++---- src/test/java/graphql/annotations/RelayTest.java | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/GraphQLAnnotations.java index d0a203c2..799ae467 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotations.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * 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, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index dd2473d3..f826367b 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * 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, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/graphql/annotations/RelayTest.java b/src/test/java/graphql/annotations/RelayTest.java index 3bc0d727..bb6e4523 100644 --- a/src/test/java/graphql/annotations/RelayTest.java +++ b/src/test/java/graphql/annotations/RelayTest.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * 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, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. From 8ce1b0978aa4e6a5a44ccdbd7443c8bc82e67a23 Mon Sep 17 00:00:00 2001 From: Yarin Date: Tue, 10 Oct 2017 15:56:30 +0300 Subject: [PATCH 5/8] more accurate condition --- src/main/java/graphql/annotations/GraphQLAnnotations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/GraphQLAnnotations.java index 799ae467..3692d726 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotations.java @@ -540,7 +540,7 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio GraphQLInputObjectType inputObject = getInputObject((GraphQLObjectType) graphQLType, "input"); inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); graphQLType = inputObject; - } else if (graphQLType instanceof GraphQLList && !(((GraphQLList) graphQLType).getWrappedType() instanceof GraphQLScalarType)) { + } else if (graphQLType instanceof GraphQLList && (((GraphQLList) graphQLType).getWrappedType() instanceof GraphQLObjectType)) { GraphQLInputObjectType inputObject = getInputObject((GraphQLList) graphQLType, "input"); inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); graphQLType = new GraphQLList(inputObject); From 272b7ed91008b1417b20a6ca2c1996d6faa11090 Mon Sep 17 00:00:00 2001 From: Yarin Date: Tue, 10 Oct 2017 20:46:39 +0300 Subject: [PATCH 6/8] support recursive lists --- .../annotations/GraphQLAnnotations.java | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/GraphQLAnnotations.java index 3692d726..b3bd9c35 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotations.java @@ -540,10 +540,20 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio GraphQLInputObjectType inputObject = getInputObject((GraphQLObjectType) graphQLType, "input"); inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); graphQLType = inputObject; - } else if (graphQLType instanceof GraphQLList && (((GraphQLList) graphQLType).getWrappedType() instanceof GraphQLObjectType)) { - GraphQLInputObjectType inputObject = getInputObject((GraphQLList) graphQLType, "input"); - inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); - graphQLType = new GraphQLList(inputObject); + } else if (graphQLType instanceof GraphQLList) { + Stack typesStack= new Stack<>(); + typesStack = getWrappedTypesStack(graphQLType, typesStack); + graphql.schema.GraphQLType wrappedType = typesStack.pop(); + if (wrappedType instanceof GraphQLObjectType){ + GraphQLInputObjectType inputObject = getInputObject((GraphQLObjectType)wrappedType, "input"); + inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); + graphQLType = inputObject; + while (!typesStack.isEmpty()){ + graphQLType = new GraphQLList(graphQLType); + typesStack.pop(); + } + + } } return getArgument(parameter, graphQLType); @@ -606,6 +616,17 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio return new GraphQLFieldDefinitionWrapper(builder.build()); } + private Stack getWrappedTypesStack(graphql.schema.GraphQLType graphQLType, Stack 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) @@ -620,11 +641,6 @@ protected static GraphQLFieldDefinition field(Method method) throws Instantiatio } - public GraphQLInputObjectType getInputObject(GraphQLList graphQLType, String newNamePrefix) { - GraphQLObjectType object = (GraphQLObjectType) graphQLType.getWrappedType(); - return getInputObject(object, newNamePrefix); - } - @Override public GraphQLInputObjectType getInputObject(GraphQLObjectType graphQLType, String newNamePrefix) { GraphQLObjectType object = graphQLType; From 3d50501e3878a54ae249153bfef339ffbd5b7515 Mon Sep 17 00:00:00 2001 From: Yarin Date: Wed, 11 Oct 2017 00:46:11 +0300 Subject: [PATCH 7/8] put braces in if --- .../annotations/GraphQLAnnotations.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/GraphQLAnnotations.java index b3bd9c35..446d1c7d 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotations.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * 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, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -541,14 +541,14 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); graphQLType = inputObject; } else if (graphQLType instanceof GraphQLList) { - Stack typesStack= new Stack<>(); + Stack typesStack = new Stack<>(); typesStack = getWrappedTypesStack(graphQLType, typesStack); graphql.schema.GraphQLType wrappedType = typesStack.pop(); - if (wrappedType instanceof GraphQLObjectType){ - GraphQLInputObjectType inputObject = getInputObject((GraphQLObjectType)wrappedType, "input"); + if (wrappedType instanceof GraphQLObjectType) { + GraphQLInputObjectType inputObject = getInputObject((GraphQLObjectType) wrappedType, "input"); inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); graphQLType = inputObject; - while (!typesStack.isEmpty()){ + while (!typesStack.isEmpty()) { graphQLType = new GraphQLList(graphQLType); typesStack.pop(); } @@ -616,23 +616,22 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio return new GraphQLFieldDefinitionWrapper(builder.build()); } - private Stack getWrappedTypesStack(graphql.schema.GraphQLType graphQLType, Stack stack){ + private Stack getWrappedTypesStack(graphql.schema.GraphQLType graphQLType, Stack stack) { stack.push(graphQLType); - if (graphQLType instanceof GraphQLList) - { + if (graphQLType instanceof GraphQLList) { return getWrappedTypesStack(((GraphQLList) graphQLType).getWrappedType(), stack); - } - else{ + } else { return stack; } } private graphql.schema.GraphQLType getOrPutInRegistry(graphql.schema.GraphQLType graphQLType) { graphql.schema.GraphQLType typeFromRegistry = typeRegistry.get(graphQLType.getName()); - if (typeFromRegistry!=null) + if (typeFromRegistry != null) { return typeFromRegistry; - else + } else { typeRegistry.put(graphQLType.getName(), graphQLType); + } return graphQLType; } @@ -651,8 +650,7 @@ public GraphQLInputObjectType getInputObject(GraphQLObjectType graphQLType, Stri GraphQLInputType inputType; if (type instanceof GraphQLObjectType) { inputType = getInputObject((GraphQLObjectType) type, newNamePrefix); - } - else { + } else { inputType = (GraphQLInputType) type; } From d901525d0d4b735c058b6d10f6f6ecc24e4cf82b Mon Sep 17 00:00:00 2001 From: Yarin Date: Wed, 11 Oct 2017 01:49:11 +0300 Subject: [PATCH 8/8] handle list of input object types as a field of an input type object --- .../annotations/GraphQLAnnotations.java | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/GraphQLAnnotations.java index 446d1c7d..395fc285 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotations.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * 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, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -193,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) { @@ -235,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) { @@ -541,19 +539,7 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); graphQLType = inputObject; } else if (graphQLType instanceof GraphQLList) { - Stack typesStack = new Stack<>(); - typesStack = getWrappedTypesStack(graphQLType, typesStack); - graphql.schema.GraphQLType wrappedType = typesStack.pop(); - if (wrappedType instanceof GraphQLObjectType) { - GraphQLInputObjectType inputObject = getInputObject((GraphQLObjectType) wrappedType, "input"); - inputObject = (GraphQLInputObjectType) getOrPutInRegistry(inputObject); - graphQLType = inputObject; - while (!typesStack.isEmpty()) { - graphQLType = new GraphQLList(graphQLType); - typesStack.pop(); - } - - } + graphQLType = handleGraphQLList(graphQLType); } return getArgument(parameter, graphQLType); @@ -616,6 +602,7 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio return new GraphQLFieldDefinitionWrapper(builder.build()); } + private Stack getWrappedTypesStack(graphql.schema.GraphQLType graphQLType, Stack stack) { stack.push(graphQLType); if (graphQLType instanceof GraphQLList) { @@ -650,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; } @@ -659,6 +648,26 @@ public GraphQLInputObjectType getInputObject(GraphQLObjectType graphQLType, Stri collect(Collectors.toList())); } + private GraphQLInputType handleGraphQLList(graphql.schema.GraphQLType type) { + GraphQLInputType inputType; + Stack 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()) { + 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); }