本文整理汇总了Java中graphql.schema.GraphQLOutputType类的典型用法代码示例。如果您正苦于以下问题:Java GraphQLOutputType类的具体用法?Java GraphQLOutputType怎么用?Java GraphQLOutputType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GraphQLOutputType类属于graphql.schema包,在下文中一共展示了GraphQLOutputType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertType
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
/** Returns a GraphQLOutputType generated from a FieldDescriptor. */
static GraphQLOutputType convertType(FieldDescriptor fieldDescriptor) {
final GraphQLOutputType type;
if (fieldDescriptor.getType() == Type.MESSAGE) {
type = getReference(fieldDescriptor.getMessageType());
} else if (fieldDescriptor.getType() == Type.GROUP) {
type = getReference(fieldDescriptor.getMessageType());
} else if (fieldDescriptor.getType() == Type.ENUM) {
type = getReference(fieldDescriptor.getEnumType());
} else {
type = TYPE_MAP.get(fieldDescriptor.getType());
}
if (type == null) {
throw new RuntimeException("Unknown type: " + fieldDescriptor.getType());
}
if (fieldDescriptor.isRepeated()) {
return new GraphQLList(type);
} else {
return type;
}
}
示例2: getInputType
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
@Override
public GraphQLInputType getInputType(Type type) {
GraphQLInputType rv;
String typeName = this.getTypeNamingStrategy().getTypeName(this, type);
if (getInputTypeCache().containsKey(typeName)) {
return getInputTypeCache().get(typeName);
}
// check typemapper
Optional<IGraphQLTypeMapper> typeMapper = getCustomTypeMapper(type);
if (typeMapper.isPresent()) {
rv = getInputTypeCache().put(typeName, typeMapper.get().getInputType(this, type));
} else {
GraphQLOutputType outputType = getOutputType(type);
rv = getInputTypeCache().put(typeName, getInputType(outputType));
}
return rv;
}
示例3: getListOutputMapping
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
private GraphQLOutputType getListOutputMapping(final IGraphQLObjectMapper graphQLObjectMapper, final Type type) {
ParameterizedType pType = (ParameterizedType) type;
GraphQLObjectType objectType = GraphQLObjectType.newObject()
.name(graphQLObjectMapper.getTypeNamingStrategy().getTypeName(graphQLObjectMapper, type))
.field(GraphQLFieldDefinition.newFieldDefinition()
.name(KEY_NAME)
.type(graphQLObjectMapper.getOutputType(pType.getActualTypeArguments()[0]))
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name(VALUE_NAME)
.type(graphQLObjectMapper.getOutputType(pType.getActualTypeArguments()[1]))
.build())
.build();
return new GraphQLList(objectType);
}
示例4: assertGenericListTypeMapping
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
private void assertGenericListTypeMapping(String name, GraphQLOutputType expectedWrappedType, GraphQLOutputType graphQLOutputType) {
assertEquals(GraphQLList.class, graphQLOutputType.getClass());
GraphQLList listType = (GraphQLList) graphQLOutputType;
GraphQLType wrappedType = listType.getWrappedType();
assertEquals(name, wrappedType.getName());
assertEquals(expectedWrappedType.getClass(), wrappedType.getClass());
if (expectedWrappedType instanceof GraphQLObjectType) {
GraphQLObjectType objectType = (GraphQLObjectType) wrappedType;
assertEquals("field1", objectType.getFieldDefinition("field1").getName());
assertEquals(Scalars.GraphQLString, objectType.getFieldDefinition("field1").getType());
assertEquals("field2", objectType.getFieldDefinition("field2").getName());
assertEquals(Scalars.GraphQLInt, objectType.getFieldDefinition("field2").getType());
}
}
示例5: generateOutputType
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
protected GraphQLOutputType generateOutputType(Object object) {
//An enum is a special case in both java and graphql,
//and must be checked for while generating other kinds of types
GraphQLEnumType enumType = generateEnumType(object);
if (enumType != null) {
return enumType;
}
List<GraphQLFieldDefinition> fields = getOutputFieldDefinitions(object);
if (fields == null || fields.isEmpty()) {
return null;
}
String typeName = getGraphQLTypeNameOrIdentityCode(object);
GraphQLObjectType.Builder builder = newObject()
.name(typeName)
.fields(fields)
.description(getTypeDescription(object));
GraphQLInterfaceType[] interfaces = getInterfaces(object);
if (interfaces != null) {
builder.withInterfaces(interfaces);
}
return builder.build();
}
示例6: toGraphQLType
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
@Override
public GraphQLObjectType toGraphQLType(String typeName, AnnotatedType javaType, Set<Type> abstractTypes, OperationMapper operationMapper, BuildContext buildContext) {
GraphQLObjectType.Builder typeBuilder = newObject()
.name(typeName)
.description(buildContext.typeInfoGenerator.generateTypeDescription(javaType));
GraphQLType graphQLType = javaType.getAnnotation(GraphQLType.class);
List<String> fieldOrder = graphQLType != null ? Arrays.asList(graphQLType.fieldOrder()) : Collections.emptyList();
List<GraphQLFieldDefinition> fields = getFields(javaType, fieldOrder, buildContext, operationMapper);
fields.forEach(typeBuilder::field);
List<GraphQLOutputType> interfaces = getInterfaces(javaType, abstractTypes, fields, buildContext, operationMapper);
interfaces.forEach(inter -> {
if (inter instanceof GraphQLInterfaceType) {
typeBuilder.withInterface((GraphQLInterfaceType) inter);
} else {
typeBuilder.withInterface((GraphQLTypeReference) inter);
}
});
GraphQLObjectType type = new MappedGraphQLObjectType(typeBuilder.build(), javaType);
interfaces.forEach(inter -> buildContext.typeRepository.registerCovariantType(inter.getName(), javaType, type));
buildContext.typeRepository.registerObjectType(type);
return type;
}
示例7: mapEntry
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
private GraphQLOutputType mapEntry(GraphQLOutputType keyType, GraphQLOutputType valueType, BuildContext buildContext) {
String typeName = "mapEntry_" + keyType.getName() + "_" + valueType.getName();
if (buildContext.knownTypes.contains(typeName)) {
return new GraphQLTypeReference(typeName);
}
buildContext.knownTypes.add(typeName);
return newObject()
.name(typeName)
.description("Map entry")
.field(newFieldDefinition()
.name("key")
.description("Map key")
.type(keyType)
.build())
.field(newFieldDefinition()
.name("value")
.description("Map value")
.type(valueType)
.build())
.build();
}
示例8: toGraphQLOperation
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
/**
* Maps a single operation to a GraphQL output field (as queries in GraphQL are nothing but fields of the root operation type).
*
* @param operation The operation to map to a GraphQL output field
* @param buildContext The shared context containing all the global information needed for mapping
*
* @return GraphQL output field representing the given operation
*/
public GraphQLFieldDefinition toGraphQLOperation(Operation operation, BuildContext buildContext) {
Set<Type> abstractTypes = new HashSet<>();
GraphQLOutputType type = toGraphQLType(operation.getJavaType(), abstractTypes, buildContext);
GraphQLFieldDefinition.Builder queryBuilder = newFieldDefinition()
.name(operation.getName())
.description(operation.getDescription())
.type(type);
List<GraphQLArgument> arguments = operation.getArguments().stream()
.filter(OperationArgument::isMappable)
.map(argument -> toGraphQLArgument(argument, abstractTypes, buildContext))
.collect(Collectors.toList());
queryBuilder.argument(arguments);
if (type.getName() != null && !type.getName().equals("Connection") && type.getName().endsWith("Connection")) {
if (buildContext.relay.getConnectionFieldArguments().stream()
.anyMatch(connArg -> arguments.stream()
.anyMatch(arg -> arg.getName().equals(connArg.getName()) && !arg.getType().getName().equals(connArg.getType().getName())))) {
throw new TypeMappingException("Operation \"" + operation.getName() + "\" has arguments of types incompatible with the Relay Connection spec");
}
}
ValueMapper valueMapper = buildContext.valueMapperFactory.getValueMapper(abstractTypes, buildContext.globalEnvironment);
queryBuilder.dataFetcher(createResolver(operation, valueMapper, buildContext.globalEnvironment));
return new MappedGraphQLFieldDefinition(queryBuilder.build(), operation);
}
示例9: testInlineUnion
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
@Test
public void testInlineUnion() {
InlineUnionService unionService = new InlineUnionService();
GraphQLSchema schema = new TestSchemaGenerator()
.withTypeAdapters(new MapToListTypeAdapter<>(new ObjectScalarStrategy()))
.withDefaults()
.withOperationsFromSingleton(unionService)
.generate();
GraphQLOutputType fieldType = schema.getQueryType().getFieldDefinition("union").getType();
assertNonNull(fieldType, GraphQLList.class);
GraphQLType list = ((graphql.schema.GraphQLNonNull) fieldType).getWrappedType();
assertListOf(list, GraphQLList.class);
GraphQLType map = ((GraphQLList) list).getWrappedType();
assertMapOf(map, GraphQLUnionType.class, GraphQLUnionType.class);
GraphQLObjectType entry = ((GraphQLObjectType) ((GraphQLList) map).getWrappedType());
GraphQLOutputType key = entry.getFieldDefinition("key").getType();
GraphQLOutputType value = entry.getFieldDefinition("value").getType();
assertEquals("Simple_One_Two", key.getName());
assertEquals("nice", ((GraphQLUnionType) key).getDescription());
assertEquals(value.getName(), "Education_Street");
assertUnionOf(key, schema.getType("SimpleOne"), schema.getType("SimpleTwo"));
assertUnionOf(value, schema.getType("Education"), schema.getType("Street"));
}
示例10: buildInstanceOutputType
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
@Override
public GraphQLOutputType buildInstanceOutputType(InstanceFieldBuilderContext instanceFieldBuilderContext,
InstanceOutputTypeService instanceOutputTypeService) {
Map<String, Object> initValues = buildInitValuesMap();
SchemaInstanceField target = getArrayEntryType().fieldFactory(getParent(), initValues);
return new GraphQLList(target.buildInstanceOutputType(instanceFieldBuilderContext, instanceOutputTypeService));
}
示例11: FieldOfTypeConfig
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
public FieldOfTypeConfig(String name, String id, Service service, GraphQLOutputType graphqlOutputType, Boolean isList, String targetName) {
this.name = name;
this.id=id;
this.service=service;
this.graphqlOutputType = graphqlOutputType;
this.targetName=targetName;
this.isList=isList;
}
示例12: buildField
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
/**
* Constructs a GraphQLField with a given name and type.
*/
public static GraphQLFieldDefinition buildField(String name, GraphQLType type) {
return GraphQLFieldDefinition.newFieldDefinition()
.type((GraphQLOutputType) type)
.name(name)
.build();
}
示例13: buildFieldWithArgs
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
/**
* Builds a GraphQL Field on a field that takes arguments in order to fetch it.
* ie: Any @GraphQLFetcher annotated method that takes an argument.
*/
public static GraphQLFieldDefinition buildFieldWithArgs(String fieldName, GraphQLType type, Class<?> beanClazz) {
PropertyDataFetcherWithArgs dataFetcher = new PropertyDataFetcherWithArgs(fieldName, beanClazz);
return GraphQLFieldDefinition.newFieldDefinition()
.type((GraphQLOutputType) type)
.name(fieldName)
.dataFetcher(dataFetcher)
.argument(dataFetcher.getValidArguments())
.build();
}
示例14: getOutputType
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
@Override
public GraphQLOutputType getOutputType(IGraphQLObjectMapper graphQLObjectMapper, Type type) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
return new GraphQLList(graphQLObjectMapper.getOutputType(parameterizedType.getActualTypeArguments()[0]));
} else {
return new GraphQLList(graphQLObjectMapper.getOutputType(Object.class));
}
}
示例15: getOutputType
import graphql.schema.GraphQLOutputType; //导入依赖的package包/类
@Override
public GraphQLOutputType getOutputType(IGraphQLObjectMapper graphQLObjectMapper, Type type) {
if (type instanceof ParameterizedType) {
return getListOutputMapping(graphQLObjectMapper, type);
} else {
throw new NotMappableException(String.format("%s is not mappable to GraphQL", graphQLObjectMapper.getTypeNamingStrategy().getTypeName(graphQLObjectMapper, type)));
}
}