Approaches to defining a custom GraphQL Schema
You can approach the definition of a custom schema in two ways. The first approach, adding a custom method to the Query type, only allows you to fetch JSON content, no other fields, and restricts you to using predefined parameters for search. The second approach, implementing the Content interface, allows you to use existing GraphQL methods and transform the JSON returned to return into smaller and more efficient JSON, rather than returning all JSON as untyped content.
-
Approach 1: Adding a custom method to the
Querytype -
In your custom schema, find the
type Querysection, which reads as follows:type Query { getCpContent(namespaceId: Int! publicationId: Int! componentId: Int! templateId: Int) : CdContent @dataProvider(dataSource: pipelineComponentPresentation) } -
Approach 2: Implementing the
Contentinterface -
This approach requires you to use the custom data type in all existing GraphQL methods instead of
UntypedContent. To use this approach, in your custom schema, add two sections, one for yourContentimplementation (here calledArticleContent), and another to define the custom data type (here calledArticleContentBody):type ArticleContent implements Content { id: ID implementationName: String @typeName type: String @source(path: "$.$type") data: ArticleContentBody } type ArticleContentBody { type: String info: String @source(path: "$.Regions[0].ComponentPresentations[0].Component.Title") }