Skip to content

Commit b356539

Browse files
committed
update nuget packages and graphql example
1 parent fdad2bb commit b356539

File tree

8 files changed

+159
-154
lines changed

8 files changed

+159
-154
lines changed

samples/OcelotGraphQL/OcelotGraphQL.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
</ItemGroup>
1313
<ItemGroup>
1414
<PackageReference Include="Ocelot" Version="14.0.9" />
15-
<PackageReference Include="GraphQL" Version="2.4.0" />
15+
<PackageReference Include="GraphQL" Version="3.1.5" />
1616
</ItemGroup>
1717
</Project>

samples/OcelotGraphQL/Program.cs

Lines changed: 134 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,138 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
7-
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
10-
using Ocelot.Middleware;
11-
using Ocelot.DependencyInjection;
12-
using GraphQL.Types;
13-
using GraphQL;
14-
using Ocelot.Requester;
15-
using Ocelot.Responses;
16-
using System.Net.Http;
17-
using System.Net;
18-
using Microsoft.Extensions.DependencyInjection;
19-
using System.Threading;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
using Ocelot.Middleware;
11+
using Ocelot.DependencyInjection;
12+
using GraphQL.Types;
13+
using GraphQL;
14+
using Ocelot.Requester;
15+
using Ocelot.Responses;
16+
using System.Net.Http;
17+
using System.Net;
18+
using Microsoft.Extensions.DependencyInjection;
19+
using System.Threading;
20+
21+
namespace OcelotGraphQL
22+
{
23+
public class Hero
24+
{
25+
public int Id { get; set; }
26+
public string Name { get; set; }
27+
}
28+
29+
public class Query
30+
{
31+
private readonly List<Hero> _heroes = new List<Hero>
32+
{
33+
new Hero { Id = 1, Name = "R2-D2" },
34+
new Hero { Id = 2, Name = "Batman" },
35+
new Hero { Id = 3, Name = "Wonder Woman" },
36+
new Hero { Id = 4, Name = "Tom Pallister" }
37+
};
38+
39+
[GraphQLMetadata("hero")]
40+
public Hero GetHero(int id)
41+
{
42+
return _heroes.FirstOrDefault(x => x.Id == id);
43+
}
44+
}
45+
46+
public class GraphQlDelegatingHandler : DelegatingHandler
47+
{
48+
//private readonly ISchema _schema;
49+
private readonly IDocumentExecuter _executer;
50+
private readonly IDocumentWriter _writer;
51+
52+
public GraphQlDelegatingHandler(IDocumentExecuter executer, IDocumentWriter writer)
53+
{
54+
_executer = executer;
55+
_writer = writer;
56+
}
57+
58+
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
59+
{
60+
//try get query from body, could check http method :)
61+
var query = await request.Content.ReadAsStringAsync();
62+
63+
//if not body try query string, dont hack like this in real world..
64+
if (query.Length == 0)
65+
{
66+
var decoded = WebUtility.UrlDecode(request.RequestUri.Query);
67+
query = decoded.Replace("?query=", "");
68+
}
2069

21-
namespace OcelotGraphQL
22-
{
23-
public class Hero
24-
{
25-
public int Id { get; set; }
26-
public string Name { get; set; }
27-
}
28-
29-
public class Query
30-
{
31-
private readonly List<Hero> _heroes = new List<Hero>
32-
{
33-
new Hero { Id = 1, Name = "R2-D2" },
34-
new Hero { Id = 2, Name = "Batman" },
35-
new Hero { Id = 3, Name = "Wonder Woman" },
36-
new Hero { Id = 4, Name = "Tom Pallister" }
37-
};
38-
39-
[GraphQLMetadata("hero")]
40-
public Hero GetHero(int id)
41-
{
42-
return _heroes.FirstOrDefault(x => x.Id == id);
43-
}
44-
}
45-
46-
public class GraphQlDelegatingHandler : DelegatingHandler
47-
{
48-
private readonly ISchema _schema;
49-
50-
public GraphQlDelegatingHandler(ISchema schema)
51-
{
52-
_schema = schema;
53-
}
54-
55-
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
56-
{
57-
//try get query from body, could check http method :)
58-
var query = await request.Content.ReadAsStringAsync();
59-
60-
//if not body try query string, dont hack like this in real world..
61-
if (query.Length == 0)
62-
{
63-
var decoded = WebUtility.UrlDecode(request.RequestUri.Query);
64-
query = decoded.Replace("?query=", "");
65-
}
66-
67-
var result = _schema.Execute(_ =>
68-
{
69-
_.Query = query;
70+
var result = await _executer.ExecuteAsync(_ =>
71+
{
72+
_.Query = query;
7073
});
7174

72-
//maybe check for errors and headers etc in real world?
73-
var response = new HttpResponseMessage(HttpStatusCode.OK)
74-
{
75-
Content = new StringContent(result)
76-
};
77-
78-
//ocelot will treat this like any other http request...
79-
return response;
80-
}
81-
}
82-
83-
public class Program
84-
{
85-
public static void Main()
86-
{
87-
var schema = Schema.For(@"
88-
type Hero {
89-
id: Int
90-
name: String
91-
}
92-
93-
type Query {
94-
hero(id: Int): Hero
95-
}
96-
", _ =>
97-
{
98-
_.Types.Include<Query>();
99-
});
75+
var responseBody = await _writer.WriteToStringAsync(result);
10076

101-
new WebHostBuilder()
102-
.UseKestrel()
103-
.UseContentRoot(Directory.GetCurrentDirectory())
104-
.ConfigureAppConfiguration((hostingContext, config) =>
105-
{
106-
config
107-
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
108-
.AddJsonFile("appsettings.json", true, true)
109-
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
110-
.AddJsonFile("ocelot.json", false, false)
111-
.AddEnvironmentVariables();
112-
})
113-
.ConfigureServices(s =>
114-
{
115-
s.AddSingleton<ISchema>(schema);
116-
s.AddOcelot()
117-
.AddDelegatingHandler<GraphQlDelegatingHandler>();
118-
})
119-
.ConfigureLogging((hostingContext, logging) =>
120-
{
121-
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
122-
logging.AddConsole();
123-
})
124-
.UseIISIntegration()
125-
.Configure(app =>
126-
{
127-
app.UseOcelot().Wait();
128-
})
129-
.Build()
130-
.Run();
131-
}
132-
}
133-
}
77+
//maybe check for errors and headers etc in real world?
78+
var response = new HttpResponseMessage(HttpStatusCode.OK)
79+
{
80+
Content = new StringContent(responseBody)
81+
};
82+
83+
//ocelot will treat this like any other http request...
84+
return response;
85+
}
86+
}
87+
88+
public class Program
89+
{
90+
public static void Main()
91+
{
92+
var schema = Schema.For(@"
93+
type Hero {
94+
id: Int
95+
name: String
96+
}
97+
98+
type Query {
99+
hero(id: Int): Hero
100+
}
101+
", _ =>
102+
{
103+
_.Types.Include<Query>();
104+
});
105+
106+
new WebHostBuilder()
107+
.UseKestrel()
108+
.UseContentRoot(Directory.GetCurrentDirectory())
109+
.ConfigureAppConfiguration((hostingContext, config) =>
110+
{
111+
config
112+
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
113+
.AddJsonFile("appsettings.json", true, true)
114+
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
115+
.AddJsonFile("ocelot.json", false, false)
116+
.AddEnvironmentVariables();
117+
})
118+
.ConfigureServices(s =>
119+
{
120+
s.AddSingleton<ISchema>(schema);
121+
s.AddOcelot()
122+
.AddDelegatingHandler<GraphQlDelegatingHandler>();
123+
})
124+
.ConfigureLogging((hostingContext, logging) =>
125+
{
126+
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
127+
logging.AddConsole();
128+
})
129+
.UseIISIntegration()
130+
.Configure(app =>
131+
{
132+
app.UseOcelot().Wait();
133+
})
134+
.Build()
135+
.Run();
136+
}
137+
}
138+
}

src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<ProjectReference Include="..\Ocelot\Ocelot.csproj" />
2828
</ItemGroup>
2929
<ItemGroup>
30-
<PackageReference Include="Consul" Version="0.7.2.6" />
30+
<PackageReference Include="Consul" Version="1.6.1.1" />
3131
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
3232
<PrivateAssets>all</PrivateAssets>
3333
</PackageReference>

src/Ocelot/Ocelot.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</PropertyGroup>
2525

2626
<ItemGroup>
27-
<PackageReference Include="FluentValidation" Version="8.6.2" />
27+
<PackageReference Include="FluentValidation" Version="9.3.0" />
2828
<PackageReference Include="Microsoft.AspNetCore.MiddlewareAnalysis" Version="3.1.3" />
2929
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="3.1.3">
3030
<NoWarn>NU1701</NoWarn>

src/Ocelot/Responses/Response.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
using Ocelot.Errors;
2-
using System.Collections.Generic;
3-
4-
namespace Ocelot.Responses
5-
{
6-
public abstract class Response
7-
{
8-
protected Response()
9-
{
10-
Errors = new List<Error>();
11-
}
12-
13-
protected Response(List<Error> errors)
14-
{
15-
Errors = errors ?? new List<Error>();
1+
using Ocelot.Errors;
2+
using System.Collections.Generic;
3+
4+
namespace Ocelot.Responses
5+
{
6+
public abstract class Response
7+
{
8+
protected Response()
9+
{
10+
Errors = new List<Error>();
11+
}
12+
13+
protected Response(List<Error> errors)
14+
{
15+
Errors = errors ?? new List<Error>();
1616
}
1717

18-
public List<Error> Errors { get; }
19-
20-
public bool IsError => Errors.Count > 0;
21-
}
18+
public List<Error> Errors { get; }
19+
20+
public bool IsError => Errors.Count > 0;
21+
}
2222
}

test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" />
6666
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
6767
<PackageReference Include="IdentityServer4" Version="3.1.1" />
68-
<PackageReference Include="Consul" Version="0.7.2.6" />
68+
<PackageReference Include="Consul" Version="1.6.1.1" />
6969
<PackageReference Include="Rafty" Version="0.4.4" />
7070
<PackageReference Include="CacheManager.Microsoft.Extensions.Logging" Version="2.0.0-beta-1629" />
7171
<PackageReference Include="CacheManager.Serialization.Json" Version="2.0.0-beta-1629" />

test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
21+
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
2222
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
2323
<PrivateAssets>all</PrivateAssets>
2424
</PackageReference>

test/Ocelot.UnitTests/Ocelot.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
7676
<PackageReference Include="IdentityServer4" Version="3.1.1" />
7777
<PackageReference Include="Steeltoe.Discovery.ClientCore" Version="2.4.2" />
78-
<PackageReference Include="Consul" Version="0.7.2.6" />
78+
<PackageReference Include="Consul" Version="1.6.1.1" />
7979
<PackageReference Include="CacheManager.Core" Version="2.0.0-beta-1629" />
8080
<PackageReference Include="CacheManager.Microsoft.Extensions.Configuration" Version="2.0.0-beta-1629" />
8181
<PackageReference Include="CacheManager.Microsoft.Extensions.Logging" Version="2.0.0-beta-1629" />

0 commit comments

Comments
 (0)