• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java GraphQLEnumType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getAllTypes

import graphql.schema.GraphQLEnumType; //导入依赖的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.GraphQLEnumType; //导入依赖的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: buildValidArgs

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
private void buildValidArgs(boolean isListFetcher) { 
	validArgs = new LinkedList<GraphQLArgument>();
	validArgs.addAll(arguments.values());
	//Only accept the f argument if we can actually do anything with it. 
	if (fetchers.size() > 0) {
		String enumName = resource.getBeanClass().getSimpleName() + (isListFetcher ? "s" : "") + "_functions";
		GraphQLEnumType.Builder functionNamesEnum = GraphQLEnumType.newEnum()
			.name(enumName);
		for (String functionName : fetchers.keySet()) { 
			functionNamesEnum.value(functionName);
		}
		validArgs.add(GraphQLArgument.newArgument()
			.name("f")
			.type(functionNamesEnum.build())
			.build());
	}
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:18,代码来源:AnetResourceDataFetcher.java


示例4: testRecursiveTypes

import graphql.schema.GraphQLEnumType; //导入依赖的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


示例5: generateOutputType

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


示例6: generateInputType

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
protected GraphQLInputType generateInputType(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<GraphQLInputObjectField> fields = getInputFieldDefinitions(object);
    if (fields == null || fields.isEmpty()) {
        return null;
    }
    String typeName = getGraphQLTypeNameOrIdentityCode(object);
    
    GraphQLInputObjectType.Builder builder = new GraphQLInputObjectType.Builder();
    builder.name(typeName);
    builder.fields(fields);
    builder.description(getTypeDescription(object));
    return builder.build();
}
 
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:21,代码来源:FullTypeGenerator.java


示例7: testEnum

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
@Test
public void testEnum() {
    logger.debug("testEnum");
    Object enumObj = testContext.getOutputType(graphql.java.generator.Enum.class);
    Assert.assertThat(enumObj, instanceOf(GraphQLEnumType.class));
    Matcher<Iterable<GraphQLEnumValueDefinition>> hasItemsMatcher =
            hasItems(
                    hasProperty("name", is("A")),
                    hasProperty("name", is("B")),
                    hasProperty("name", is("C")));
    assertThat(((GraphQLEnumType)enumObj).getValues(), hasItemsMatcher);
    
    enumObj = testContext.getOutputType(graphql.java.generator.EmptyEnum.class);
    Assert.assertThat(enumObj, instanceOf(GraphQLEnumType.class));
    assertThat(((GraphQLEnumType)enumObj).getValues(),
            instanceOf(List.class));
    assertThat(((GraphQLEnumType)enumObj).getValues().size(),
            is(0));
}
 
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:20,代码来源:TypeGeneratorWithFieldsGenIntegrationTest.java


示例8: getComplexity

import graphql.schema.GraphQLEnumType; //导入依赖的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


示例9: classToEnumType

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
/**
 * Converts an enum to a GraphQLEnumType.
 * @param enumClazz the Enum to convert
 * @return A GraphQLEnum type for class.
 */
public GraphQLEnumType classToEnumType(Class<?> enumClazz) {
    if (enumConversions.containsKey(enumClazz)) {
        return enumConversions.get(enumClazz);
    }

    Enum [] values = (Enum []) enumClazz.getEnumConstants();

    GraphQLEnumType.Builder builder = newEnum().name(toValidNameName(enumClazz.getName()));

    for (Enum value : values) {
        builder.value(toValidNameName(value.name()), value);
    }

    GraphQLEnumType enumResult = builder.build();

    enumConversions.put(enumClazz, enumResult);

    return enumResult;
}
 
开发者ID:yahoo,项目名称:elide,代码行数:25,代码来源:GraphQLConversionUtils.java


示例10: toTs

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
/** Returns a proto source file for the schema. */
public static String toTs(GraphQLSchema schema) {
  ArrayList<String> messages = new ArrayList<>();
  for (GraphQLType type : SchemaToProto.getAllTypes(schema)) {
    if (type instanceof GraphQLEnumType) {
      messages.add(toEnum((GraphQLEnumType) type));
    } else if (type instanceof GraphQLObjectType) {
      messages.add(toMessage((GraphQLObjectType) type));
    }
  }
  return HEADER + Joiner.on("\n\n").join(messages);
}
 
开发者ID:google,项目名称:rejoiner,代码行数:13,代码来源:SchemaToTypeScript.java


示例11: toEnum

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
private static String toEnum(GraphQLEnumType type) {
  String types =
      type.getValues()
          .stream()
          .map(value -> value.getName())
          .filter(name -> !name.equals("UNRECOGNIZED"))
          .collect(Collectors.joining(", \n  "));
  return String.format("export enum %s {\n  %s\n}", type.getName() + "Enum", types);
}
 
开发者ID:google,项目名称:rejoiner,代码行数:10,代码来源:SchemaToTypeScript.java


示例12: toType

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
private static String toType(GraphQLType type) {
  if (type instanceof GraphQLList) {
    return toType(((GraphQLList) type).getWrappedType()) + "[]";
  } else if (type instanceof GraphQLObjectType) {
    return type.getName();
  } else if (type instanceof GraphQLEnumType) {
    return type.getName() + "Enum";
  } else {
    return TYPE_MAP.get(type.getName());
  }
}
 
开发者ID:google,项目名称:rejoiner,代码行数:12,代码来源:SchemaToTypeScript.java


示例13: toProto

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
/** Returns a proto source file for the schema. */
public static String toProto(GraphQLSchema schema) {
  ArrayList<String> messages = new ArrayList<>();

  for (GraphQLType type : getAllTypes(schema)) {
    if (type instanceof GraphQLEnumType) {
      messages.add(toEnum((GraphQLEnumType) type));
    } else if (type instanceof GraphQLObjectType) {
      messages.add(toMessage((GraphQLObjectType) type));
    }
  }

  return HEADER + Joiner.on("\n\n").join(messages);
}
 
开发者ID:google,项目名称:rejoiner,代码行数:15,代码来源:SchemaToProto.java


示例14: toEnum

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
private static String toEnum(GraphQLEnumType type) {
  ArrayList<String> values = new ArrayList<>();
  int i = 0;
  for (GraphQLEnumValueDefinition value : type.getValues()) {
    if (value.getName().equals("UNRECOGNIZED")) {
      continue;
    }
    values.add(String.format("%s = %d;", value.getName(), i));
    i++;
  }
  return String.format(
      "message %s {\n %s\n enum Enum {\n%s\n}\n}",
      type.getName(), getJspb(type), Joiner.on("\n").join(values));
}
 
开发者ID:google,项目名称:rejoiner,代码行数:15,代码来源:SchemaToProto.java


示例15: toType

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
private static String toType(GraphQLType type) {
  if (type instanceof GraphQLList) {
    return "repeated " + toType(((GraphQLList) type).getWrappedType());
  } else if (type instanceof GraphQLObjectType) {
    return type.getName();
  } else if (type instanceof GraphQLEnumType) {
    return type.getName() + ".Enum";
  } else {
    return TYPE_MAP.get(type.getName());
  }
}
 
开发者ID:google,项目名称:rejoiner,代码行数:12,代码来源:SchemaToProto.java


示例16: convert

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
static GraphQLEnumType convert(EnumDescriptor descriptor) {
  GraphQLEnumType.Builder builder = GraphQLEnumType.newEnum().name(getReferenceName(descriptor));
  for (EnumValueDescriptor value : descriptor.getValues()) {
    builder.value(value.getName());
  }
  return builder.build();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:8,代码来源:ProtoToGql.java


示例17: convertShouldWorkForEnums

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
@Test
public void convertShouldWorkForEnums() {
  GraphQLEnumType result = ProtoToGql.convert(TestEnum.getDescriptor());
  assertThat(result.getName())
      .isEqualTo("javatests_com_google_api_graphql_rejoiner_proto_Proto2_TestEnum");
  assertThat(result.getValues()).hasSize(3);
  assertThat(result.getValues().stream().map(a -> a.getName()).toArray())
      .asList()
      .containsExactly("UNKNOWN", "FOO", "BAR");
}
 
开发者ID:google,项目名称:rejoiner,代码行数:11,代码来源:ProtoToGqlTest.java


示例18: gqlEnumBuilder

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
public static GraphQLEnumType gqlEnumBuilder(Class<? extends Enum<?>> enumClazz) { 
	Enum<?>[] constants = enumClazz.getEnumConstants();
	GraphQLEnumType.Builder builder = GraphQLEnumType.newEnum().name(enumClazz.getSimpleName());
	for (Enum<?> s : constants) { 
		builder.value(s.name(), s);
	}
	return builder.build();
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:9,代码来源:GraphQLUtils.java


示例19: getOutputType

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
@Override
public GraphQLOutputType getOutputType(IGraphQLObjectMapper graphQLObjectMapper, Type type) {
	Class<?> classType = (Class<?>) type;
	Class<?> enumClassType = classType.getComponentType();
	GraphQLEnumType.Builder enumType = GraphQLEnumType.newEnum()
			.name(graphQLObjectMapper.getTypeNamingStrategy().getTypeName(graphQLObjectMapper, enumClassType));

	for (Object value : enumClassType.getEnumConstants()) {
		enumType.value(value.toString(), value);
	}
	return new GraphQLList(enumType.build());

}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:14,代码来源:EnumSetMapper.java


示例20: getInputType

import graphql.schema.GraphQLEnumType; //导入依赖的package包/类
@Override
public GraphQLInputType getInputType(IGraphQLObjectMapper graphQLObjectMapper, Type type) {
	Class<?> classType = (Class<?>) type;
	Class<?> enumClassType = classType.getComponentType();
	GraphQLEnumType.Builder enumType = GraphQLEnumType.newEnum()
			.name(graphQLObjectMapper.getTypeNamingStrategy().getTypeName(graphQLObjectMapper, enumClassType));

	for (Object value : enumClassType.getEnumConstants()) {
		enumType.value(value.toString(), value);
	}
	return new GraphQLList(enumType.build());
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:13,代码来源:EnumSetMapper.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RowPosition类代码示例发布时间:2022-05-22
下一篇:
Java ClassType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap