private TypeInfo(Type type) { this.rawType = assertNotNull(type, "type must not be null"); while (!(type instanceof TypeName)) { if (type instanceof NonNullType) { decoration.push(NonNullType.class); type = ((NonNullType) type).getType(); } if (type instanceof ListType) { decoration.push(ListType.class); type = ((ListType) type).getType(); } } this.typeName = (TypeName) type; }
private void checkArgValueMatchesAllowedListType(List<GraphQLError> errors, Value instanceValue, ListType allowedArgType) { if (instanceValue instanceof NullValue) { return; } if (!(instanceValue instanceof ArrayValue)) { addValidationError(errors, EXPECTED_LIST_MESSAGE, instanceValue.getClass().getSimpleName()); return; } ArrayValue arrayValue = ((ArrayValue) instanceValue); Type unwrappedAllowedType = allowedArgType.getType(); // validate each instance value in the list, all instances must match for the list to match arrayValue.getValues().forEach(value -> checkArgValueMatchesAllowedType(errors, value, unwrappedAllowedType)); }
public TypeInfo unwrapOne() { if (rawType instanceof NonNullType) { return typeInfo(((NonNullType) rawType).getType()); } if (rawType instanceof ListType) { return typeInfo(((ListType) rawType).getType()); } return this; }
private Builder(ListType existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.type = existing.getType(); this.ignoredChars = existing.getIgnoredChars(); }
public TypeName getUnmodifiedType(Type type) { if (type instanceof ListType) { return getUnmodifiedType(((ListType) type).getType()); } else if (type instanceof NonNullType) { return getUnmodifiedType(((NonNullType) type).getType()); } else if (type instanceof TypeName) { return (TypeName) type; } return Assert.assertShouldNeverHappen(); }
private String type(Type type) { if (type instanceof NonNullType) { NonNullType inner = (NonNullType) type; return wrap("", type(inner.getType()), "!"); } else if (type instanceof ListType) { ListType inner = (ListType) type; return wrap("[", type(inner.getType()), "]"); } else { TypeName inner = (TypeName) type; return inner.getName(); } }
public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) { GraphQLType innerType; if (type instanceof ListType) { innerType = getTypeFromAST(schema, ((ListType) type).getType()); return innerType != null ? list(innerType) : null; } else if (type instanceof NonNullType) { innerType = getTypeFromAST(schema, ((NonNullType) type).getType()); return innerType != null ? nonNull(innerType) : null; } return schema.getType(((TypeName) type).getName()); } }
private TypeInfo(Type type) { this.rawType = assertNotNull(type, "type must not be null"); while (!(type instanceof TypeName)) { if (type instanceof NonNullType) { decoration.push(NonNullType.class); type = ((NonNullType) type).getType(); } if (type instanceof ListType) { decoration.push(ListType.class); type = ((ListType) type).getType(); } } this.typeName = (TypeName) type; }
private void checkArgValueMatchesAllowedListType(List<GraphQLError> errors, Value instanceValue, ListType allowedArgType) { if (instanceValue instanceof NullValue) { return; } if (!(instanceValue instanceof ArrayValue)) { addValidationError(errors, EXPECTED_LIST_MESSAGE, instanceValue.getClass().getSimpleName()); return; } ArrayValue arrayValue = ((ArrayValue) instanceValue); Type unwrappedAllowedType = allowedArgType.getType(); // validate each instance value in the list, all instances must match for the list to match arrayValue.getValues().forEach(value -> checkArgValueMatchesAllowedType(errors, value, unwrappedAllowedType)); }
private String toGraphQLType(Type type) { if ( type instanceof ListType ) { return "new GraphQLList(" + toGraphQLType(((ListType)type).getType()) + ")"; } else if ( type instanceof NonNullType ) { return toGraphQLType(((NonNullType)type).getType()); } else if ( type instanceof TypeName ) { String name = ((TypeName)type).getName(); if ( BUILTINS.containsKey(name) ) { return "Scalars.GraphQL" + name; } return "new GraphQLTypeReference(\""+name+"\")"; } else { throw new UnsupportedOperationException("Unknown Type="+type.getClass().getName()); } }
private String toJavaTypeName(Type type) { if ( type instanceof ListType ) { return "List<" + toJavaTypeName(((ListType)type).getType()) + ">"; } else if ( type instanceof NonNullType ) { return toJavaTypeName(((NonNullType)type).getType()); } else if ( type instanceof TypeName ) { String name = ((TypeName)type).getName(); String rename = RENAME.get(name); // TODO: scalar type directive to get implementation class... if ( null != rename ) return rename; return name; } else { throw new UnsupportedOperationException("Unknown Type="+type.getClass().getName()); } }
private void addImports(Collection<String> imports, Type type) { if ( type instanceof ListType ) { imports.add("java.util.List"); addImports(imports, ((ListType)type).getType()); } else if ( type instanceof NonNullType ) { addImports(imports, ((NonNullType)type).getType()); } else if ( type instanceof TypeName ) { String name = ((TypeName)type).getName(); if ( BUILTINS.containsKey(name) ) { String importName = BUILTINS.get(name); if ( null == importName ) return; imports.add(importName); } else { TypeEntry refEntry = referenceTypes.get(name); // TODO: scalar name may be different... should read annotations for scalars. if ( null == refEntry ) { throw new RuntimeException("Unknown type '"+name+"' was not defined in the schema"); } else { imports.add(refEntry.getPackageName() + "." + name); } } } else { throw new RuntimeException("Unknown Type="+type.getClass().getName()); } } }
public TypeInfo unwrapOne() { if (rawType instanceof NonNullType) { return typeInfo(((NonNullType) rawType).getType()); } if (rawType instanceof ListType) { return typeInfo(((ListType) rawType).getType()); } return this; }
private Builder(ListType existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.type = existing.getType(); this.ignoredChars = existing.getIgnoredChars(); }
private String getOutputType(Type type) { if (type.getClass() == TypeName.class) { TypeName castType = (TypeName) type; String name = castType.getName(); if (SCALAR_TYPES.containsKey(name)) { return SCALAR_TYPES.get(name); } else return schemaNamespace + name; } String dummyNode = schemaNamespace + UUID.randomUUID(); if (type.getClass() == ListType.class) { ListType castType = (ListType) type; String subTypeUri = getOutputType(castType.getType()); rdfSchema.insertObjectTriple(dummyNode, RDF_TYPE, HGQL_LIST_TYPE); rdfSchema.insertObjectTriple(dummyNode, HGQL_OF_TYPE, subTypeUri); } if (type.getClass() == NonNullType.class) { NonNullType castType = (NonNullType) type; String subTypeUri = getOutputType(castType.getType()); rdfSchema.insertObjectTriple(dummyNode, RDF_TYPE, HGQL_NON_NULL_TYPE); rdfSchema.insertObjectTriple(dummyNode, HGQL_OF_TYPE, subTypeUri); } return dummyNode; }
private DataResolver toDataResolver(Type type) { if ( type instanceof ListType ) { DataResolver resolver = toDataResolver(((ListType)type).getType()); if ( null == resolver ) return null; resolver.listDepth++; return resolver; } else if ( type instanceof NonNullType ) { return toDataResolver(((NonNullType)type).getType()); } else if ( type instanceof TypeName ) { String typeName = ((TypeName)type).getName(); if ( BUILTINS.containsKey(typeName) ) return null; TypeEntry typeEntry = referenceTypes.get(typeName); if ( !typeEntry.hasIdField() ) return null; DataResolver resolver = new DataResolver(); resolver.fieldType = typeName + ".Resolver"; resolver.fieldName = "_" + lcFirst(typeName) + "Resolver"; return resolver; } else { throw new UnsupportedOperationException("Unknown Type="+type.getClass().getName()); } }
public TypeName getUnmodifiedType(Type type) { if (type instanceof ListType) { return getUnmodifiedType(((ListType) type).getType()); } else if (type instanceof NonNullType) { return getUnmodifiedType(((NonNullType) type).getType()); } else if (type instanceof TypeName) { return (TypeName) type; } return Assert.assertShouldNeverHappen(); }
private String getOutputType(Type type) { if (type.getClass() == TypeName.class) { TypeName castType = (TypeName) type; String name = castType.getName(); if (SCALAR_TYPES.containsKey(name)) { return SCALAR_TYPES.get(name); } else return schemaNamespace + name; } String dummyNode = schemaNamespace + UUID.randomUUID(); if (type.getClass() == ListType.class) { ListType castType = (ListType) type; String subTypeUri = getOutputType(castType.getType()); rdfSchema.insertObjectTriple(dummyNode, RDF_TYPE, HGQL_LIST_TYPE); rdfSchema.insertObjectTriple(dummyNode, HGQL_OF_TYPE, subTypeUri); } if (type.getClass() == NonNullType.class) { NonNullType castType = (NonNullType) type; String subTypeUri = getOutputType(castType.getType()); rdfSchema.insertObjectTriple(dummyNode, RDF_TYPE, HGQL_NON_NULL_TYPE); rdfSchema.insertObjectTriple(dummyNode, HGQL_OF_TYPE, subTypeUri); } return dummyNode; }
private String type(Type type) { if (type instanceof NonNullType) { NonNullType inner = (NonNullType) type; return wrap("", type(inner.getType()), "!"); } else if (type instanceof ListType) { ListType inner = (ListType) type; return wrap("[", type(inner.getType()), "]"); } else { TypeName inner = (TypeName) type; return inner.getName(); } }
public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) { GraphQLType innerType; if (type instanceof ListType) { innerType = getTypeFromAST(schema, ((ListType) type).getType()); return innerType != null ? list(innerType) : null; } else if (type instanceof NonNullType) { innerType = getTypeFromAST(schema, ((NonNullType) type).getType()); return innerType != null ? nonNull(innerType) : null; } return schema.getType(((TypeName) type).getName()); } }