当前位置: 首页>>代码示例>>Java>>正文


Java GraphQLType类代码示例

本文整理汇总了Java中graphql.schema.GraphQLType的典型用法代码示例。如果您正苦于以下问题:Java GraphQLType类的具体用法?Java GraphQLType怎么用?Java GraphQLType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GraphQLType类属于graphql.schema包,在下文中一共展示了GraphQLType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllTypes

import graphql.schema.GraphQLType; //导入依赖的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;
}
 
开发者ID:google,项目名称:rejoiner,代码行数:27,代码来源:SchemaToProto.java

示例2: get

import graphql.schema.GraphQLType; //导入依赖的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));
}
 
开发者ID:google,项目名称:rejoiner,代码行数:26,代码来源:ProtoToGql.java

示例3: modifyTypes

import graphql.schema.GraphQLType; //导入依赖的package包/类
/** Applies the supplied modifications to the GraphQLTypes. */
private static BiMap<String, GraphQLType> modifyTypes(
    BiMap<String, GraphQLType> mapping,
    ImmutableListMultimap<String, TypeModification> modifications) {
  BiMap<String, GraphQLType> result = HashBiMap.create(mapping.size());
  for (String key : mapping.keySet()) {
    if (mapping.get(key) instanceof GraphQLObjectType) {
      GraphQLObjectType val = (GraphQLObjectType) mapping.get(key);
      if (modifications.containsKey(key)) {
        for (TypeModification modification : modifications.get(key)) {
          val = modification.apply(val);
        }
      }
      result.put(key, val);
    } else {
      result.put(key, mapping.get(key));
    }
  }
  return result;
}
 
开发者ID:google,项目名称:rejoiner,代码行数:21,代码来源:ProtoRegistry.java

示例4: completeValue

import graphql.schema.GraphQLType; //导入依赖的package包/类
/**
 * If the result that is returned by the {@link graphql.schema.DataFetcher} is a {@link
 * CompletableFuture}, then wait for it to complete, prior to calling the super method.
 *
 * @return the completed execution result
 */
@Override
protected ExecutionResult completeValue(final ExecutionContext executionContext,
                                        final GraphQLType fieldType,
                                        final List<Field> fields, Object result) {
  if (!(result instanceof CompletableFuture)) {
    return super.completeValue(executionContext, fieldType, fields, result);
  }
  ExecutionStrategy executionStrategy = this;
  return ((CompletableFuture<ExecutionResult>) result)
    .thenComposeAsync(
      (Function<Object, CompletableFuture<ExecutionResult>>)
        completedResult -> completable(
          executionStrategy.completeValue(executionContext, fieldType, fields, completedResult),
          executorService), executorService)
    .exceptionally(throwable -> {
      executionContext.addError(new ExceptionWhileDataFetching(throwable));
      return null;
    })
    .join();
}
 
开发者ID:karthicks,项目名称:graphql-java-async,代码行数:27,代码来源:AsyncExecutionStrategy.java

示例5: assertGenericListTypeMapping

import graphql.schema.GraphQLType; //导入依赖的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());
	}
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:19,代码来源:GraphQLObjectMapper_CollectionsTest.java

示例6: testRecursiveTypes

import graphql.schema.GraphQLType; //导入依赖的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);
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:23,代码来源:GraphQLObjectMapper_CollectionsTest.java

示例7: getParameterizedType

import graphql.schema.GraphQLType; //导入依赖的package包/类
@Override
public GraphQLType getParameterizedType(Object object,
        Type genericType, TypeKind typeKind) {
    TypeSpecContainer originalObject = new TypeSpecContainer(
            object, genericType, typeKind);
    TypeSpecContainer interiorObject = getInteriorObjectToGenerate(originalObject);
    if (interiorObject == null) {
        return getType(object, genericType, typeKind);
    }
    
    //using getParameterizedType is intentional,
    //in case multiple wrappers are desired
    GraphQLType interiorType = getParameterizedType(
            interiorObject.getRepresentativeObject(),
            interiorObject.getGenericType(),
            interiorObject.getTypeKind());
    return wrapType(interiorType, originalObject);
}
 
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:19,代码来源:WrappingTypeGenerator.java

示例8: basicsOutput

import graphql.schema.GraphQLType; //导入依赖的package包/类
public void basicsOutput() {
    GraphQLType type = generator.getOutputType(clazz);
    Assert.assertThat(type,
            instanceOf(GraphQLObjectType.class));
    GraphQLObjectType objectType = (GraphQLObjectType) type;
    Assert.assertThat(objectType.getName(),
            containsString(expectedName));
    Assert.assertThat(objectType.getDescription(),
            containsString("Autogenerated f"));
    Assert.assertThat(objectType.getFieldDefinitions(),
            notNullValue());
    for (GraphQLFieldDefinition field : objectType.getFieldDefinitions()) {
        Assert.assertThat(field,
                notNullValue());
        Assert.assertThat(field.getDescription(),
                containsString("Autogenerated f"));
    }
    Assert.assertThat(objectType.getFieldDefinitions().size(),
            is(expectedNumFields));
}
 
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:21,代码来源:TypeGeneratorParameterizedTest.java

示例9: TypeRepository

