Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. import { Component, OnInit, Input } from '@angular/core';
  2. import { ComponentRendering } from '@sitecore-jss/sitecore-jss-angular';
  3. import { ApolloQueryResult } from 'apollo-client';
  4. import { DocumentNode } from 'graphql';
  5. import { JssGraphQLService } from '../../jss-graphql.service';
  6. import { Observable } from 'rxjs';
  7.  
  8. const ComponentQuery: DocumentNode = require('graphql-tag/loader!./heroes-connected.component.graphql');
  9.  
  10.  
  11. @Component({
  12. selector: 'app-heroes',
  13. templateUrl: './heroes-connected.component.html',
  14. styleUrls: ['./heroes-connected.component.css']
  15. })
  16.  
  17. export class HeroesConnectedComponent implements OnInit {
  18. @Input() rendering: ComponentRendering;
  19. query$: Observable<ApolloQueryResult<any>>;
  20.  
  21. constructor(private graphQLService: JssGraphQLService) { }
  22.  
  23. ngOnInit() {
  24.  
  25. this.query$ = this.graphQLService.query({
  26. query: ComponentQuery
  27. });
  28.  
  29. }
  30. }
  31.  
  32. query myquery {
  33. search(fieldsEqual: [{name: "_templatename", value: "hero*"}], rootItem: "/sitecore/content/") {
  34. results {
  35. items {
  36. item {
  37. ... on Hero {
  38. id
  39. name
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46.  
  47. {
  48. "data": {
  49. "search": {
  50. "results": {
  51. "items": [
  52. {
  53. "item": {
  54. "id": "7760B9378E114B7F9912E3EF65D8A622",
  55. "name": "Ouiame"
  56. }
  57. },
  58. {
  59. "item": {
  60. "id": "B937D81BA6A25BAEBBD814DB047D6A90",
  61. "name": "Arnaud"
  62. }
  63. },
  64. {
  65. "item": {
  66. "id": "3AF3733F5DF44ABCB41CF39EAD367D0F",
  67. "name": "Flora"
  68. }
  69. },
  70. {
  71. "item": {
  72. "id": "90BC52778C13471E9E5CCB77D687B2A0",
  73. "name": "Celine"
  74. }
  75. },
  76. {
  77. "item": {
  78. "id": "550F86ACCAF64BD2B31BE7F567FE2C19",
  79. "name": "Julie"
  80. }
  81. },
  82. {
  83. "item": {
  84. "id": "36ECD568914F4C55B80E5B38059F5C43",
  85. "name": "Ramdane"
  86. }
  87. },
  88. {
  89. "item": {
  90. "id": "88FB51A58FB95C6DA812B845B87152E4",
  91. "name": "Reana"
  92. }
  93. }
  94. ]
  95. }
  96. }
  97. }
  98. }
  99.  
  100. Error: GraphQL error: Cannot query field "search" on type "Query"
  101.  
  102. type Query {
  103. item(path: String, language: String, version: Int): Item
  104. sites(name: String = "", current: Boolean = false, includeSystemSites: Boolean = false): [SiteGraphType]
  105. templates(path: String): [ItemTemplate]
  106. search(first: Int, after: String = 0, rootItem: String, keyword: String, language: String, latestVersion: Boolean = true, index: String, fieldsEqual: [ItemSearchFieldQuery], facetOn: [String!]): ContentSearchResults
  107. }
  108.  
  109. <queries hint="raw:AddQuery">
  110. <query name="item" type="Sitecore.Services.GraphQL.Content.Queries.ItemQuery, Sitecore.Services.GraphQL.Content"/>
  111. <query name="sites" type="Sitecore.Services.GraphQL.Content.Queries.SiteQuery, Sitecore.Services.GraphQL.Content"/>
  112. <query name="templates" type="Sitecore.Services.GraphQL.Content.Queries.TemplatesQuery, Sitecore.Services.GraphQL.Content"/>
  113. <query name="search" type="Sitecore.Services.GraphQL.Content.Queries.SearchQuery, Sitecore.Services.GraphQL.Content"/>
  114. </queries>
  115.  
  116. <app name="angular-app"
  117. sitecorePath="/sitecore/content/angular-app"
  118. inherits="defaults"
  119. useLanguageSpecificLayout="true"
  120. graphQLEndpoint="/api/angular-app"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement