本文整理汇总了Java中graphql.schema.GraphQLList类的典型用法代码示例。如果您正苦于以下问题:Java GraphQLList类的具体用法?Java GraphQLList怎么用?Java GraphQLList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphQLList类属于graphql.schema包,在下文中一共展示了GraphQLList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllTypes
import graphql.schema.GraphQLList; //导入依赖的package包/类
@SuppressWarnings("JdkObsolete")
static Set<GraphQLType> getAllTypes(GraphQLSchema schema) {
LinkedHashSet<GraphQLType> types = new LinkedHashSet<>();
LinkedList<GraphQLObjectType> loop = new LinkedList<>();
loop.add(schema.getQueryType());
types.add(schema.getQueryType());
while (!loop.isEmpty()) {
for (GraphQLFieldDefinition field : loop.pop().getFieldDefinitions()) {
GraphQLType type = field.getType();
if (type instanceof GraphQLList) {
type = ((GraphQLList) type).getWrappedType();
}
if (!types.contains(type)) {
if (type instanceof GraphQLEnumType) {
types.add(field.getType());
}
if (type instanceof GraphQLObjectType) {
types.add(type);
loop.add((GraphQLObjectType) type);
}
}
}
}
return types;
}
示例2: get
import graphql.schema.GraphQLList; //导入依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
Object source = environment.getSource();
if (source == null) {
return null;
}
if (source instanceof Map) {
return ((Map<?, ?>) source).get(name);
}
GraphQLType type = environment.getFieldType();
if (type instanceof GraphQLNonNull) {
type = ((GraphQLNonNull) type).getWrappedType();
}
if (type instanceof GraphQLList) {
return call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name) + "List");
}
if (type instanceof GraphQLEnumType) {
Object o = call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name));
if (o != null) {
return o.toString();
}
}
return call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name));
}
示例3: convertType
import graphql.schema.GraphQLList; //导入依赖的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;
}
}
示例4: completeValueForList
import graphql.schema.GraphQLList; //导入依赖的package包/类
/**
* If the result is a list, then it's elements can now potentially be a {@link CompletableFuture}.
* To reduce the number of tasks in progress, it behooves us to wait for all those completable
* elements to wrap up.
*
* @return the completed execution result
*/
@Override
protected ExecutionResult completeValueForList(ExecutionContext executionContext,
GraphQLList fieldType,
List<Field> fields, Iterable<Object> result) {
ExecutionResult executionResult =
super.completeValueForList(executionContext, fieldType, fields, result);
List<Object> completableResults = (List<Object>) executionResult.getData();
List<Object> completedResults = new ArrayList<>();
completableResults.forEach(completedResult -> {
completedResults.add((completedResult instanceof CompletableFuture) ?
((CompletableFuture) completedResult).join() : completedResult);
});
((ExecutionResultImpl) executionResult).setData(completedResults);
return executionResult;
}
示例5: getListOutputMapping
import graphql.schema.GraphQLList; //导入依赖的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);
}
示例6: getListInputMapping
import graphql.schema.GraphQLList; //导入依赖的package包/类
private GraphQLInputType getListInputMapping(final IGraphQLObjectMapper graphQLObjectMapper, final Type type) {
ParameterizedType pType = (ParameterizedType) type;
GraphQLInputObjectType objectType = GraphQLInputObjectType.newInputObject()
.name(graphQLObjectMapper.getTypeNamingStrategy().getTypeName(graphQLObjectMapper, type))
.field(GraphQLInputObjectField.newInputObjectField()
.name(KEY_NAME)
.type(graphQLObjectMapper.getInputType(pType.getActualTypeArguments()[0]))
.build())
.field(GraphQLInputObjectField.newInputObjectField()
.name(VALUE_NAME)
.type(graphQLObjectMapper.getInputType(pType.getActualTypeArguments()[1]))
.build())
.build();
return new GraphQLList(objectType);
}
示例7: testRelayConnectionType
import graphql.schema.GraphQLList; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testRelayConnectionType() {
IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper(Optional.<ITypeNamingStrategy> of(new RelayTypeNamingStrategy()));
GraphQLObjectType type = (GraphQLObjectType) graphQLObjectMapper.getOutputType(new TypeToken<RelayConnection<String>>() {
}.getType());
assertEquals("Relay_String_Connection", type.getName());
assertNotNull(type.getFieldDefinition("edges"));
assertNotNull(type.getFieldDefinition("pageInfo"));
assertEquals(GraphQLList.class, type.getFieldDefinition("edges").getType().getClass());
assertEquals("Edge_String", ((GraphQLList) type.getFieldDefinition("edges").getType()).getWrappedType().getName());
assertEquals(GraphQLObjectType.class, ((GraphQLList) type.getFieldDefinition("edges").getType()).getWrappedType().getClass());
GraphQLObjectType edgeObject = (GraphQLObjectType) ((GraphQLList) type.getFieldDefinition("edges").getType()).getWrappedType();
assertNotNull(edgeObject.getFieldDefinition("node"));
assertNotNull(edgeObject.getFieldDefinition("cursor"));
assertEquals(Scalars.GraphQLString, edgeObject.getFieldDefinition("node").getType());
assertEquals(Scalars.GraphQLString, edgeObject.getFieldDefinition("cursor").getType());
}
示例8: testMethodBasedFields
import graphql.schema.GraphQLList; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testMethodBasedFields() {
IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper(
ImmutableList.<IGraphQLTypeMapper> builder().add(new TestTypeMapper()).addAll(GraphQLSchemaBuilder.getDefaultTypeMappers()).build());
GraphQLObjectType objectType = (GraphQLObjectType) graphQLObjectMapper.getOutputType(new TypeToken<MethodBasedFields>() {
}.getType());
assertEquals(MethodBasedFields.class.getSimpleName(), objectType.getName());
assertEquals(2, objectType.getFieldDefinitions().size());
assertNotNull(objectType.getFieldDefinition("stringField"));
assertEquals(Scalars.GraphQLString, objectType.getFieldDefinition("stringField").getType());
assertNotNull(objectType.getFieldDefinition("stringList"));
assertEquals(GraphQLList.class, objectType.getFieldDefinition("stringList").getType().getClass());
assertEquals(Scalars.GraphQLString, ((GraphQLList) objectType.getFieldDefinition("stringList").getType()).getWrappedType());
assertNull(objectType.getFieldDefinition("ignoredObject"));
assertEquals(DefaultMethodDataFetcher.class, objectType.getFieldDefinition("stringField").getDataFetcher().getClass());
assertEquals(CollectionConverterDataFetcher.class, objectType.getFieldDefinition("stringList").getDataFetcher().getClass());
}
示例9: testMethodOnlyFields
import graphql.schema.GraphQLList; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testMethodOnlyFields() {
IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper(
ImmutableList.<IGraphQLTypeMapper> builder().add(new TestTypeMapper()).addAll(GraphQLSchemaBuilder.getDefaultTypeMappers()).build());
GraphQLObjectType objectType = (GraphQLObjectType) graphQLObjectMapper.getOutputType(new TypeToken<MethodOnlyFields>() {
}.getType());
assertEquals(MethodOnlyFields.class.getSimpleName(), objectType.getName());
assertEquals(2, objectType.getFieldDefinitions().size());
assertNotNull(objectType.getFieldDefinition("stringField"));
assertEquals(Scalars.GraphQLString, objectType.getFieldDefinition("stringField").getType());
assertNotNull(objectType.getFieldDefinition("stringList"));
assertEquals(GraphQLList.class, objectType.getFieldDefinition("stringList").getType().getClass());
assertEquals(Scalars.GraphQLString, ((GraphQLList) objectType.getFieldDefinition("stringList").getType()).getWrappedType());
assertNull(objectType.getFieldDefinition("ignoredObject"));
assertEquals(DefaultMethodDataFetcher.class, objectType.getFieldDefinition("stringField").getDataFetcher().getClass());
assertEquals(CollectionConverterDataFetcher.class, objectType.getFieldDefinition("stringList").getDataFetcher().getClass());
}
示例10: assertGenericListTypeMapping
import graphql.schema.GraphQLList; //导入依赖的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());
}
}
示例11: testRecursiveTypes
import graphql.schema.GraphQLList; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testRecursiveTypes() {
GraphQLList listType = (GraphQLList) graphQLObjectMapper
.getOutputType(new TypeToken<Map<TestEnum, List<List<List<List<List<List<String>>>>>>>>() {
}.getType());
GraphQLObjectType outputType = (GraphQLObjectType) listType.getWrappedType();
assertEquals("Map_TestEnum_List_List_List_List_List_List_String", outputType.getName());
GraphQLEnumType keyType = (GraphQLEnumType) outputType.getFieldDefinition(MapMapper.KEY_NAME).getType();
GraphQLType valueType = outputType.getFieldDefinition(MapMapper.VALUE_NAME).getType();
int depth = 0;
while (valueType.getClass() == GraphQLList.class) {
depth++;
valueType = ((GraphQLList) valueType).getWrappedType();
}
assertEquals(6, depth);
// now we verify the key type
assertEquals(Scalars.GraphQLString, valueType);
}
示例12: testInlineUnion
import graphql.schema.GraphQLList; //导入依赖的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"));
}
示例13: completeValueForList
import graphql.schema.GraphQLList; //导入依赖的package包/类
@Override
protected ExecutionResult completeValueForList(ExecutionContext executionContext, GraphQLList fieldType, List<Field> fields, List<Object> result) {
Observable<?> resultObservable =
Observable.from(
IntStream.range(0, result.size())
.mapToObj(idx -> new ListTuple(idx, result.get(idx)))
.toArray(ListTuple[]::new)
)
.flatMap(tuple -> {
ExecutionResult executionResult = completeValue(executionContext, fieldType.getWrappedType(), fields, tuple.result);
if (executionResult instanceof RxExecutionResult) {
return Observable.zip(Observable.just(tuple.index), ((RxExecutionResult)executionResult).getDataObservable(), ListTuple::new);
}
return Observable.just(new ListTuple(tuple.index, executionResult.getData()));
})
.toList()
.map(listTuples -> {
return listTuples.stream()
.sorted(Comparator.comparingInt(x -> x.index))
.map(x -> x.result)
.collect(Collectors.toList());
});
return new RxExecutionResult(resultObservable, null);
}
示例14: buildInputObjectArgument
import graphql.schema.GraphQLList; //导入依赖的package包/类
/**
* Wraps a constructed GraphQL Input Object in an argument.
* @param entityClass - The class to construct the input object from.
* @param asList Whether or not the argument is a single instance or a list.
* @return The constructed argument.
*/
private GraphQLArgument buildInputObjectArgument(Class<?> entityClass, boolean asList) {
GraphQLInputType argumentType = inputObjectRegistry.get(entityClass);
if (asList) {
return newArgument()
.name(ARGUMENT_DATA)
.type(new GraphQLList(argumentType))
.build();
} else {
return newArgument()
.name(ARGUMENT_DATA)
.type(argumentType)
.build();
}
}
示例15: instances
import graphql.schema.GraphQLList; //导入依赖的package包/类
private GraphQLFieldDefinition instances() {
return newFieldDefinition().name(Introspector.decapitalize(English.plural(name)))
.description(String.format("Return the instances of %s",
name))
.argument(newArgument().name(IDS)
.description("list of ids of the instances to query")
.type(new GraphQLList(GraphQLUuid))
.build())
.type(new GraphQLList(referenceToType(facet)))
.dataFetcher(context -> {
@SuppressWarnings("unchecked")
List<UUID> ids = (List<UUID>) context.getArgument(ID);
return (ids != null ? ctx(context).lookupList(ids)
: ctx(context).getInstances(facet)).stream()
.collect(Collectors.toList());
})
.build();
}