mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-07-01 20:08:16 +08:00
+semver: upgrade to net5.0 (#1390)
* breaking upgrade base build image to net5.0 * add make and build tools to image * fix code broken after net5.0 upgrade * fix warnings * fix tests and line endings * upgrade dotnet test and coverages packages * update circle build image * removed rafty and updated more packages * bring back develop * rename authorisation to authorization
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
@ -10,4 +10,4 @@
|
||||
<PackageReference Include="Ocelot.Administration" Version="14.0.9" />
|
||||
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -17,7 +17,6 @@ COPY src/Ocelot.Cache.CacheManager/Ocelot.Cache.CacheManager.csproj src/Ocelot.C
|
||||
COPY src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj
|
||||
COPY src/Ocelot.Provider.Eureka/Ocelot.Provider.Eureka.csproj src/Ocelot.Provider.Eureka/Ocelot.Provider.Eureka.csproj
|
||||
COPY src/Ocelot.Provider.Polly/Ocelot.Provider.Polly.csproj src/Ocelot.Provider.Polly/Ocelot.Provider.Polly.csproj
|
||||
COPY src/Ocelot.Provider.Rafty/Ocelot.Provider.Rafty.csproj src/Ocelot.Provider.Rafty/Ocelot.Provider.Rafty.csproj
|
||||
COPY src/Ocelot.Tracing.Butterfly/Ocelot.Tracing.Butterfly.csproj src/Ocelot.Tracing.Butterfly/Ocelot.Tracing.Butterfly.csproj
|
||||
COPY src/Ocelot.Provider.Kubernetes/Ocelot.Provider.Kubernetes.csproj src/Ocelot.Provider.Kubernetes/Ocelot.Provider.Kubernetes.csproj
|
||||
COPY test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Update="ocelot.json;appsettings.json">
|
||||
@ -12,6 +12,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Ocelot" Version="14.0.9" />
|
||||
<PackageReference Include="GraphQL" Version="2.4.0" />
|
||||
<PackageReference Include="GraphQL" Version="3.1.5" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -1,133 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.DependencyInjection;
|
||||
using GraphQL.Types;
|
||||
using GraphQL;
|
||||
using Ocelot.Requester;
|
||||
using Ocelot.Responses;
|
||||
using System.Net.Http;
|
||||
using System.Net;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.DependencyInjection;
|
||||
using GraphQL.Types;
|
||||
using GraphQL;
|
||||
using Ocelot.Requester;
|
||||
using Ocelot.Responses;
|
||||
using System.Net.Http;
|
||||
using System.Net;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading;
|
||||
|
||||
namespace OcelotGraphQL
|
||||
{
|
||||
public class Hero
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class Query
|
||||
{
|
||||
private readonly List<Hero> _heroes = new List<Hero>
|
||||
{
|
||||
new Hero { Id = 1, Name = "R2-D2" },
|
||||
new Hero { Id = 2, Name = "Batman" },
|
||||
new Hero { Id = 3, Name = "Wonder Woman" },
|
||||
new Hero { Id = 4, Name = "Tom Pallister" }
|
||||
};
|
||||
|
||||
[GraphQLMetadata("hero")]
|
||||
public Hero GetHero(int id)
|
||||
{
|
||||
return _heroes.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
|
||||
public class GraphQlDelegatingHandler : DelegatingHandler
|
||||
{
|
||||
//private readonly ISchema _schema;
|
||||
private readonly IDocumentExecuter _executer;
|
||||
private readonly IDocumentWriter _writer;
|
||||
|
||||
public GraphQlDelegatingHandler(IDocumentExecuter executer, IDocumentWriter writer)
|
||||
{
|
||||
_executer = executer;
|
||||
_writer = writer;
|
||||
}
|
||||
|
||||
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
//try get query from body, could check http method :)
|
||||
var query = await request.Content.ReadAsStringAsync();
|
||||
|
||||
//if not body try query string, dont hack like this in real world..
|
||||
if (query.Length == 0)
|
||||
{
|
||||
var decoded = WebUtility.UrlDecode(request.RequestUri.Query);
|
||||
query = decoded.Replace("?query=", "");
|
||||
}
|
||||
|
||||
namespace OcelotGraphQL
|
||||
{
|
||||
public class Hero
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class Query
|
||||
{
|
||||
private readonly List<Hero> _heroes = new List<Hero>
|
||||
{
|
||||
new Hero { Id = 1, Name = "R2-D2" },
|
||||
new Hero { Id = 2, Name = "Batman" },
|
||||
new Hero { Id = 3, Name = "Wonder Woman" },
|
||||
new Hero { Id = 4, Name = "Tom Pallister" }
|
||||
};
|
||||
|
||||
[GraphQLMetadata("hero")]
|
||||
public Hero GetHero(int id)
|
||||
{
|
||||
return _heroes.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
|
||||
public class GraphQlDelegatingHandler : DelegatingHandler
|
||||
{
|
||||
private readonly ISchema _schema;
|
||||
|
||||
public GraphQlDelegatingHandler(ISchema schema)
|
||||
{
|
||||
_schema = schema;
|
||||
}
|
||||
|
||||
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
//try get query from body, could check http method :)
|
||||
var query = await request.Content.ReadAsStringAsync();
|
||||
|
||||
//if not body try query string, dont hack like this in real world..
|
||||
if (query.Length == 0)
|
||||
{
|
||||
var decoded = WebUtility.UrlDecode(request.RequestUri.Query);
|
||||
query = decoded.Replace("?query=", "");
|
||||
}
|
||||
|
||||
var result = _schema.Execute(_ =>
|
||||
{
|
||||
_.Query = query;
|
||||
var result = await _executer.ExecuteAsync(_ =>
|
||||
{
|
||||
_.Query = query;
|
||||
});
|
||||
|
||||
//maybe check for errors and headers etc in real world?
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent(result)
|
||||
};
|
||||
var responseBody = await _writer.WriteToStringAsync(result);
|
||||
|
||||
//ocelot will treat this like any other http request...
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var schema = Schema.For(@"
|
||||
type Hero {
|
||||
id: Int
|
||||
name: String
|
||||
}
|
||||
|
||||
type Query {
|
||||
hero(id: Int): Hero
|
||||
}
|
||||
", _ =>
|
||||
{
|
||||
_.Types.Include<Query>();
|
||||
});
|
||||
|
||||
new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.ConfigureAppConfiguration((hostingContext, config) =>
|
||||
{
|
||||
config
|
||||
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", true, true)
|
||||
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
|
||||
.AddJsonFile("ocelot.json", false, false)
|
||||
.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s =>
|
||||
{
|
||||
s.AddSingleton<ISchema>(schema);
|
||||
s.AddOcelot()
|
||||
.AddDelegatingHandler<GraphQlDelegatingHandler>();
|
||||
})
|
||||
.ConfigureLogging((hostingContext, logging) =>
|
||||
{
|
||||
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
||||
logging.AddConsole();
|
||||
})
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseOcelot().Wait();
|
||||
})
|
||||
.Build()
|
||||
.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
//maybe check for errors and headers etc in real world?
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent(responseBody)
|
||||
};
|
||||
|
||||
//ocelot will treat this like any other http request...
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var schema = Schema.For(@"
|
||||
type Hero {
|
||||
id: Int
|
||||
name: String
|
||||
}
|
||||
|
||||
type Query {
|
||||
hero(id: Int): Hero
|
||||
}
|
||||
", _ =>
|
||||
{
|
||||
_.Types.Include<Query>();
|
||||
});
|
||||
|
||||
new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.ConfigureAppConfiguration((hostingContext, config) =>
|
||||
{
|
||||
config
|
||||
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", true, true)
|
||||
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
|
||||
.AddJsonFile("ocelot.json", false, false)
|
||||
.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s =>
|
||||
{
|
||||
s.AddSingleton<ISchema>(schema);
|
||||
s.AddOcelot()
|
||||
.AddDelegatingHandler<GraphQlDelegatingHandler>();
|
||||
})
|
||||
.ConfigureLogging((hostingContext, logging) =>
|
||||
{
|
||||
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
||||
logging.AddConsole();
|
||||
})
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseOcelot().Wait();
|
||||
})
|
||||
.Build()
|
||||
.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Ocelot using GraphQL example
|
||||
|
||||
Loads of people keep asking me if Ocelot will every support GraphQL, in my mind Ocelot and GraphQL are two different things that can work together.
|
||||
I would not try and implement GraphQL in Ocelot instead I would either have Ocelot in front of GraphQL to handle things like authorisation / authentication or I would
|
||||
I would not try and implement GraphQL in Ocelot instead I would either have Ocelot in front of GraphQL to handle things like authorization / authentication or I would
|
||||
bring in the awesome [graphql-dotnet](https://github.com/graphql-dotnet/graphql-dotnet) library and use it in a [DelegatingHandler](http://ocelot.readthedocs.io/en/latest/features/delegatinghandlers.html). This way you could have Ocelot and GraphQL without the extra hop to GraphQL. This same is an example of how to do that.
|
||||
|
||||
## Example
|
||||
|
@ -1,13 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
|
||||
<PackageReference Include="Ocelot" Version="14.0.9" />
|
||||
<PackageReference Include="Ocelot.Provider.Kubernetes" Version="14.0.9" />
|
||||
</ItemGroup>
|
||||
|
@ -1,13 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Jaeger" Version="0.3.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" />
|
||||
<PackageReference Include="Jaeger" Version="0.4.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<Description>Stateless Web Service for Stateful OcelotApplicationApiGateway App</Description>
|
||||
<Authors> </Authors>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AssemblyName>OcelotApplicationApiGateway</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<PackageId>OcelotApplicationApiGateway</PackageId>
|
||||
@ -13,10 +13,10 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.ServiceFabric" Version="6.1.456" />
|
||||
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="3.0.456" />
|
||||
<PackageReference Include="Microsoft.ServiceFabric" Version="7.2.434" />
|
||||
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="4.2.434" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Ocelot\Ocelot.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -3,16 +3,16 @@
|
||||
<Description>Stateless Service Application</Description>
|
||||
<Authors> </Authors>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AssemblyName>OcelotApplicationService</AssemblyName>
|
||||
<PackageId>OcelotApplicationService</PackageId>
|
||||
<PackageTargetFallback>$(PackageTargetFallback)</PackageTargetFallback>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.ServiceFabric" Version="6.1.456" />
|
||||
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="3.0.456" />
|
||||
<PackageReference Include="Microsoft.ServiceFabric" Version="7.2.434" />
|
||||
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="4.2.434" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.Kestrel" Version="3.0.456" />
|
||||
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.Kestrel" Version="4.2.434" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user