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


Java GraphQLObjectType类代码示例

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


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

示例1: test_helloWorld

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@Test
public void test_helloWorld(TestContext context) {
	Async async = context.async();
	
	GraphQLObjectType query = GraphQLObjectType.newObject()
	        .name("query")
	        .field(GraphQLFieldDefinition.newFieldDefinition()
	                .name("hello")
	                .type(Scalars.GraphQLString)
	                .dataFetcher(environment -> {
	        			return "world";
	        		}))
	        .build(); 
	
	GraphQLSchema schema = GraphQLSchema.newSchema()
			.query(query)
			.build();
	
	AsyncGraphQLExec asyncGraphQL = AsyncGraphQLExec.create(schema);
	Future<JsonObject> queryResult = asyncGraphQL.executeQuery("query { hello }", null, null, null);
	queryResult.setHandler(res -> {
		JsonObject json = res.result();
		context.assertEquals(new JsonObject().put("hello", "world"), json);
		async.complete();
	});
}
 
开发者ID:tibor-kocsis,项目名称:vertx-graphql-utils,代码行数:27,代码来源:AsyncGraphQLExecTest.java

示例2: getAllTypes

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

示例3: modifyTypes

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

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@Test
public void emptySchemaShouldGenerateCorrectProto() {
  assertThat(
          SchemaToProto.toProto(
              GraphQLSchema.newSchema()
                  .query(GraphQLObjectType.newObject().name("queryType"))
                  .build()))
      .isEqualTo(
          "// LINT: LEGACY_NAMES\n"
              + "// Autogenerated. Do not edit.\n"
              + "syntax = \"proto3\";\n"
              + "\n"
              + "package google.api.graphql.rejoiner.proto;\n"
              + "\n"
              + "option java_package = \"com.google.api.graphql.rejoiner.proto\";\n"
              + "option (jspb.js_namespace) = \"com.google.api.graphql.rejoiner.proto\";\n"
              + "import \"java/com/google/apps/jspb/jspb.proto\";\n"
              + "\n"
              + "message queryType {\n"
              + "option (jspb.message_id) = \"graphql.queryType\";\n"
              + "}");
}
 
开发者ID:google,项目名称:rejoiner,代码行数:23,代码来源:SchemaToProtoTest.java

示例5: getProductType

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@Bean
@Qualifier("ProductType")
public GraphQLObjectType getProductType() {
    return newObject()
            .name("ProductDto")
            .field(newFieldDefinition()
                    .name("productId")
                    .type(GraphQLID)
                    .dataFetcher(dfe -> ((ProductDto) dfe.getSource()).getId()))
            .field(newFieldDefinition()
                    .name("name")
                    .type(GraphQLString))
            .field(newFieldDefinition()
                    .name("brand")
                    .type(GraphQLString))
            .field(newFieldDefinition()
                    .name("description")
                    .type(GraphQLString))
            .field(newFieldDefinition()
                    .name("category")
                    .type(list(GraphQLString)))
            .field(newFieldDefinition()
                    .name("price")
                    .type(GraphQLBigDecimal))
            .build();
}
 
开发者ID:roybailey,项目名称:research-graphql,代码行数:27,代码来源:ManualGraphQLQuerySchema.java

示例6: getOrderItemType

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@Bean
@Qualifier("OrderItemType")
public GraphQLObjectType getOrderItemType() {
    return newObject()
            .name("OrderItemDto")
            .field(newFieldDefinition()
                    .name("productId")
                    .type(GraphQLString))
            .field(newFieldDefinition()
                    .name("quantity")
                    .type(GraphQLInt))
            .field(newFieldDefinition()
                    .name("product")
                    .type(getProductType())
                    .dataFetcher(new OrderItemProductFetcher(productAdaptor)))
            .build();
}
 
开发者ID:roybailey,项目名称:research-graphql,代码行数:18,代码来源:ManualGraphQLQuerySchema.java

示例7: testGraphQl

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@Test
public void testGraphQl() {
    GraphQLObjectType queryType = newObject()
            .name("helloWorldQuery")
            .field(newFieldDefinition()
                    .type(GraphQLString)
                    .name("hello")
                    .staticValue("world"))
            .build();

    GraphQLSchema schema = GraphQLSchema.newSchema()
            .query(queryType)
            .build();

    GraphQL graphQL = GraphQL.newGraphQL(schema).build();

    Map<String, Object> result = graphQL.execute("{hello}").getData();
    System.out.println(result);
    // Prints: {hello=world}
}
 
开发者ID:roybailey,项目名称:research-graphql,代码行数:21,代码来源:GraphQLHelloWorldTest.java

示例8: InstanceFieldBuilderContext

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
private InstanceFieldBuilderContext(String schemaNamespace,
                                    int maxDepth,
                                    String authHeader,
                                    Set<SchemaKey> referencedDefinitionIds,
                                    Map<SchemaKey, SchemaDescription> schemaDefinitionPreloadCache,
                                    Map<SchemaKey, SchemaDescription> schemaDescriptionRequestCache,
                                    Set<String> builtOutput,
                                    Map<String, GraphQLObjectType> objectTypeMap) {
    this.schemaNamespace = schemaNamespace;
    this.maxDepth = maxDepth;
    this.authHeader = authHeader;
    this.schemaDescriptionRequestCache = schemaDescriptionRequestCache;
    this.schemaDefinitionPreloadCache = schemaDefinitionPreloadCache;
    this.referencedDefinitionIds = referencedDefinitionIds;
    this.builtOutput = builtOutput;
    this.objectTypeMap = objectTypeMap;
}
 