import graphql.schema.GraphQLType; //导入依赖的package包/类
public TypeRepository(Set<GraphQLType> knownTypes) {
    //extract known interface implementations
    knownTypes.stream()
            .filter(type -> type instanceof MappedGraphQLObjectType)
            .map(type -> (MappedGraphQLObjectType) type)
            .forEach(obj -> obj.getInterfaces().forEach(
                    inter -> registerCovariantType(inter.getName(), obj.getJavaType(), obj)));

    //extract known union members
    knownTypes.stream()
            .filter(type -> type instanceof GraphQLUnionType)
            .map(type -> (GraphQLUnionType) type)
            .forEach(union -> union.getTypes().stream()
                    .filter(type -> type instanceof MappedGraphQLObjectType)
                    .map(type -> (MappedGraphQLObjectType) type)
                    .forEach(obj -> registerCovariantType(union.getName(), obj.getJavaType(), obj)));
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:18,代码来源:TypeRepository.java

示例10: getComplexity

import graphql.schema.GraphQLType; //导入依赖的package包/类
@Override
public int getComplexity(ResolvedField node, int childScore) {
    String expression = node.getResolver().getComplexityExpression();
    if (expression == null) {
        GraphQLType fieldType = GraphQLUtils.unwrap(node.getFieldDefinition().getType());
        if (fieldType instanceof GraphQLScalarType || fieldType instanceof GraphQLEnumType) {
            return 1;
        }
        return 1 + childScore;
    }
    Bindings bindings = engine.createBindings();
    bindings.putAll(node.getArguments());
    bindings.put("childScore", childScore);
    try {
        return ((Number) engine.eval(expression, bindings)).intValue();
    } catch (ScriptException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:20,代码来源:JavaScriptEvaluator.java

示例11: testInlineUnion

import graphql.schema.GraphQLType; //导入依赖的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"));
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:26,代码来源:UnionTest.java

示例12: createType

import graphql.schema.GraphQLType; //导入依赖的package包/类
public GraphQLType createType(Project project) {
	Map<String, GraphQLObjectType> types = generateMicroschemaFieldType(project);
	// No microschemas have been found - We need to add a dummy type in order to keep the type system working
	if (types.isEmpty()) {
		types.put("dummy", newObject().name("dummy").field(newFieldDefinition().name("dummy").type(GraphQLString).staticValue(null).build()).description("Placeholder dummy microschema type").build());
	}
	GraphQLObjectType[] typeArray = types.values().toArray(new GraphQLObjectType[types.values().size()]);

	GraphQLUnionType fieldType = newUnionType().name(MICRONODE_TYPE_NAME).possibleTypes(typeArray).description("Fields of the micronode.")
			.typeResolver(env -> {
				Object object = env.getObject();
				if (object instanceof Micronode) {
					Micronode fieldContainer = (Micronode) object;
					MicroschemaContainerVersion micronodeFieldSchema = fieldContainer.getSchemaContainerVersion();
					String schemaName = micronodeFieldSchema.getName();
					GraphQLObjectType foundType = types.get(schemaName);
					return foundType;
				}
				return null;
			}).build();

	return fieldType;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:24,代码来源:MicronodeFieldTypeProvider.java

示例13: getElementTypeOfList

import graphql.schema.GraphQLType; //导入依赖的package包/类
private GraphQLType getElementTypeOfList(ListFieldSchema schema) {
	switch (schema.getListType()) {
	case "boolean":
		return GraphQLBoolean;
	case "html":
		return GraphQLString;
	case "string":
		return GraphQLString;
	case "number":
		return GraphQLBigDecimal;
	case "date":
		return GraphQLString;
	case "node":
		return new GraphQLTypeReference("Node");
	case "micronode":
		return new GraphQLTypeReference("Micronode");
	default:
		return null;
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:21,代码来源:FieldDefinitionProvider.java

示例14: set

import graphql.schema.GraphQLType; //导入依赖的package包/类
private void set(UpdatableRecord<?> instance,
                 Map<String, GraphQLType> types,
                 Map<String, Object> state) {
    state.entrySet()
         .stream()
         .filter(entry -> !entry.getKey()
                                .equals("id"))
         .forEach(entry -> {
             try {
                 PropertyUtils.setProperty(instance, entry.getKey(),
                                           entry.getValue());
             } catch (IllegalAccessException | InvocationTargetException
                     | NoSuchMethodException e) {
                 throw new IllegalArgumentException(String.format("Illegal property: %s",
                                                                  entry));
             }
         });
}
 
开发者ID:ChiralBehaviors,项目名称:Ultrastructure,代码行数:19,代码来源:JooqSchema.java

示例15: build

import graphql.schema.GraphQLType; //导入依赖的package包/类
@Override
public GraphQLType build() {
  return Types.elementTypeBuilder()
              .name(NAME)
              .field(Fields.stringField("title"))
              .field(Fields.spelField("directors", "${source.from('directed')}") // SPEL Expression
                           .type(Types.list(Director.REF)))
              .build();
}
 
开发者ID:creactiviti,项目名称:graffiti,代码行数:10,代码来源:Movie.java


注:本文中的graphql.schema.GraphQLType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。