private static Value handleNonNull(Object _value, GraphQLNonNull type) { GraphQLType wrappedType = type.getWrappedType(); return astFromValue(_value, wrappedType); }
private GraphQLType unwrapNonNull(GraphQLNonNull type) { if (isList(type.getWrappedType())) { //we only care about [type!]! i.e. non-null lists of non-nulls GraphQLList listType = (GraphQLList) type.getWrappedType(); if (isNonNull(listType.getWrappedType())) { return unwrapAll(listType.getWrappedType()); } else { return type.getWrappedType(); } } else { return unwrapAll(type.getWrappedType()); } }
/** * Unwraps one layer of the type or just returns the type again if its not a wrapped type * * @param type the type to unwrapOne * * @return the unwrapped type or the same type again if its not wrapped */ public static GraphQLType unwrapOne(GraphQLType type) { if (isNonNull(type)) { return ((GraphQLNonNull) type).getWrappedType(); } else if (isList(type)) { return ((GraphQLList) type).getWrappedType(); } return type; }
public static GraphQLType unwrapNonNull(GraphQLType type) { while (type instanceof GraphQLNonNull) { type = ((GraphQLNonNull) type).getWrappedType(); } return type; }
private boolean isBooleanMethod(GraphQLOutputType outputType) { if (outputType == GraphQLBoolean) return true; if (outputType instanceof GraphQLNonNull) { return ((GraphQLNonNull) outputType).getWrappedType() == GraphQLBoolean; } return false; }
private boolean isBooleanMethod(GraphQLOutputType outputType) { if (outputType == GraphQLBoolean) return true; if (outputType instanceof GraphQLNonNull) { return ((GraphQLNonNull) outputType).getWrappedType() == GraphQLBoolean; } return false; }
private boolean isaBoolean() { return outputType == GraphQLBoolean || (outputType instanceof GraphQLNonNull && ((GraphQLNonNull) outputType).getWrappedType() == GraphQLBoolean); }
private static boolean isListable(final graphql.schema.GraphQLType type){ if(type instanceof GraphQLNonNull){ graphql.schema.GraphQLType wrappedType = ((GraphQLNonNull) type).getWrappedType(); return isListable(wrappedType); } return (type instanceof GraphQLList); }
private static Value handleNonNull(Object _value, GraphQLNonNull type) { GraphQLType wrappedType = type.getWrappedType(); return astFromValue(_value, wrappedType); }
private GraphQLType unwrapNonNull(GraphQLNonNull type) { if (isList(type.getWrappedType())) { //we only care about [type!]! i.e. non-null lists of non-nulls GraphQLList listType = (GraphQLList) type.getWrappedType(); if (isNonNull(listType.getWrappedType())) { return unwrapAll(listType.getWrappedType()); } else { return type.getWrappedType(); } } else { return unwrapAll(type.getWrappedType()); } }
private GraphQLOutputType getGraphQLConnection(AccessibleObject field, graphql.schema.GraphQLType type, Relay relay, Map<String, graphql.schema.GraphQLType> typeRegistry) { if (type instanceof GraphQLNonNull) { GraphQLList listType = (GraphQLList) ((GraphQLNonNull) type).getWrappedType(); return new GraphQLNonNull(internalGetGraphQLConnection(field, listType, relay, typeRegistry)); } else { return internalGetGraphQLConnection(field, (GraphQLList) type, relay, typeRegistry); } }
private static graphql.schema.GraphQLType getType(final graphql.schema.GraphQLType type){ if(type instanceof GraphQLNonNull){ graphql.schema.GraphQLType wrappedType = ((GraphQLNonNull) type).getWrappedType(); return getType(wrappedType); } if(type instanceof GraphQLList){ graphql.schema.GraphQLType wrappedType = ((GraphQLList) type).getWrappedType(); return getType(wrappedType); } return type; }
/** * Unwraps one layer of the type or just returns the type again if its not a wrapped type * * @param type the type to unwrapOne * * @return the unwrapped type or the same type again if its not wrapped */ public static GraphQLType unwrapOne(GraphQLType type) { if (isNonNull(type)) { return ((GraphQLNonNull) type).getWrappedType(); } else if (isList(type)) { return ((GraphQLList) type).getWrappedType(); } return type; }
public static boolean isConnection(AccessibleObject obj, GraphQLType type) { if (type instanceof graphql.schema.GraphQLNonNull) { type = ((GraphQLNonNull) type).getWrappedType(); } final GraphQLType actualType = type; boolean isValidGraphQLTypeForConnection = obj.isAnnotationPresent(GraphQLConnection.class) && actualType instanceof GraphQLList && TYPES_FOR_CONNECTION.stream().anyMatch(aClass -> aClass.isInstance(((GraphQLList) actualType).getWrappedType())); if (isValidGraphQLTypeForConnection) { ConnectionValidator validator = newInstance(obj.getAnnotation(GraphQLConnection.class).validator()); validator.validate(obj); return true; } else { return false; } }
@Test public void optional() throws NoSuchMethodException { ProcessingElementsContainer container = testedProcessingElementsContainer(); graphql.schema.GraphQLType type = container.getDefaultTypeFunction().buildType(getClass().getMethod("optionalMethod").getReturnType(), getClass().getMethod("listMethod").getAnnotatedReturnType(),null); assertTrue(type instanceof GraphQLList); GraphQLType subtype = ((GraphQLList) type).getWrappedType(); assertTrue(subtype instanceof graphql.schema.GraphQLNonNull); GraphQLType wrappedType = (((graphql.schema.GraphQLNonNull) subtype).getWrappedType()); assertEquals(wrappedType, GraphQLString); }
private void assertIsGraphListOfListOfString(GraphQLType type) { assertTrue(type instanceof GraphQLList); GraphQLList subtype = (GraphQLList) ((GraphQLList) type).getWrappedType(); assertTrue(subtype.getWrappedType() instanceof graphql.schema.GraphQLNonNull); graphql.schema.GraphQLNonNull wrappedType = (graphql.schema.GraphQLNonNull) subtype.getWrappedType(); assertEquals(wrappedType.getWrappedType(), GraphQLString); }
assertEquals(fields.get(2).getDescription(), "field"); assertTrue(fields.get(2).getType() instanceof graphql.schema.GraphQLNonNull); assertEquals(((graphql.schema.GraphQLNonNull) fields.get(2).getType()).getWrappedType(), GraphQLString); assertEquals(args.get(0).getName(), "a"); assertTrue(args.get(0).getType() instanceof graphql.schema.GraphQLNonNull); assertEquals(((graphql.schema.GraphQLNonNull) args.get(0).getType()).getWrappedType(), GraphQLString); assertEquals(args.get(1).getName(), "b"); assertEquals(args.get(1).getType(), GraphQLString);
GraphQLInputType input = doSomethingElse.getArgument("input").getType(); assertTrue(input instanceof GraphQLNonNull); GraphQLType inputType = ((graphql.schema.GraphQLNonNull) input).getWrappedType(); assertTrue(inputType instanceof GraphQLInputObjectType); GraphQLInputObjectType inputType_ = (GraphQLInputObjectType) inputType;
@Test public void noArgMutation() { GraphQLObjectType object = GraphQLAnnotations.object(TestObject.class); GraphQLFieldDefinition doSomething = object.getFieldDefinition("doSomething"); assertNotNull(doSomething); assertEquals(doSomething.getArguments().size(), 1); GraphQLInputType input = doSomething.getArgument("input").getType(); assertTrue(input instanceof GraphQLNonNull); GraphQLType inputType = ((graphql.schema.GraphQLNonNull) input).getWrappedType(); assertTrue(inputType instanceof GraphQLInputObjectType); assertTrue(doSomething.getType() instanceof GraphQLObjectType); GraphQLObjectType returnType = (GraphQLObjectType) doSomething.getType(); assertNotNull(returnType.getFieldDefinition("getI")); assertNotNull(returnType.getFieldDefinition("clientMutationId")); GraphQLSchema schema = GraphQLSchema.newSchema().query(object).mutation(object).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build(); ExecutionResult result = graphQL.execute("mutation { doSomething(input: {clientMutationId: \"1\"}) { getI clientMutationId } }", new TestObject()); assertEquals(result.getErrors().size(), 0); Map<String, Object> returns = (Map<String, Object>) ((Map<String, Object>) result.getData()).get("doSomething"); assertEquals(returns.get("getI"), 0); assertEquals(returns.get("clientMutationId"), "1"); }
@Test public void argMutation() { GraphQLObjectType object = GraphQLAnnotations.object(TestObject.class); GraphQLFieldDefinition doSomethingElse = object.getFieldDefinition("doSomethingElse"); assertNotNull(doSomethingElse); assertEquals(doSomethingElse.getArguments().size(), 1); GraphQLInputType input = doSomethingElse.getArgument("input").getType(); assertTrue(input instanceof GraphQLNonNull); GraphQLType inputType = ((graphql.schema.GraphQLNonNull) input).getWrappedType(); assertTrue(inputType instanceof GraphQLInputObjectType); GraphQLInputObjectType inputType_ = (GraphQLInputObjectType) inputType; assertNotNull(inputType_.getField("a")); assertNotNull(inputType_.getField("b")); assertEquals(inputType_.getField("a").getDescription(), "A"); assertTrue(doSomethingElse.getType() instanceof GraphQLObjectType); GraphQLObjectType returnType = (GraphQLObjectType) doSomethingElse.getType(); assertNotNull(returnType.getFieldDefinition("getI")); assertNotNull(returnType.getFieldDefinition("clientMutationId")); GraphQLSchema schema = GraphQLSchema.newSchema().query(object).mutation(object).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build(); ExecutionResult result = graphQL.execute("mutation { doSomethingElse(input: {a: 0, b: 1, clientMutationId: \"1\"}) { getI clientMutationId } }", new TestObject()); assertEquals(result.getErrors().size(), 0); Map<String, Object> returns = (Map<String, Object>) ((Map<String, Object>) result.getData()).get("doSomethingElse"); assertEquals(returns.get("getI"), -1); assertEquals(returns.get("clientMutationId"), "1"); }