close

Filter

loading table of contents...

Headless Server Developer Manual / Version 2101

Table Of Contents

4.6 Adapter

An Adapter can be used to enhance domain model objects with

  • Business logic from blueprint-base
  • Aggregation, Recomposition
  • Fallbacks

An Adapter is defined as Spring Bean and can be accessed from the GraphQL schema.

There are several predefined Adapters in the Headless Server, that can be accessed in the GraphQL schema.

For example, to access the settings of a content object, the SettingsAdapter can be used.

The StructAdapter provides access to values in structs. The Adapter expects a name of the struct which is to be accessed and a list specifying the path including the property to be found. This list shouldn't contain the name of the struct. Additionally, it is possible to provide a default value which is used in case the struct value wasn't found.

      type CMSettingsImpl implements CMSettings ... {
  settings(paths: [[String]]): JSON @fetch(from: "#paths == null ? #this.settings : @structAdapter.to(#root).getWrappedInStruct('settings',#paths, null)")
}

    

Example 4.3. Retrieve a value from a struct with the StructAdapter


The SettingsAdapter provides functionality to retrieve settings via the SettingsService from blueprint-base packages. By doing so, it can find local and linked settings on content objects. The SettingsAdapter covers a specific case of values in a Struct. Inheritance of settings is not supported at the moment.

      settings(paths: "commerce")

settings(paths: ["commerce"])

settings(paths: [["commerce"]])

settings(paths: ["commerce","endpoint"])

settings(paths: [["commerce","endpoint"],["commerce","locale"]])

    

Example 4.4. Different ways to pass the paths parameter to the settings field from the GraphQL perspective


      
@Bean
public SettingsAdapterFactory settingsAdapter(@Qualifier("settingsService") SettingsService settingsService) {
  return new SettingsAdapterFactory(settingsService);
}

    

Example 4.5. Define SettingsAdapter as bean


      
type CMTeasableImpl implements CMTeasable ... {
  customSetting: String @fetch(from:
    "{!@settingsAdapter.to(#root).get({'customSetting'},'')}")
}

    

Example 4.6. Retrieve settings with the SettingsAdapter


There are several Adapters available, for example:

structAdapter

Retrieve values from a Struct at a content object.

responsiveMediaAdapter

Retrieve the crops for a Picture.

mediaLinkListAdapter

Retrieve the media for a content object, for example, picture(s), video(s).

pageGridAdapter

Retrieve the pagegrid.

imageMapAdapter

Retrieve image maps.

navigationAdapter

Retrieve the navigation context.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.