Skip to content

Commit 396a5a1

Browse files
committed
Problem: invariant if mutation providers don't provide any mutations
"mutation fields must be an object with field names as keys or a function which returns such an object." Solution: if no mutations provided, no mutation object shall be created
1 parent 2455981 commit 396a5a1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/graphql/servlet/GraphQLServlet.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
*/
1515
package graphql.servlet;
1616

17-
import com.fasterxml.jackson.annotation.JsonGetter;
1817
import com.fasterxml.jackson.core.JsonParser;
19-
import com.fasterxml.jackson.core.JsonProcessingException;
2018
import com.fasterxml.jackson.core.type.TypeReference;
2119
import com.fasterxml.jackson.databind.DeserializationContext;
2220
import com.fasterxml.jackson.databind.JsonDeserializer;
@@ -37,7 +35,10 @@
3735
import org.apache.commons.fileupload.FileItemStream;
3836
import org.apache.commons.fileupload.FileUploadException;
3937
import org.apache.commons.fileupload.servlet.ServletFileUpload;
40-
import org.osgi.service.component.annotations.*;
38+
import org.osgi.service.component.annotations.Component;
39+
import org.osgi.service.component.annotations.Reference;
40+
import org.osgi.service.component.annotations.ReferenceCardinality;
41+
import org.osgi.service.component.annotations.ReferencePolicyOption;
4142

4243
import javax.security.auth.Subject;
4344
import javax.servlet.Servlet;
@@ -93,7 +94,12 @@ protected void updateSchema() {
9394
provider.getMutations().forEach(mutationObject::field);
9495
}
9596

96-
schema = newSchema().query(object.build()).mutation(mutationObject.build()).build();
97+
GraphQLObjectType mutationType = mutationObject.build();
98+
if (mutationType.getFieldDefinitions().size() == 0) {
99+
schema = readOnlySchema;
100+
} else {
101+
schema = newSchema().query(object.build()).mutation(mutationType).build();
102+
}
97103
}
98104
}
99105

0 commit comments

Comments
 (0)