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


Java GraphQLFieldDefinition类代码示例

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


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

示例1: test_helloWorld

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

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
@Override
public GraphQLFieldDefinition apply(FieldDescriptor fieldDescriptor) {
  GraphQLFieldDefinition.Builder builder =
      GraphQLFieldDefinition.newFieldDefinition()
          .type(convertType(fieldDescriptor))
          .dataFetcher(
              new ProtoDataFetcher(UNDERSCORE_TO_CAMEL.convert(fieldDescriptor.getName())))
          .name(UNDERSCORE_TO_CAMEL.convert(fieldDescriptor.getName()));
  if (fieldDescriptor.getFile().toProto().getSourceCodeInfo().getLocationCount()
      > fieldDescriptor.getIndex()) {
    builder.description(
        fieldDescriptor
            .getFile()
            .toProto()
            .getSourceCodeInfo()
            .getLocation(fieldDescriptor.getIndex())
            .getLeadingComments());
  }
  if (fieldDescriptor.getOptions().hasDeprecated()
      && fieldDescriptor.getOptions().getDeprecated()) {
    builder.deprecate("deprecated in proto");
  }
  return builder.build();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:25,代码来源:ProtoToGql.java

示例4: schemaModuleShouldProvideQueryType

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
@Test
public void schemaModuleShouldProvideQueryType() {
  Injector injector =
      Guice.createInjector(
          new SchemaProviderModule(),
          new SchemaModule() {
            @Query
            GraphQLFieldDefinition greeting =
                GraphQLFieldDefinition.newFieldDefinition()
                    .name("greeting")
                    .type(Scalars.GraphQLString)
                    .staticValue("hello world")
                    .build();
          });
  assertThat(
          injector
              .getInstance(Key.get(GraphQLSchema.class, Schema.class))
              .getQueryType()
              .getFieldDefinition("greeting"))
      .isNotNull();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:22,代码来源:SchemaProviderModuleTest.java

示例5: schemaModuleShouldProvideQueryFields

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
@Test
public void schemaModuleShouldProvideQueryFields() {
  Injector injector =
      Guice.createInjector(
          new SchemaModule() {
            @Query
            GraphQLFieldDefinition greeting =
                GraphQLFieldDefinition.newFieldDefinition()
                    .name("greeting")
                    .type(Scalars.GraphQLString)
                    .staticValue("hello world")
                    .build();
          });
  assertThat(injector.getInstance(QUERY_KEY)).hasSize(1);
  assertThat(injector.getInstance(MUTATION_KEY)).isEmpty();
  assertThat(injector.getInstance(EXTRA_TYPE_KEY)).isEmpty();
  assertThat(injector.getInstance(MODIFICATION_KEY)).isEmpty();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:19,代码来源:SchemaModuleTest.java

示例6: replaceFieldShouldReplaceField

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
@Test
public void replaceFieldShouldReplaceField() throws Exception {
  TypeModification typeModification =
      Type.find("project")
          .replaceField(
              GraphQLFieldDefinition.newFieldDefinition()
                  .name("name")
                  .staticValue("rejoinerv2")
                  .type(Scalars.GraphQLString)
                  .build());
  assertThat(
          typeModification
              .apply(OBJECT_TYPE)
              .getFieldDefinition("name")
              .getDataFetcher()
              .get(null))
      .isEqualTo("rejoinerv2");
}
 
开发者ID:google,项目名称:rejoiner,代码行数:19,代码来源:TypeTest.java

示例7: getGraphQLFieldDefinitionBuilder

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
@Override
protected GraphQLFieldDefinition.Builder getGraphQLFieldDefinitionBuilder(
        InstanceFieldBuilderContext instanceFieldBuilderContext,
        InstanceOutputTypeService instanceOutputTypeService) {
    return super.getGraphQLFieldDefinitionBuilder(instanceFieldBuilderContext,
            instanceOutputTypeService).dataFetcher(environment -> {
        @SuppressWarnings("unchecked")
        Map<String, Object> id = (Map<String, Object>)
                ((Map<String, Object>) environment.getSource()).get(getMemberFieldName());
        if (id == null) {
            return null;
        }

        SchemaInstanceKey parentSchemaInstanceKey =
                ((GraphQLInstanceRequestContext) environment.getContext()).getSchemaInstanceKey();
        @SuppressWarnings("unchecked")
        String childSchemaName = ((Map<String, String>)id.get(SCHEMA_INSTANCE_KEY_FIELD)).get(SCHEMA_NAME_FIELD);
        SchemaInstanceKey schemaInstanceKey = parentSchemaInstanceKey.getChildSchemaInstanceKey(childSchemaName);

        return instanceOutputTypeService.findMultiTypeById(schemaInstanceKey, id);
    });
}
 
开发者ID:nfl,项目名称:gold,代码行数:23,代码来源:MultiTypeDynamicReferenceType.java

示例8: processDeprecated

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
private GraphQLFieldDefinition.Builder processDeprecated(GraphQLFieldDefinition.Builder builder, Optional<Method> method, Optional<Field> field) {
	GraphQLDeprecated deprecated = null;
	Deprecated javaDeprecreated = null;
	if (method.isPresent()) {
		deprecated = method.get().getAnnotation(GraphQLDeprecated.class);
		javaDeprecreated = method.get().getAnnotation(Deprecated.class);
	}
	if (field.isPresent()) {
		if (deprecated == null) {
			deprecated = field.get().getAnnotation(GraphQLDeprecated.class);
		}
		if (javaDeprecreated == null) {
			javaDeprecreated = field.get().getAnnotation(Deprecated.class);
		}
	}

	if (deprecated != null) {
		builder.deprecate(deprecated.value());
	} else if (javaDeprecreated != null) {
		builder.deprecate("");
	}

	return builder;
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:25,代码来源:GraphQLObjectMapper.java

示例9: processDescription

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
private GraphQLFieldDefinition.Builder processDescription(GraphQLFieldDefinition.Builder builder, Optional<Method> method, Optional<Field> field) {
	Optional<GraphQLDescription> maybeDescription = Optional.absent();
	if (method.isPresent()) {
		maybeDescription = Optional.fromNullable(method.get().getAnnotation(GraphQLDescription.class));
	}
	if (field.isPresent() && !maybeDescription.isPresent()) {
		if (!maybeDescription.isPresent() ) {
			maybeDescription = Optional.fromNullable(field.get().getAnnotation(GraphQLDescription.class));
		}
	}

	if (maybeDescription.isPresent()) {
		builder.description(maybeDescription.get().value());
	}

	return builder;
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:18,代码来源:GraphQLObjectMapper.java

示例10: getListOutputMapping

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

示例11: testMutation

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

	GraphQLFieldDefinition mutationType = schema.getMutationType().getFieldDefinition("setName");
	assertEquals("setName", mutationType.getName());
	assertEquals(Scalars.GraphQLString, mutationType.getArgument("name").getType());

	ExecutionResult result = new GraphQL(schema).execute("mutation M { setName(name: \"The new name\") }");

	String newName = ((Map<String, String>) result.getData()).get("setName");
	assertEquals(0, result.getErrors().size());
	assertEquals("The new name", newName);

	result = new GraphQL(schema).execute("query Q { getName }");

	newName = ((Map<String, String>) result.getData()).get("getName");
	assertEquals(0, result.getErrors().size());
	assertEquals("The new name", newName);
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:25,代码来源:GraphQLSchemaBuilderTest.java

示例12: testDocumentedControllerAndMethods

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

示例13: setup

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
@Before
public void setup() {
	expectedObjectType = GraphQLObjectType.newObject()
			.name(CollectionsTestObject.class.getSimpleName())
			.field(GraphQLFieldDefinition.newFieldDefinition().name("field1").type(Scalars.GraphQLString).build())
			.field(GraphQLFieldDefinition.newFieldDefinition().name("field2").type(Scalars.GraphQLInt).build())
			.build();

	graphQLObjectMapper = new GraphQLObjectMapper(objectMapper,
			GraphQLSchemaBuilder.getDefaultTypeMappers(),
			Optional.<ITypeNamingStrategy>absent(),
			Optional.<IDataFetcherFactory>absent(),
			Optional.<Class<? extends IDataFetcher>>absent(),
			GraphQLSchemaBuilder.getDefaultTypeConverters(),
			ImmutableList.<Class<?>> of());
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:17,代码来源:GraphQLObjectMapper_CollectionsTest.java

示例14: generateOutputType

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

示例15: generateInterfaceType

import graphql.schema.GraphQLFieldDefinition; //导入依赖的package包/类
protected GraphQLInterfaceType generateInterfaceType(Object object) {
    List<GraphQLFieldDefinition> fieldDefinitions = getOutputFieldDefinitions(object);
    if (fieldDefinitions == null || fieldDefinitions.isEmpty()) {
        return null;
    }
    String name = getGraphQLTypeNameOrIdentityCode(object);
    TypeResolver typeResolver = getTypeResolver(object);
    String description = getTypeDescription(object);
    if (name == null || fieldDefinitions == null || typeResolver == null) {
        return null;
    }
    GraphQLInterfaceType.Builder builder = GraphQLInterfaceType.newInterface()
            .description(description)
            .fields(fieldDefinitions)
            .name(name)
            .typeResolver(typeResolver);
    return builder.build();
}
 
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:19,代码来源:FullTypeGenerator.java


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