Skip to content

Commit 13b7c87

Browse files
committed
Installed StrawberryShake, it's dotnet graphql tools, used dotnet graphql init to create the graphqlrc.json and schema files. Added a search query. Removed FIND.
1 parent 193f69a commit 13b7c87

10 files changed

Lines changed: 1928 additions & 13 deletions

.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"strawberryshake.tools": {
6+
"version": "15.1.11",
7+
"commands": [
8+
"dotnet-graphql"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

.graphqlrc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"schema": "schema.graphql",
3+
"documents": "**/*.graphql",
4+
"extensions": {
5+
"strawberryShake": {
6+
"name": "GraphQLClient",
7+
"url": "https://cg.optimizely.com/content/v2?auth=n3nCUREbvDHzkajZjLZmuY1KtS4bR5RhlgXXsnEslceIxnRG",
8+
"records": {
9+
"inputs": false,
10+
"entities": false
11+
},
12+
"transportProfiles": [
13+
{
14+
"default": "Http",
15+
"subscription": "WebSocket"
16+
}
17+
]
18+
}
19+
}
20+
}

Articles.graphql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
query articles($query: String) {
2+
ArticlePage(where: { _fulltext: { match: $query } }) {
3+
items {
4+
Body {
5+
html
6+
}
7+
}
8+
}
9+
}

Controllers/SearchPageController.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
using EPiServer.Find;
2-
using EPiServer.Find.Cms;
31
using EPiServer.Web.Mvc;
42
using FindToGraph.Models;
53
using Microsoft.AspNetCore.Mvc;
64
using System.Collections.Generic;
75
using System.Linq;
6+
using System.Threading.Tasks;
87
using FindToGraph.Extensions;
8+
using StrawberryShake;
9+
910

1011
namespace FindToGraph.Controllers
1112
{
1213
public class SearchPageController : PageController<SearchPage>
1314
{
14-
private readonly IClient _searchClient;
15+
private readonly IGraphQLClient _searchClient;
1516

16-
public SearchPageController(IClient findClient)
17+
public SearchPageController(IGraphQLClient graphClient)
1718
{
18-
_searchClient = findClient;
19+
_searchClient = graphClient;
1920
}
2021

21-
public IActionResult Index(SearchPage currentPage, string? q)
22+
public async Task<IActionResult> Index(SearchPage currentPage, string? q)
2223
{
2324
List<string> results = new List<string>();
2425
if (!string.IsNullOrWhiteSpace(q))
2526
{
26-
var searchResults = _searchClient.Search<ArticlePage>()
27-
.For(q).GetContentResult();
28-
29-
results = searchResults.Select(hit => hit.Body?.ToHtmlString().StripParagraphTags() ?? "No content").ToList();
27+
var searchResult = await _searchClient.Articles.ExecuteAsync(q);
28+
searchResult.EnsureNoErrors();
29+
var items = searchResult.Data?.ArticlePage?.Items;
30+
if (items != null) {
31+
results = items.Select(item => item?.Body?.Html?.StripParagraphTags() ?? "No content").ToList();
32+
}
3033
}
34+
3135
ViewBag.Query = q;
3236
ViewBag.Results = results;
3337
return View(currentPage);

FindToGraph.csproj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="EPiServer.CMS" Version="12.34.1" />
17-
<PackageReference Include="EPiServer.Find.Cms" Version="16.6.0" />
1817
<PackageReference Include="Optimizely.ContentGraph.Cms" Version="4.1.1" />
18+
<PackageReference Include="StrawberryShake.Server" Version="15.1.11" />
1919
</ItemGroup>
2020

2121
<ItemGroup>
2222
<EmbeddedResource Include="Resources\Translations\**\*" />
2323
</ItemGroup>
24+
25+
<ItemGroup>
26+
<Compile Remove="GraphQLClient\**" />
27+
<Content Remove="GraphQLClient\**" />
28+
<EmbeddedResource Remove="GraphQLClient\**" />
29+
<GraphQL Remove="GraphQLClient\**" />
30+
<None Remove="GraphQLClient\**" />
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<EmbeddedResource Include="Articles.graphql" />
35+
<EmbeddedResource Include="schema.extensions.graphql" />
36+
<EmbeddedResource Include="schema.graphql" />
37+
</ItemGroup>
2438
</Project>

FindToGraph.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36623.8 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FindToGraph", "FindToGraph.csproj", "{76D90868-282F-1736-7497-D28C364A289F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{76D90868-282F-1736-7497-D28C364A289F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{76D90868-282F-1736-7497-D28C364A289F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{76D90868-282F-1736-7497-D28C364A289F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{76D90868-282F-1736-7497-D28C364A289F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {7927BEE4-01A7-46B1-BA9B-52167BB19EA5}
24+
EndGlobalSection
25+
EndGlobal

Models/ArticlePage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace FindToGraph.Models
66
[ContentType(DisplayName = "ArticlePage", GUID = "a1b2c3d4-e5f6-7890-abcd-ef1234567890", Description = "Article page with body content")]
77
public class ArticlePage : PageData
88
{
9+
[Searchable]
910
public virtual XhtmlString? Body { get; set; }
1011
}
1112
}

Startup.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using EPiServer.Cms.Shell;
22
using EPiServer.Cms.UI.AspNetIdentity;
33
using EPiServer.DependencyInjection;
4-
using EPiServer.Find.Cms;
54
using EPiServer.Scheduler;
65
using EPiServer.ServiceLocation;
76
using EPiServer.Web.Routing;
7+
using StrawberryShake;
88

99
namespace FindToGraph;
1010

@@ -30,11 +30,12 @@ public void ConfigureServices(IServiceCollection services)
3030
.AddCmsAspNetIdentity<ApplicationUser>()
3131
.AddCms()
3232
.AddAdminUserRegistration()
33-
.AddFind()
3433
.AddEmbeddedLocalization<Startup>();
3534

3635
services.AddContentDeliveryApi();
3736
services.AddContentGraph();
37+
services.AddGraphQLClient().ConfigureHttpClient(c => c.BaseAddress = new Uri("https://cg.optimizely.com/content/v2?auth=n3nCUREbvDHzkajZjLZmuY1KtS4bR5RhlgXXsnEslceIxnRG"));
38+
3839
}
3940

4041
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

schema.extensions.graphql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
scalar _KeyFieldSet
2+
3+
directive @key(fields: _KeyFieldSet!) on SCHEMA | OBJECT
4+
5+
directive @serializationType(name: String!) on SCALAR
6+
7+
directive @runtimeType(name: String!) on SCALAR
8+
9+
directive @enumValue(value: String!) on ENUM_VALUE
10+
11+
directive @rename(name: String!) on INPUT_FIELD_DEFINITION | INPUT_OBJECT | ENUM | ENUM_VALUE
12+
13+
extend schema @key(fields: "id")

0 commit comments

Comments
 (0)