开发者ID:nfl,项目名称:gold,代码行数:18,代码来源:InstanceFieldBuilderContext.java

示例9: getListOutputMapping

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

示例10: testDocumentedControllerAndMethods

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testDocumentedControllerAndMethods() {
	GraphQLSchema schema = GraphQLSchemaBuilder.newBuilder()
			.registerTypeFactory(new JacksonTypeFactory(new ObjectMapper()))
			.registerGraphQLControllerObjects(ImmutableList.<Object>of(new DocumentedMethodsTest()))
			.build();

	GraphQLObjectType mutationType = (GraphQLObjectType) schema.getMutationType().getFieldDefinition("Mutations").getType();
	GraphQLObjectType queryType = (GraphQLObjectType) schema.getQueryType().getFieldDefinition("Queries").getType();;
	assertEquals("Mutation Description", mutationType.getDescription());
	assertEquals("Query Description", queryType.getDescription());

	GraphQLFieldDefinition someQuery = queryType.getFieldDefinition("getSomeStrings");
	GraphQLFieldDefinition someMutation =  mutationType.getFieldDefinition("setSomeStrings");
	assertEquals("getSomeStrings description", someQuery.getDescription());
	assertEquals("setSomeStrings description", someMutation.getDescription());
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:19,代码来源:GraphQLSchemaBuilderTest.java

示例11: testFullTypeMappingStrategy

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@Test
public void testFullTypeMappingStrategy() {
	IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper(Optional.<ITypeNamingStrategy> of(new FullTypeNamingStrategy()));
	assertTypeMapping("String", Scalars.GraphQLString, graphQLObjectMapper.getOutputType(String.class));
	assertTypeMapping("Int", Scalars.GraphQLInt, graphQLObjectMapper.getOutputType(Integer.class));
	assertTypeMapping("Int", Scalars.GraphQLInt, graphQLObjectMapper.getOutputType(int.class));
	assertTypeMapping("Long", Scalars.GraphQLLong, graphQLObjectMapper.getOutputType(Long.class));
	assertTypeMapping("Long", Scalars.GraphQLLong, graphQLObjectMapper.getOutputType(long.class));
	assertTypeMapping("Float", Scalars.GraphQLFloat, graphQLObjectMapper.getOutputType(Float.class));
	assertTypeMapping("Float", Scalars.GraphQLFloat, graphQLObjectMapper.getOutputType(float.class));
	assertTypeMapping("Float", Scalars.GraphQLFloat, graphQLObjectMapper.getOutputType(Double.class));
	assertTypeMapping("Float", Scalars.GraphQLFloat, graphQLObjectMapper.getOutputType(double.class));
	assertTypeMapping("Boolean", Scalars.GraphQLBoolean, graphQLObjectMapper.getOutputType(Boolean.class));
	assertTypeMapping("com_bretpatterson_schemagen_graphql_impl_GraphQLObjectMapperTest",
			GraphQLObjectType.newObject().name("com_bretpatterson_schemagen_graphql_impl_GraphQLObjectMapperTest").build(),
			graphQLObjectMapper.getOutputType(this.getClass()));
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:18,代码来源:GraphQLObjectMapperTest.java

示例12: testRelayConnectionType

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

示例13: testGenericObjectsVariableResolution

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testGenericObjectsVariableResolution() {
	IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper(Optional.<ITypeNamingStrategy> absent());

	GraphQLObjectType outputType1 = (GraphQLObjectType) graphQLObjectMapper
			.getOutputType(new TypeToken<GenericObjectVariableResolution1<String, String>>() {
			}.getType());
	GraphQLObjectType outputType2 = (GraphQLObjectType) graphQLObjectMapper
			.getOutputType(new TypeToken<GenericObjectVariableResolution1<Integer, Integer>>() {
			}.getType());

	assertNotNull(outputType1.getFieldDefinition("innerGeneric"));
	assertEquals("InnerGeneric_String_String", outputType1.getFieldDefinition("innerGeneric").getType().getName());

	assertNotNull(outputType2.getFieldDefinition("innerGeneric"));
	assertEquals("InnerGeneric_Integer_Integer", outputType2.getFieldDefinition("innerGeneric").getType().getName());
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:19,代码来源:GraphQLObjectMapperTest.java

示例14: testMethodParameterRequired

import graphql.schema.GraphQLObjectType; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testMethodParameterRequired() {
	IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper(
			ImmutableList.<IGraphQLTypeMapper>builder().add(new TestTypeMapper()).addAll(GraphQLSchemaBuilder.getDefaultTypeMappers()).build());

	GraphQLObjectType objectType = (GraphQLObjectType) graphQLObjectMapper.getOutputType(new TypeToken<MethodRequiredFields>() {
	}.getType());

	assertEquals(MethodRequiredFields.class.getSimpleName(), objectType.getName());
	assertEquals(1, objectType.getFieldDefinitions().size());
	assertNotNull(objectType.getFieldDefinition("method"));

	List<GraphQLArgument> arguments = objectType.getFieldDefinition("method").getArguments();
	assertEquals(2, arguments.size());
	assertEquals(new GraphQLNonNull(Scalars.GraphQLString), arguments.get(0).getType());
	assertEquals(Scalars.GraphQLString, arguments.get(1).getType());
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:19,代码来源:GraphQLObjectMapperTest.java

示例15: testMethodBasedFields

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


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