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


Java GraphQLEnumType类代码示例

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


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


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