Skip to content

Commit 0dccb22

Browse files
authored
Merge pull request #60 from roycornelissen/feature/fix-cdn-queries
🐛 Fix support for queries with parameters against CDN endpoint
2 parents 069fc7b + 286a7ea commit 0dccb22

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

src/Sanity.Linq/Sanity.Linq.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This file is part of Sanity LINQ (https://github.com/oslofjord/sanity-linq).
2626
<Authors>Oslofjord Operations AS</Authors>
2727
<Company>Oslofjord Operations AS</Company>
2828
<Product>Sanity LINQ</Product>
29-
<Version>1.5.0</Version>
29+
<Version>1.6.0</Version>
3030
<Description>Strongly-typed .Net Client for Sanity CMS (https://sanity.io)</Description>
3131
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
3232
<Copyright>2018 Oslofjord Operations AS</Copyright>
@@ -35,11 +35,11 @@ This file is part of Sanity LINQ (https://github.com/oslofjord/sanity-linq).
3535
<RepositoryType>git</RepositoryType>
3636
<PackageTags>sanity cms dotnet linq client groq</PackageTags>
3737
<PackageLicenseUrl>https://raw.githubusercontent.com/oslofjord/sanity-linq/master/LICENSE</PackageLicenseUrl>
38-
<AssemblyVersion>1.5.0.0</AssemblyVersion>
38+
<AssemblyVersion>1.6.0.0</AssemblyVersion>
3939
<PackageId>Sanity.Linq</PackageId>
4040
<AssemblyName>Sanity.Linq</AssemblyName>
4141
<RootNamespace>Sanity.Linq</RootNamespace>
42-
<FileVersion>1.5.0.0</FileVersion>
42+
<FileVersion>1.6.0.0</FileVersion>
4343
<PackageReleaseNotes>1.0 - Sanity Linq library
4444
1.1 - BlockContent library
4545
1.1.1 - Improvements BlockContent
@@ -60,6 +60,7 @@ This file is part of Sanity LINQ (https://github.com/oslofjord/sanity-linq).
6060
1.4.4 - SanityFile type added
6161
1.4.5 - Added support for choosing API-version
6262
1.5.0 - Updated dependencies and support for source link, some serialization fixes
63+
1.6.0 - Fixed support for queries with parameters against the CDN endpoint
6364
</PackageReleaseNotes>
6465

6566
<PublishRepositoryUrl>true</PublishRepositoryUrl>

src/Sanity.Linq/SanityClient.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public virtual void Initialize()
7171
{
7272
_httpQueryClient.BaseAddress = new Uri($"https://{WebUtility.UrlEncode(_options.ProjectId)}.api.sanity.io/{_options.ApiVersion}/");
7373
}
74-
if (!string.IsNullOrEmpty(_options.Token) && !_options.UseCdn)
74+
if (!string.IsNullOrEmpty(_options.Token))
7575
{
7676
_httpQueryClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _options.Token);
7777
}
@@ -92,7 +92,6 @@ public virtual void Initialize()
9292
_httpQueryClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _options.Token);
9393
}
9494
}
95-
9695
}
9796

9897
public virtual async Task<SanityQueryResponse<TResult>> FetchAsync<TResult>(string query, object parameters = null, CancellationToken cancellationToken = default)
@@ -106,23 +105,8 @@ public virtual async Task<SanityQueryResponse<TResult>> FetchAsync<TResult>(stri
106105
Query = query,
107106
Params = parameters
108107
};
109-
HttpResponseMessage response = null;
110-
if (_options.UseCdn)
111-
{
112-
// CDN only supports GET requests
113-
var url = $"data/query/{WebUtility.UrlEncode(_options.Dataset)}?query={WebUtility.UrlEncode(query ?? "")}";
114-
if (parameters != null)
115-
{
116-
//TODO: Add support for parameters
117-
}
118-
response = await _httpQueryClient.GetAsync(url, cancellationToken);
119-
}
120-
else
121-
{
122-
// Preferred method is POST
123-
var json = new StringContent(JsonConvert.SerializeObject(oQuery, Formatting.None, SerializerSettings), Encoding.UTF8, "application/json");
124-
response = await _httpQueryClient.PostAsync($"data/query/{WebUtility.UrlEncode(_options.Dataset)}", json, cancellationToken).ConfigureAwait(false);
125-
}
108+
var json = new StringContent(JsonConvert.SerializeObject(oQuery, Formatting.None, SerializerSettings), Encoding.UTF8, "application/json");
109+
HttpResponseMessage response = await _httpQueryClient.PostAsync($"data/query/{WebUtility.UrlEncode(_options.Dataset)}", json, cancellationToken).ConfigureAwait(false);
126110

127111
return await HandleHttpResponseAsync<SanityQueryResponse<TResult>>(response).ConfigureAwait(false);
128112
}

tests/Sanity.Linq.Tests/Sanity.Linq.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
15-
<PackageReference Include="xunit" Version="2.4.1" />
16-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
15+
<PackageReference Include="xunit" Version="2.4.2" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>

0 commit comments

Comments
 (0)