graphql.schema.GraphQLInterfaceType Java Examples
The following examples show how to use
graphql.schema.GraphQLInterfaceType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeRegistryTest.java From graphql-spqr with Apache License 2.0 | 6 votes |
private void assertSameType(GraphQLType t1, GraphQLType t2, GraphQLCodeRegistry code1, GraphQLCodeRegistry code2) { assertSame(t1, t2); if (t1 instanceof GraphQLInterfaceType) { GraphQLInterfaceType i = (GraphQLInterfaceType) t1; assertSame(code1.getTypeResolver(i), code2.getTypeResolver(i)); } if (t1 instanceof GraphQLUnionType) { GraphQLUnionType u = (GraphQLUnionType) t1; assertSame(code1.getTypeResolver(u), code2.getTypeResolver(u)); } if (t1 instanceof GraphQLFieldsContainer) { GraphQLFieldsContainer c = (GraphQLFieldsContainer) t1; c.getFieldDefinitions().forEach(fieldDef -> assertSame(code1.getDataFetcher(c, fieldDef), code2.getDataFetcher(c, fieldDef))); } }
Example #2
Source File: FederationSdlPrinter.java From federation-jvm with MIT License | 6 votes |
private TypePrinter<GraphQLInterfaceType> interfacePrinter() { return (out, type, visibility) -> { if (isIntrospectionType(type)) { return; } GraphqlTypeComparatorEnvironment environment = GraphqlTypeComparatorEnvironment.newEnvironment() .parentType(GraphQLInterfaceType.class) .elementType(GraphQLFieldDefinition.class) .build(); Comparator<? super GraphQLSchemaElement> comparator = options.comparatorRegistry.getComparator(environment); if (shouldPrintAsAst(type.getDefinition())) { printAsAst(out, type.getDefinition(), type.getExtensionDefinitions()); } else { printComments(out, type, ""); out.format("interface %s%s", type.getName(), directivesString(GraphQLInterfaceType.class, type.getDirectives())); printFieldDefinitions(out, comparator, visibility.getFieldDefinitions(type)); out.format("\n\n"); } }; }
Example #3
Source File: Bootstrap.java From smallrye-graphql with Apache License 2.0 | 6 votes |
private void createGraphQLInterfaceType(InterfaceType interfaceType) { GraphQLInterfaceType.Builder interfaceTypeBuilder = GraphQLInterfaceType.newInterface() .name(interfaceType.getName()) .description(interfaceType.getDescription()); // Fields if (interfaceType.hasFields()) { interfaceTypeBuilder = interfaceTypeBuilder .fields(createGraphQLFieldDefinitionsFromFields(interfaceType.getName(), interfaceType.getFields())); } // Interfaces if (interfaceType.hasInterfaces()) { Set<Reference> interfaces = interfaceType.getInterfaces(); for (Reference i : interfaces) { interfaceTypeBuilder = interfaceTypeBuilder.withInterface(GraphQLTypeReference.typeRef(i.getName())); } } GraphQLInterfaceType graphQLInterfaceType = interfaceTypeBuilder.build(); // To resolve the concrete class codeRegistryBuilder.typeResolver(graphQLInterfaceType, new InterfaceResolver(interfaceType)); interfaceMap.put(interfaceType.getClassName(), graphQLInterfaceType); }
Example #4
Source File: InterfaceMapper.java From graphql-spqr with Apache License 2.0 | 6 votes |
@Override public GraphQLInterfaceType toGraphQLType(String typeName, AnnotatedType javaType, TypeMappingEnvironment env) { BuildContext buildContext = env.buildContext; GraphQLInterfaceType.Builder typeBuilder = newInterface() .name(typeName) .description(buildContext.typeInfoGenerator.generateTypeDescription(javaType, buildContext.messageBundle)); List<GraphQLFieldDefinition> fields = objectTypeMapper.getFields(typeName, javaType, env); fields.forEach(typeBuilder::field); typeBuilder.withDirective(Directives.mappedType(javaType)); buildContext.directiveBuilder.buildInterfaceTypeDirectives(javaType, buildContext.directiveBuilderParams()).forEach(directive -> typeBuilder.withDirective(env.operationMapper.toGraphQLDirective(directive, buildContext))); typeBuilder.comparatorRegistry(buildContext.comparatorRegistry(javaType)); GraphQLInterfaceType type = typeBuilder.build(); buildContext.codeRegistry.typeResolver(type, buildContext.typeResolver); registerImplementations(javaType, type, env); return type; }
Example #5
Source File: Interfaces_Reflection.java From graphql-java-type-generator with MIT License | 6 votes |
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); } }
Example #6
Source File: FullTypeGenerator.java From graphql-java-type-generator with MIT License | 6 votes |
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(); }
Example #7
Source File: FullTypeGenerator.java From graphql-java-type-generator with MIT License | 6 votes |
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(); }
Example #8
Source File: FederationSdlPrinter.java From federation-jvm with MIT License | 5 votes |
/** * This can print an in memory GraphQL schema back to a logical schema definition * * @param schema the schema in play * @return the logical schema definition */ public String print(GraphQLSchema schema) { StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); GraphqlFieldVisibility visibility = schema.getCodeRegistry().getFieldVisibility(); printer(schema.getClass()).print(out, schema, visibility); List<GraphQLType> typesAsList = schema.getAllTypesAsList() .stream() .sorted(Comparator.comparing(GraphQLNamedType::getName)) .filter(options.getIncludeTypeDefinition()) .collect(toList()); printType(out, typesAsList, GraphQLInterfaceType.class, visibility); printType(out, typesAsList, GraphQLUnionType.class, visibility); printType(out, typesAsList, GraphQLObjectType.class, visibility); printType(out, typesAsList, GraphQLEnumType.class, visibility); printType(out, typesAsList, GraphQLScalarType.class, visibility); printType(out, typesAsList, GraphQLInputObjectType.class, visibility); String result = sw.toString(); if (result.endsWith("\n\n")) { result = result.substring(0, result.length() - 1); } return result; }
Example #9
Source File: GraphQLUtils.java From graphql-spqr with Apache License 2.0 | 5 votes |
public static boolean isRelayNodeInterface(GraphQLType node) { if (!(node instanceof GraphQLInterfaceType)) { return false; } GraphQLInterfaceType interfaceType = (GraphQLInterfaceType) node; return interfaceType.getName().equals(Relay.NODE) && interfaceType.getFieldDefinitions().size() == 1 && interfaceType.getFieldDefinition(GraphQLId.RELAY_ID_FIELD_NAME) != null && isRelayId(interfaceType.getFieldDefinition(GraphQLId.RELAY_ID_FIELD_NAME)); }
Example #10
Source File: ObjectTypeMapper.java From graphql-spqr with Apache License 2.0 | 5 votes |
@Override public GraphQLObjectType toGraphQLType(String typeName, AnnotatedType javaType, TypeMappingEnvironment env) { BuildContext buildContext = env.buildContext; GraphQLObjectType.Builder typeBuilder = newObject() .name(typeName) .description(buildContext.typeInfoGenerator.generateTypeDescription(javaType, buildContext.messageBundle)); List<GraphQLFieldDefinition> fields = getFields(typeName, javaType, env); fields.forEach(typeBuilder::field); List<GraphQLNamedOutputType> interfaces = getInterfaces(javaType, fields, env); interfaces.forEach(inter -> { if (inter instanceof GraphQLInterfaceType) { typeBuilder.withInterface((GraphQLInterfaceType) inter); } else { typeBuilder.withInterface((GraphQLTypeReference) inter); } }); typeBuilder.withDirective(Directives.mappedType(javaType)); buildContext.directiveBuilder.buildObjectTypeDirectives(javaType, buildContext.directiveBuilderParams()).forEach(directive -> typeBuilder.withDirective(env.operationMapper.toGraphQLDirective(directive, buildContext))); typeBuilder.comparatorRegistry(buildContext.comparatorRegistry(javaType)); GraphQLObjectType type = typeBuilder.build(); interfaces.forEach(inter -> buildContext.typeRegistry.registerCovariantType(inter.getName(), javaType, type)); return type; }
Example #11
Source File: TypeGeneratorTest.java From graphql-java-type-generator with MIT License | 5 votes |
@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)); }
Example #12
Source File: Interfaces_Reflection.java From graphql-java-type-generator with MIT License | 5 votes |
@Override public GraphQLInterfaceType[] getInterfaces(Object object) { //TODO handle generics? if (object instanceof Class<?>) { if (((Class<?>) object).isInterface()) { return null; } Map<Class<?>, GraphQLInterfaceType> interfaces = new HashMap<Class<?>, GraphQLInterfaceType>(); getInterfaces(interfaces, (Class<?>) object); return interfaces.values().toArray(new GraphQLInterfaceType[0]); } return null; }
Example #13
Source File: FederationSdlPrinter.java From federation-jvm with MIT License | 5 votes |
public FederationSdlPrinter(Options options) { this.options = options; printers.put(GraphQLSchema.class, schemaPrinter()); printers.put(GraphQLObjectType.class, objectPrinter()); printers.put(GraphQLEnumType.class, enumPrinter()); printers.put(GraphQLScalarType.class, scalarPrinter()); printers.put(GraphQLInterfaceType.class, interfacePrinter()); printers.put(GraphQLUnionType.class, unionPrinter()); printers.put(GraphQLInputObjectType.class, inputObjectPrinter()); }
Example #14
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 5 votes |
private static BiMap<String, GraphQLType> getMap( List<FileDescriptor> fileDescriptors, List<Descriptor> descriptors, List<EnumDescriptor> enumDescriptors, GraphQLInterfaceType nodeInterface, SchemaOptions schemaOptions) { HashBiMap<String, GraphQLType> mapping = HashBiMap.create(getEnumMap(enumDescriptors, schemaOptions)); LinkedList<Descriptor> loop = new LinkedList<>(descriptors); Set<FileDescriptor> fileDescriptorSet = extractDependencies(fileDescriptors); for (FileDescriptor fileDescriptor : fileDescriptorSet) { loop.addAll(fileDescriptor.getMessageTypes()); mapping.putAll(getEnumMap(fileDescriptor.getEnumTypes(), schemaOptions)); } while (!loop.isEmpty()) { Descriptor descriptor = loop.pop(); if (!mapping.containsKey(descriptor.getFullName())) { mapping.put( ProtoToGql.getReferenceName(descriptor), ProtoToGql.convert(descriptor, nodeInterface, schemaOptions)); GqlInputConverter inputConverter = GqlInputConverter.newBuilder().add(descriptor.getFile()).build(); mapping.put( GqlInputConverter.getReferenceName(descriptor), inputConverter.getInputType(descriptor, schemaOptions)); loop.addAll(descriptor.getNestedTypes()); mapping.putAll(getEnumMap(descriptor.getEnumTypes(), schemaOptions)); } } return ImmutableBiMap.copyOf(mapping); }
Example #15
Source File: Bootstrap.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private void createGraphQLObjectType(Type type) { GraphQLObjectType.Builder objectTypeBuilder = GraphQLObjectType.newObject() .name(type.getName()) .description(type.getDescription()); // Fields if (type.hasFields()) { objectTypeBuilder = objectTypeBuilder .fields(createGraphQLFieldDefinitionsFromFields(type.getName(), type.getFields())); } // Operations if (type.hasOperations()) { for (Operation operation : type.getOperations()) { GraphQLFieldDefinition graphQLFieldDefinition = createGraphQLFieldDefinitionFromOperation(type.getName(), operation); objectTypeBuilder = objectTypeBuilder.field(graphQLFieldDefinition); } } // Interfaces if (type.hasInterfaces()) { Set<Reference> interfaces = type.getInterfaces(); for (Reference i : interfaces) { if (interfaceMap.containsKey(i.getClassName())) { GraphQLInterfaceType graphQLInterfaceType = interfaceMap.get(i.getClassName()); objectTypeBuilder = objectTypeBuilder.withInterface(graphQLInterfaceType); } } } GraphQLObjectType graphQLObjectType = objectTypeBuilder.build(); typeMap.put(type.getClassName(), graphQLObjectType); // Register this output for interface type resolving InterfaceOutputRegistry.register(type, graphQLObjectType); }
Example #16
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 5 votes |
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, schemaOptions), modificationsMap)); return new ProtoRegistry(mapping, nodeInterface); }
Example #17
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 4 votes |
private ProtoRegistry(BiMap<String, GraphQLType> mapping, GraphQLInterfaceType nodeInterface) { this.mapping = mapping; this.nodeInterface = nodeInterface; }
Example #18
Source File: GraphQLSchemaGenerator.java From graphql-spqr with Apache License 2.0 | 4 votes |
@Override public TypeResolver getTypeResolver(GraphQLInterfaceType interfaceType) { return codeRegistry.getTypeResolver(interfaceType); }
Example #19
Source File: GraphQLSchemaGenerator.java From graphql-spqr with Apache License 2.0 | 4 votes |
default TypeResolver getTypeResolver(GraphQLInterfaceType interfaceType) { return null; }
Example #20
Source File: OperationMapper.java From graphql-spqr with Apache License 2.0 | 4 votes |
private Map<String, String> getNodeQueriesByType(List<Operation> queries, List<GraphQLFieldDefinition> graphQLQueries, TypeRegistry typeRegistry, GraphQLInterfaceType node, BuildContext buildContext) { Map<String, String> nodeQueriesByType = 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 GraphQLNamedType) { GraphQLNamedType unwrappedOutput = (GraphQLNamedOutputType) unwrappedQueryType; unwrappedQueryType = buildContext.typeCache.resolveType(unwrappedOutput.getName()); if (unwrappedQueryType instanceof GraphQLObjectType && ((GraphQLObjectType) unwrappedQueryType).getInterfaces().contains(node)) { nodeQueriesByType.put(unwrappedOutput.getName(), query.getName()); } else if (unwrappedQueryType instanceof GraphQLInterfaceType) { typeRegistry.getOutputTypes(unwrappedOutput.getName()).stream() .map(MappedType::getAsObjectType) .filter(implementation -> implementation.getInterfaces().contains(node)) .forEach(nodeType -> nodeQueriesByType.putIfAbsent(nodeType.getName(), query.getName())); //never override more precise resolvers } else if (unwrappedQueryType instanceof GraphQLUnionType) { typeRegistry.getOutputTypes(unwrappedOutput.getName()).stream() .map(MappedType::getAsObjectType) .filter(implementation -> implementation.getInterfaces().contains(node)) .filter(Directives::isMappedType) // only register the possible types that can actually be returned from the primary resolver // for interface-unions it is all the possible types but, for inline unions, only one (right?) possible type can match .filter(implementation -> GenericTypeReflector.isSuperType(query.getResolver(GraphQLId.RELAY_ID_FIELD_NAME).getReturnType().getType(), Directives.getMappedType(implementation).getType())) .forEach(nodeType -> nodeQueriesByType.putIfAbsent(nodeType.getName(), query.getName())); //never override more precise resolvers } } } } return nodeQueriesByType; }
Example #21
Source File: BuildContext.java From graphql-spqr with Apache License 2.0 | 4 votes |
/** * The shared context accessible throughout the schema generation process * @param basePackages The base (root) package of the entire project * @param environment The globally shared environment * @param operationRegistry 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 transformers Repository of all registered {@link io.leangen.graphql.generator.mapping.SchemaTransformer}s * @param valueMapperFactory The factory used to produce {@link ValueMapper} instances * @param typeInfoGenerator Generates type name/description * @param messageBundle The global translation message bundle * @param interfaceStrategy The strategy deciding what Java type gets mapped to a GraphQL interface * @param scalarStrategy The strategy deciding how abstract Java types are discovered * @param abstractInputHandler The strategy deciding what Java type gets mapped to a GraphQL interface * @param inputFieldBuilders The strategy deciding how GraphQL input fields are discovered from Java types * @param interceptorFactory The factory to use to obtain interceptors applicable to a resolver * @param directiveBuilder The factory used to create directives where applicable * @param relayMappingConfig Relay specific configuration * @param knownTypes The cache of known type names */ public BuildContext(String[] basePackages, GlobalEnvironment environment, OperationRegistry operationRegistry, TypeMapperRegistry typeMappers, SchemaTransformerRegistry transformers, ValueMapperFactory valueMapperFactory, TypeInfoGenerator typeInfoGenerator, MessageBundle messageBundle, InterfaceMappingStrategy interfaceStrategy, ScalarDeserializationStrategy scalarStrategy, TypeTransformer typeTransformer, AbstractInputHandler abstractInputHandler, InputFieldBuilderRegistry inputFieldBuilders, ResolverInterceptorFactory interceptorFactory, DirectiveBuilder directiveBuilder, InclusionStrategy inclusionStrategy, RelayMappingConfig relayMappingConfig, Collection<GraphQLNamedType> knownTypes, List<AnnotatedType> additionalDirectives, Comparator<AnnotatedType> typeComparator, ImplementationDiscoveryStrategy implementationStrategy, GraphQLCodeRegistry.Builder codeRegistry) { this.operationRegistry = operationRegistry; this.typeRegistry = environment.typeRegistry; this.transformers = transformers; this.interceptorFactory = interceptorFactory; this.directiveBuilder = directiveBuilder; this.typeCache = new TypeCache(knownTypes); this.additionalDirectives = additionalDirectives; this.typeMappers = typeMappers; this.typeInfoGenerator = typeInfoGenerator; this.messageBundle = messageBundle; this.relay = environment.relay; this.node = knownTypes.stream() .filter(GraphQLUtils::isRelayNodeInterface) .findFirst().map(type -> (GraphQLInterfaceType) type) .orElse(relay.nodeInterface(new RelayNodeTypeResolver(this.typeRegistry, typeInfoGenerator, messageBundle))); this.typeResolver = new DelegatingTypeResolver(this.typeRegistry, typeInfoGenerator, messageBundle); this.interfaceStrategy = interfaceStrategy; this.basePackages = basePackages; this.valueMapperFactory = valueMapperFactory; this.inputFieldBuilders = inputFieldBuilders; this.inclusionStrategy = inclusionStrategy; this.scalarStrategy = scalarStrategy; this.typeTransformer = typeTransformer; this.implDiscoveryStrategy = implementationStrategy; this.abstractInputHandler = abstractInputHandler; this.globalEnvironment = environment; this.relayMappingConfig = relayMappingConfig; this.classFinder = new ClassFinder(); this.validator = new Validator(environment, typeMappers, knownTypes, typeComparator); this.codeRegistry = codeRegistry; this.postBuildHooks = new ArrayList<>(Collections.singletonList(context -> classFinder.close())); }
Example #22
Source File: InterfaceMapper.java From graphql-spqr with Apache License 2.0 | 4 votes |
private void registerImplementations(AnnotatedType javaType, GraphQLInterfaceType type, TypeMappingEnvironment env) { BuildContext buildContext = env.buildContext; buildContext.implDiscoveryStrategy.findImplementations(javaType, isImplementationAutoDiscoveryEnabled(javaType), getScanPackages(javaType), buildContext) .forEach(impl -> getImplementingType(impl, env) .ifPresent(implType -> buildContext.typeRegistry.registerDiscoveredCovariantType(type.getName(), impl, implType))); }
Example #23
Source File: Types.java From spring-boot-starter-graphql with Apache License 2.0 | 4 votes |
public static GraphQLInterfaceType.Builder interfaceTypeBuilder () { return new GraphQLInterfaceType.Builder (); }
Example #24
Source File: ProtoToGql.java From rejoiner with Apache License 2.0 | 4 votes |
static GraphQLObjectType convert( Descriptor descriptor, GraphQLInterfaceType nodeInterface, SchemaOptions schemaOptions) { ImmutableList<GraphQLFieldDefinition> graphQLFieldDefinitions = descriptor.getFields().stream() .map(field -> ProtoToGql.convertField(field, schemaOptions)) .collect(toImmutableList()); // TODO: add back relay support // Optional<GraphQLFieldDefinition> relayId = // descriptor.getFields().stream() // .filter(field -> field.getOptions().hasExtension(RelayOptionsProto.relayOptions)) // .map( // field -> // 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)) .description(schemaOptions.commentsMap().get(descriptor.getFullName())) .fields(graphQLFieldDefinitions.isEmpty() ? STATIC_FIELD : graphQLFieldDefinitions) .build(); }
Example #25
Source File: WrappingTypeGenerator.java From graphql-java-type-generator with MIT License | 4 votes |
@Override protected GraphQLInterfaceType generateInterfaceType(Object object) { return getNextGen().generateInterfaceType(object); }
Example #26
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 4 votes |
GraphQLInterfaceType getRelayNode() { return nodeInterface; }
Example #27
Source File: TypeGenerator.java From graphql-java-type-generator with MIT License | 4 votes |
protected GraphQLInterfaceType[] getInterfaces(Object object) { return getStrategies().getInterfacesStrategy().getInterfaces(object); }
Example #28
Source File: InterfacesStrategy.java From graphql-java-type-generator with MIT License | 2 votes |
/** * Should return all interfaces, including those from superclasses * and from superinterfaces. * @param object an object representing a java class, but not itself an interface. * @return */ GraphQLInterfaceType[] getInterfaces(Object object);
Example #29
Source File: ITypeGenerator.java From graphql-java-type-generator with MIT License | 2 votes |
/** * @param object A representative "object" from which to construct * a {@link GraphQLInterfaceType}, the exact type of which is contextual * @return */ GraphQLInterfaceType getInterfaceType(Object object);
Example #30
Source File: TypeGenerator.java From graphql-java-type-generator with MIT License | 2 votes |
/** * @param object A representative "object" from which to construct * a {@link GraphQLInterfaceType}, the exact type of which is contextual, * but MUST represent a java interface, NOT an object or class with an interface. * Will be stored internally as a {@link GraphQLOutputType}, so its name * must not clash with any GraphQLOutputType. * * @return */ @Override public final GraphQLInterfaceType getInterfaceType(Object object) { return (GraphQLInterfaceType) getParameterizedType(object, null, TypeKind.INTERFACE); }