本文整理汇总了Java中graphql.schema.GraphQLInterfaceType类的典型用法代码示例。如果您正苦于以下问题:Java GraphQLInterfaceType类的具体用法?Java GraphQLInterfaceType怎么用?Java GraphQLInterfaceType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphQLInterfaceType类属于graphql.schema包,在下文中一共展示了GraphQLInterfaceType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: generateOutputType
import graphql.schema.GraphQLInterfaceType; //导入依赖的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
示例2: generateInterfaceType
import graphql.schema.GraphQLInterfaceType; //导入依赖的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
示例3: getInterfaces
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
protected void getInterfaces(
final Map<Class<?>, GraphQLInterfaceType> interfaceMap,
final Class<?> clazz) {
for (Class<?> intf : clazz.getInterfaces()) {
if (interfaceMap.containsKey(intf)) {
continue;
}
GraphQLInterfaceType iType = getContext().getInterfaceType(intf);
if (iType != null) {
interfaceMap.put(intf, iType);
}
getInterfaces(interfaceMap, intf);
}
Class<?> superClazz = clazz.getSuperclass();
if (superClazz != null && superClazz != Object.class) {
getInterfaces(interfaceMap, superClazz);
}
}
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:20,代码来源:Interfaces_Reflection.java
示例4: toGraphQLType
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
@Override
public GraphQLObjectType toGraphQLType(String typeName, AnnotatedType javaType, Set<Type> abstractTypes, OperationMapper operationMapper, BuildContext buildContext) {
GraphQLObjectType.Builder typeBuilder = newObject()
.name(typeName)
.description(buildContext.typeInfoGenerator.generateTypeDescription(javaType));
GraphQLType graphQLType = javaType.getAnnotation(GraphQLType.class);
List<String> fieldOrder = graphQLType != null ? Arrays.asList(graphQLType.fieldOrder()) : Collections.emptyList();
List<GraphQLFieldDefinition> fields = getFields(javaType, fieldOrder, buildContext, operationMapper);
fields.forEach(typeBuilder::field);
List<GraphQLOutputType> interfaces = getInterfaces(javaType, abstractTypes, fields, buildContext, operationMapper);
interfaces.forEach(inter -> {
if (inter instanceof GraphQLInterfaceType) {
typeBuilder.withInterface((GraphQLInterfaceType) inter);
} else {
typeBuilder.withInterface((GraphQLTypeReference) inter);
}
});
GraphQLObjectType type = new MappedGraphQLObjectType(typeBuilder.build(), javaType);
interfaces.forEach(inter -> buildContext.typeRepository.registerCovariantType(inter.getName(), javaType, type));
buildContext.typeRepository.registerObjectType(type);
return type;
}
开发者ID:leangen,项目名称:graphql-spqr,代码行数:26,代码来源:ObjectTypeMapper.java
示例5: build
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
ProtoRegistry build() {
ImmutableListMultimap<String, TypeModification> modificationsMap =
ImmutableListMultimap.copyOf(
this.typeModifications
.stream()
.map(
modification ->
new SimpleImmutableEntry<>(modification.getTypeName(), modification))
.collect(Collectors.toList()));
final BiMap<String, GraphQLType> mapping = HashBiMap.create();
GraphQLInterfaceType nodeInterface =
new Relay()
.nodeInterface(
env -> {
Relay.ResolvedGlobalId resolvedGlobalId =
new Relay().fromGlobalId(env.getArguments().get("id").toString());
return (GraphQLObjectType) mapping.get(resolvedGlobalId.getType());
});
mapping.putAll(
modifyTypes(
getMap(fileDescriptors, descriptors, enumDescriptors, nodeInterface),
modificationsMap));
return new ProtoRegistry(mapping, nodeInterface);
}
开发者ID:google,项目名称:rejoiner,代码行数:29,代码来源:ProtoRegistry.java
示例6: getMap
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
private static BiMap<String, GraphQLType> getMap(
List<FileDescriptor> fileDescriptors,
List<Descriptor> descriptors,
List<EnumDescriptor> enumDescriptors,
GraphQLInterfaceType nodeInterface) {
HashBiMap<String, GraphQLType> mapping = HashBiMap.create(getEnumMap(enumDescriptors));
LinkedList<Descriptor> loop = new LinkedList<>(descriptors);
Set<FileDescriptor> fileDescriptorSet = extractDependencies(fileDescriptors);
for (FileDescriptor fileDescriptor : fileDescriptorSet) {
loop.addAll(fileDescriptor.getMessageTypes());
mapping.putAll(getEnumMap(fileDescriptor.getEnumTypes()));
}
while (!loop.isEmpty()) {
Descriptor descriptor = loop.pop();
if (!mapping.containsKey(descriptor.getFullName())) {
mapping.put(
ProtoToGql.getReferenceName(descriptor),
ProtoToGql.convert(descriptor, nodeInterface));
GqlInputConverter inputConverter =
GqlInputConverter.newBuilder().add(descriptor.getFile()).build();
mapping.put(
GqlInputConverter.getReferenceName(descriptor),
inputConverter.getInputType(descriptor));
loop.addAll(descriptor.getNestedTypes());
mapping.putAll(getEnumMap(descriptor.getEnumTypes()));
}
}
return ImmutableBiMap.copyOf(mapping);
}
开发者ID:google,项目名称:rejoiner,代码行数:34,代码来源:ProtoRegistry.java
示例7: GraphQLObjectMapper
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
public GraphQLObjectMapper(ITypeFactory typeFactory, List<IGraphQLTypeMapper> graphQLTypeMappers, Optional<ITypeNamingStrategy> typeNamingStrategy,
Optional<IDataFetcherFactory> dataFetcherFactory, Optional<Class<? extends IDataFetcher>> defaultMethodDataFetcher,
Map<Class<?>, Class<? extends DefaultTypeConverter>> typeConverters, List<Class<?>> relayNodeTypes) {
this.typeFactory = typeFactory;
this.relayNodeTypes = relayNodeTypes;
this.defaultTypeConverters = typeConverters;
this.setDefaultMethodDataFetcher(defaultMethodDataFetcher.or(DefaultMethodDataFetcher.class));
if (typeNamingStrategy.isPresent()) {
this.typeNamingStrategy = typeNamingStrategy.get();
}
if (dataFetcherFactory.isPresent()) {
this.setDataFetcherFactory(dataFetcherFactory.get());
}
ImmutableList.Builder<IGraphQLTypeMapper> interfaceTypeMappersBuilder = ImmutableList.builder();
Map<Type, IGraphQLTypeMapper> classTypeMappersBuilder = Maps.newHashMap();
for (IGraphQLTypeMapper mapper : graphQLTypeMappers) {
GraphQLTypeMapper mapperAnnotation = mapper.getClass().getAnnotation(GraphQLTypeMapper.class);
if (mapperAnnotation.type().isInterface()) {
interfaceTypeMappersBuilder.add(mapper);
} else {
classTypeMappersBuilder.put(mapperAnnotation.type(), mapper);
}
}
this.interfaceTypeMappers = interfaceTypeMappersBuilder.build();
this.classTypeMappers = ImmutableMap.copyOf(classTypeMappersBuilder);
// store the Node type interface mapping
nodeTypeName = getTypeNamingStrategy().getTypeName(this, INode.class);
this.getOutputTypeCache().put(nodeTypeName,
GraphQLInterfaceType.newInterface()
.name(nodeTypeName)
.typeResolver(this)
.field(GraphQLFieldDefinition.newFieldDefinition().name("id").type(Scalars.GraphQLString).build())
.build());
}
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:41,代码来源:GraphQLObjectMapper.java
示例8: testGraphQLInterfaces
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
@Test
public void testGraphQLInterfaces() throws JsonProcessingException {
logger.debug("testGraphQLInterfaces");
Object interfaceType = generator.getInterfaceType(InterfaceChild.class);
assertThat(interfaceType, instanceOf(GraphQLInterfaceType.class));
GraphQLObjectType queryType = newObject()
.name("testQuery")
.field(newFieldDefinition()
.type((GraphQLOutputType) interfaceType)
.name("testObj")
.staticValue(new InterfaceImpl())
.build())
.build();
GraphQLSchema testSchema = GraphQLSchema.newSchema()
.query(queryType)
.build();
String queryString =
"{"
+ " testObj {"
+ " parent"
+ " child"
+ " }"
+ "}";
ExecutionResult queryResult = new GraphQL(testSchema).execute(queryString);
assertThat(queryResult.getErrors(), is(empty()));
Map<String, Object> resultMap = (Map<String, Object>) queryResult.getData();
if (logger.isDebugEnabled()) {
logger.debug("testGraphQLInterfaces resultMap {}", prettyPrint(resultMap));
}
assertThat(((Map<String, Object>)resultMap.get("testObj")),
equalTo((Map<String, Object>) new HashMap<String, Object>() {{
put("parent", "parent");
put("child", "child");
}}));
assertThat(((Map<String, Object>)resultMap.get("testObj")).size(),
is(2));
}
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:41,代码来源:TypeGeneratorTest.java
示例9: toGraphQLType
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
@Override
public GraphQLInterfaceType toGraphQLType(String typeName, AnnotatedType javaType, Set<Type> abstractTypes, OperationMapper operationMapper, BuildContext buildContext) {
GraphQLInterfaceType.Builder typeBuilder = newInterface()
.name(typeName)
.description(buildContext.typeInfoGenerator.generateTypeDescription(javaType));
GraphQLInterface graphQLInterface = javaType.getAnnotation(GraphQLInterface.class);
List<String> fieldOrder = graphQLInterface != null ? Arrays.asList(graphQLInterface.fieldOrder()) : Collections.emptyList();
List<GraphQLFieldDefinition> fields = objectTypeMapper.getFields(javaType, fieldOrder, buildContext, operationMapper);
fields.forEach(typeBuilder::field);
typeBuilder.typeResolver(buildContext.typeResolver);
GraphQLInterfaceType type = new MappedGraphQLInterfaceType(typeBuilder.build(), javaType);
if (javaType.isAnnotationPresent(GraphQLInterface.class)) {
GraphQLInterface meta = javaType.getAnnotation(GraphQLInterface.class);
if (meta.implementationAutoDiscovery()) {
String[] scanPackages = meta.scanPackages();
if (scanPackages.length == 0 && Utils.arrayNotEmpty(buildContext.basePackages)) {
scanPackages = buildContext.basePackages;
}
ClassUtils.findImplementations(javaType, scanPackages).forEach(impl ->
getImplementingType(impl, abstractTypes, operationMapper, buildContext)
.ifPresent(implType -> buildContext.typeRepository.registerDiscoveredCovariantType(type.getName(), impl, implType)));
}
}
return type;
}
开发者ID:leangen,项目名称:graphql-spqr,代码行数:30,代码来源:InterfaceMapper.java
示例10: equals
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
@Override
public boolean equals(Object that) {
if (that == this) return true;
boolean baseEquals = that instanceof GraphQLInterfaceType &&
((GraphQLInterfaceType) that).getName().equals(getName()) &&
((GraphQLInterfaceType) that).getFieldDefinitions().equals(getFieldDefinitions());
return baseEquals && (!(that instanceof MappedGraphQLInterfaceType) ||
GenericTypeReflector.equals(((MappedGraphQLInterfaceType) that).getJavaType(), this.getJavaType()));
}
开发者ID:leangen,项目名称:graphql-spqr,代码行数:11,代码来源:MappedGraphQLInterfaceType.java
示例11: BuildContext
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
/**
* The shared context accessible throughout the schema generation process
*
* @param operationRepository Repository that can be used to fetch all known (singleton and domain) queries
* @param typeMappers Repository of all registered {@link io.leangen.graphql.generator.mapping.TypeMapper}s
* @param environment The globally shared environment
* @param interfaceStrategy The strategy deciding what Java type gets mapped to a GraphQL interface
* @param basePackages The base (root) package of the entire project
* @param typeInfoGenerator Generates type name/description
* @param valueMapperFactory The factory used to produce {@link io.leangen.graphql.metadata.strategy.value.ValueMapper} instances
* @param inputFieldStrategy The strategy deciding how GraphQL input fields are discovered from Java types
* @param knownTypes The cache of known type names
* @param relayMappingConfig Relay specific configuration
*/
public BuildContext(OperationRepository operationRepository, TypeMapperRepository typeMappers,
GlobalEnvironment environment,
InterfaceMappingStrategy interfaceStrategy, String[] basePackages,
TypeInfoGenerator typeInfoGenerator, ValueMapperFactory valueMapperFactory,
InputFieldDiscoveryStrategy inputFieldStrategy, Set<GraphQLType> knownTypes,
RelayMappingConfig relayMappingConfig) {
this.operationRepository = operationRepository;
this.typeRepository = environment.typeRepository;
this.typeMappers = typeMappers;
this.typeInfoGenerator = typeInfoGenerator;
this.relay = environment.relay;
this.node = knownTypes.stream()
.filter(GraphQLUtils::isRelayNodeInterface)
.findFirst().map(type -> (GraphQLInterfaceType) type)
.orElse(relay.nodeInterface(new RelayNodeTypeResolver(this.typeRepository, typeInfoGenerator)));
this.typeResolver = new DelegatingTypeResolver(this.typeRepository, typeInfoGenerator);
this.interfaceStrategy = interfaceStrategy;
this.basePackages = basePackages;
this.valueMapperFactory = valueMapperFactory;
this.inputFieldStrategy = inputFieldStrategy;
this.globalEnvironment = environment;
this.knownTypes = knownTypes.stream()
.filter(type -> type instanceof GraphQLOutputType)
.map(GraphQLType::getName)
.collect(Collectors.toSet());
this.knownInputTypes = knownTypes.stream()
.filter(type -> type instanceof GraphQLInputType)
.map(GraphQLType::getName)
.collect(Collectors.toSet());
this.relayMappingConfig = relayMappingConfig;
}
开发者ID:leangen,项目名称:graphql-spqr,代码行数:46,代码来源:BuildContext.java
示例12: getNodeQueriesByType
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
private Map<String, String> getNodeQueriesByType(List<Operation> queries,
List<GraphQLFieldDefinition> graphQlQueries,
TypeRepository typeRepository, GraphQLInterfaceType node) {
Map<String, String> nodeQueriesByType = new HashMap<>();
Map<String, String> directNodeQueriesByType = new HashMap<>();
for (int i = 0; i < queries.size(); i++) {
Operation query = queries.get(i);
GraphQLFieldDefinition graphQlQuery = graphQlQueries.get(i);
if (graphQlQuery.getArgument(GraphQLId.RELAY_ID_FIELD_NAME) != null
&& GraphQLUtils.isRelayId(graphQlQuery.getArgument(GraphQLId.RELAY_ID_FIELD_NAME))
&& query.getResolver(GraphQLId.RELAY_ID_FIELD_NAME) != null) {
GraphQLType unwrappedQueryType = GraphQLUtils.unwrapNonNull(graphQlQuery.getType());
if (unwrappedQueryType instanceof GraphQLObjectType
&& ((GraphQLObjectType) unwrappedQueryType).getInterfaces().contains(node)) {
directNodeQueriesByType.put(unwrappedQueryType.getName(), query.getName());
} else if (unwrappedQueryType instanceof GraphQLInterfaceType || unwrappedQueryType instanceof GraphQLUnionType) {
typeRepository.getOutputTypes(unwrappedQueryType.getName()).stream()
.map(MappedType::getAsObjectType)
.filter(implementation -> implementation.getInterfaces().contains(node))
.forEach(nodeType -> nodeQueriesByType.put(nodeType.getName(), query.getName()));
}
}
}
//this way more precise queries (returning node types directly) override interface/union queries
nodeQueriesByType.putAll(directNodeQueriesByType);
return nodeQueriesByType;
}
开发者ID:leangen,项目名称:graphql-spqr,代码行数:32,代码来源:OperationMapper.java
示例13: isRelayNodeInterface
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
public static boolean isRelayNodeInterface(GraphQLType node) {
return node instanceof GraphQLInterfaceType
&& node.getName().equals(Relay.NODE)
&& ((GraphQLInterfaceType) node).getFieldDefinitions().size() == 1
&& ((GraphQLInterfaceType) node).getFieldDefinition("id") != null
&& isRelayId(((GraphQLInterfaceType) node).getFieldDefinition("id"));
}
开发者ID:leangen,项目名称:graphql-spqr,代码行数:8,代码来源:GraphQLUtils.java
示例14: addPhantasmCast
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
private void addPhantasmCast(GraphQLInterfaceType.Builder builder,
Entry<FacetRecord, FacetFields> resolved) {
builder.field(GraphQLFieldDefinition.newFieldDefinition()
.name(String.format("as%s",
WorkspacePresentation.toTypeName(resolved.getKey()
.getName())))
.description(String.format("Cast to the %s facet",
resolved.getKey()
.getName()))
.type(new GraphQLTypeReference(resolved.getValue()
.getName()))
.build());
}
开发者ID:ChiralBehaviors,项目名称:Ultrastructure,代码行数:14,代码来源:WorkspaceSchema.java
示例15: existentialType
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
private GraphQLInterfaceType existentialType(Map<FacetRecord, FacetFields> resolved,
PhantasmProcessor processor) {
GraphQLInterfaceType.Builder builder = GraphQLInterfaceType.newInterface();
builder.name("Existential")
.description("The Existential interface type")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("id")
.description("Existential id")
.type(GraphQLUuid)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("name")
.description("Existential name")
.type(GraphQLString)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("description")
.description("Existential description")
.type(GraphQLString)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("updatedBy")
.description("Agency that updated the Existential")
.type(new GraphQLTypeReference("Agency"))
.build())
.typeResolver(processor);
resolved.entrySet()
.forEach(e -> addPhantasmCast(builder, e));
return builder.build();
}
开发者ID:ChiralBehaviors,项目名称:Ultrastructure,代码行数:32,代码来源:WorkspaceSchema.java
示例16: convert
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
static GraphQLObjectType convert(Descriptor descriptor, GraphQLInterfaceType nodeInterface) {
ImmutableList<GraphQLFieldDefinition> graphQLFieldDefinitions =
descriptor.getFields().stream().map(FIELD_CONVERTER).collect(toImmutableList());
Optional<GraphQLFieldDefinition> relayId =
descriptor
.getFields()
.stream()
.filter(field -> field.getOptions().hasExtension(RelayOptionsProto.relayOptions))
.map(
field ->
GraphQLFieldDefinition.newFieldDefinition()
.name("id")
.type(new GraphQLNonNull(GraphQLID))
.description("Relay ID")
.dataFetcher(
data ->
new Relay()
.toGlobalId(
getReferenceName(descriptor),
data.<Message>getSource().getField(field).toString()))
.build())
.findFirst();
if (relayId.isPresent()) {
return GraphQLObjectType.newObject()
.name(getReferenceName(descriptor))
.withInterface(nodeInterface)
.field(relayId.get())
.fields(
graphQLFieldDefinitions
.stream()
.map(
field ->
field.getName().equals("id")
? GraphQLFieldDefinition.newFieldDefinition()
.name("rawId")
.description(field.getDescription())
.type(field.getType())
.dataFetcher(field.getDataFetcher())
.build()
: field)
.collect(ImmutableList.toImmutableList()))
.build();
}
return GraphQLObjectType.newObject()
.name(getReferenceName(descriptor))
.fields(graphQLFieldDefinitions.isEmpty() ? STATIC_FIELD : graphQLFieldDefinitions)
.build();
}
开发者ID:google,项目名称:rejoiner,代码行数:52,代码来源:ProtoToGql.java
示例17: ProtoRegistry
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
private ProtoRegistry(BiMap<String, GraphQLType> mapping, GraphQLInterfaceType nodeInterface) {
this.mapping = mapping;
this.nodeInterface = nodeInterface;
}
开发者ID:google,项目名称:rejoiner,代码行数:5,代码来源:ProtoRegistry.java
示例18: getRelayNode
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
GraphQLInterfaceType getRelayNode() {
return nodeInterface;
}
开发者ID:google,项目名称:rejoiner,代码行数:4,代码来源:ProtoRegistry.java
示例19: getInterfaces
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
protected GraphQLInterfaceType[] getInterfaces(Object object) {
return getStrategies().getInterfacesStrategy().getInterfaces(object);
}
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:4,代码来源:TypeGenerator.java
示例20: generateInterfaceType
import graphql.schema.GraphQLInterfaceType; //导入依赖的package包/类
@Override
protected GraphQLInterfaceType generateInterfaceType(Object object) {
return getNextGen().generateInterfaceType(object);
}
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:5,代码来源:WrappingTypeGenerator.java
注:本文中的graphql.schema.GraphQLInterfaceType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论