Setup and Configuration
This section describes how to include the GraphQL viewer’s module and set its configuration properties.
Maven pom.xml
Dependency Management
If your application inherits from the Apache Causeway starter app (org.apache.causeway.app:causeway-app-starter-parent
) then that will define the version automatically:
<parent>
<groupId>org.apache.causeway.app</groupId>
<artifactId>causeway-app-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/>
</parent>
Alternatively, import the core BOM. This is usually done in the top-level parent pom of your application:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.causeway.core</groupId>
<artifactId>causeway-core</artifactId>
<version>3.1.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
Update AppManifest
In your application’s AppManifest
(top-level Spring @Configuration
used to bootstrap the app), import the
@Configuration
@Import({
...
CausewayModuleViewerGraphQlViewer.class,
...
})
public class AppManifest {
}
Configuration Properties
The configuration properties for the GraphQL viewer fall into a number of categories.
(To make this section easier to read, the causeway.viewer.graphql.
prefix of all of these configuration properties is omitted).
API variant and Schema Style
The most important configuration properties are:
-
Whether to support relaxed (but non-spec compliant) queries with mutations, or instead to expose an API that is query only.
-
Whether to include all domain classes in the GraphQL schema (entities and view models), or whether only to include view models. Which to use depends upon whether the GraphQL client is owned by the same team the owns the backend application.
-
Whether to use the "simple" schema style (data only, client-driven), the "rich" schema style (includes supporting facets, server-driven) or both schema styles.
These were discussed on the main page for GraphQL viewer.
Customizing the Schema
A number of other configuration properties can customize the schema in various ways. Normally these can be left as their default:
-
schema.simple.top-level-field-name
If using the
SIMPLE_AND_RICH
orRICH_AND_SIMPLE
schema styles, this configuration defines the name of the top-level field that holds the rest of the simple schema.It defaults to “simple”.
-
schema.rich.top-level-field-name
If using the
SIMPLE_AND_RICH
orRICH_AND_SIMPLE
schema styles, this configuration defines the name of the top-level field that holds the rest of the rich schema.It defaults to “rich”.
-
Defines the field name of the "meta data" structure used to expose the id, logical type name and (for entities) the version of a domain object.
The default value for this config property is “_meta”.
The schema to look up a domain object can also be customized:
-
This is the name of the synthetic first argument used to locate the object to be looked up.
It defaults to “object”.
-
Whether to prefix the field name of the domain object’s type.
This defaults to an empty string, in other words no prefix.
-
Whether to add a suffix to the field name of the domain object’s type.
This defaults to an empty string, in other words no suffix.
If executing a mutation rather than a query:
-
This is the name of the synthetic first argument used to locate the object to be mutated.
It defaults to “_target”.
The remaining configuration properties are explained in more detail elsewhere:
-
Control whether the Resource controller is enabled
-
schema.rich.enable-scenario-testing
Enable scenario testing.
-
authentication.fallback.username and authentication.fallback.roles
Are used by the default UserMementoProvider for authentication.
Marshalling SPI:
-
zoned-date-time-format, scalar-marshaller.local-date-format and scalar-marshaller.local-time-format
specify the format that dates and times should be specified as strings, eg “yyyy-MM-dd”.