Class InterfaceType
java.lang.Object
com.graphql_java_generator.plugin.language.impl.AbstractType
com.graphql_java_generator.plugin.language.impl.ObjectType
com.graphql_java_generator.plugin.language.impl.InterfaceType
- All Implemented Interfaces:
Type
This class represents an Interface, as defined in a GraphQL schema. In the generated classes, this needs to be an
interface, as an object type may implement several interfaces. One of the issue to face, when generating the POJOs,
is that we may have to instanciate an instance of this interface. For instance, in this GraphQL schema:
To solve this, a GraphQL interface declaration let to two java files:
interface Character { id: ID! name: String! } type Human implements Character { id: ID! name: String! friends: [Character]! } type Droid implements Character { id: ID! name: String! primaryFunction: String! }If you get a Human from a query, it will return its friends. But when returning it, you'll only get the its id and name. The mapper has to instanciate a POJO, but this POJO can't be a Human, nor a Droid.
To solve this, a GraphQL interface declaration let to two java files:
- The interface itself. In the above case, the interface is named Character, as defined in the GraphQL schema.
- A concrete Java class, implementing the interface itself, and only it. In the above case, the interface would be named CharacterImpl, a name derived from the interface named defined in the GraphQL schema. In the case where this name is an already defined type in the GraphQL schema, the generator will search for non used alternative names (CharacterImpl1, CharacterImpl2...)
- Author:
- etienne-sf
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.graphql_java_generator.plugin.language.Type
Type.GraphQlType, Type.TargetFileType
-
Constructor Summary
ConstructorDescriptionInterfaceType
(String name, CommonConfiguration configuration, DocumentParser documentParser) -
Method Summary
Methods inherited from class com.graphql_java_generator.plugin.language.impl.ObjectType
getIdentifier, getImplementedTypes, getPackageName, getRequestTypePascalCase, isCustomScalar, isScalar
Methods inherited from class com.graphql_java_generator.plugin.language.impl.AbstractType
addAnnotation, addAnnotation, addImport, addImportForUtilityClasses, getAnnotation, getCamelCaseName, getClassSimpleName, getGraphQlType, getJavaName, setAnnotation, setComments
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.graphql_java_generator.plugin.language.Type
getAppliedDirectives, getClassFullName, getComments, getDataFetcher, getDescription, getField, getFields, getImports, getImportsForUtilityClasses, getName, getRequestType, getTargetFileName, isEnum, isInputType
-
Constructor Details
-
InterfaceType
- Parameters:
name
- the name for this typeconfiguration
- The current plugin configuration, which is accessible through an interface that extendsCommonConfiguration
documentParser
- TheDocumentParser
that has parsed the schema, and so that contains the whole schema definition
-
-
Method Details
-
getPrefix
- Overrides:
getPrefix
in classObjectType
-
getSuffix
- Overrides:
getSuffix
in classObjectType
-
toString
- Overrides:
toString
in classObjectType
-