Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Apollo Federation support #4618

Merged
merged 3 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/HotChocolate/ApolloFederation/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
56 changes: 56 additions & 0 deletions src/HotChocolate/ApolloFederation/ApolloFederation.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3638306A-64F0-4B29-8CCA-1F87291928EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApolloFederation", "src\ApolloFederation\ApolloFederation.csproj", "{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{F137FB69-3BD8-4B39-A578-C94873112B7F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApolloFederation.Tests", "test\ApolloFederation.Tests\ApolloFederation.Tests.csproj", "{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Debug|x64.ActiveCfg = Debug|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Debug|x64.Build.0 = Debug|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Debug|x86.ActiveCfg = Debug|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Debug|x86.Build.0 = Debug|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Release|Any CPU.Build.0 = Release|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Release|x64.ActiveCfg = Release|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Release|x64.Build.0 = Release|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Release|x86.ActiveCfg = Release|Any CPU
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51}.Release|x86.Build.0 = Release|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Debug|x64.ActiveCfg = Debug|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Debug|x64.Build.0 = Debug|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Debug|x86.ActiveCfg = Debug|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Debug|x86.Build.0 = Debug|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Release|Any CPU.Build.0 = Release|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Release|x64.ActiveCfg = Release|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Release|x64.Build.0 = Release|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Release|x86.ActiveCfg = Release|Any CPU
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0DF7AB7F-3B66-4C83-B6C1-739A636E6A51} = {3638306A-64F0-4B29-8CCA-1F87291928EF}
{BC491D0D-85A2-45A4-A8F5-F644AC7E7C09} = {F137FB69-3BD8-4B39-A578-C94873112B7F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="10.5.3"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\GreenDonut\test\DiagnosticSource.Tests\GreenDonut.DiagnosticSource.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\ApolloFederation\src\ApolloFederation\ApolloFederation.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\ApolloFederation\test\ApolloFederation.Tests\ApolloFederation.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\AspNetCore\sample\StarWars\StarWars.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\AspNetCore\src\AspNetCore.Authorization\HotChocolate.AspNetCore.Authorization.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\AspNetCore\src\AspNetCore\HotChocolate.AspNetCore.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\AspNetCore\test\AspNetCore.Authorization.Tests\HotChocolate.AspNetCore.Authorization.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\AspNetCore\test\AspNetCore.Tests\HotChocolate.AspNetCore.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Abstractions\HotChocolate.Abstractions.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Core\HotChocolate.Core.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Execution\HotChocolate.Execution.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Fetching\HotChocolate.Fetching.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Subscriptions.InMemory\HotChocolate.Subscriptions.InMemory.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Subscriptions.Redis\HotChocolate.Subscriptions.Redis.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Subscriptions\HotChocolate.Subscriptions.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Types.CursorPagination\HotChocolate.Types.CursorPagination.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Types.OffsetPagination\HotChocolate.Types.OffsetPagination.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Types\HotChocolate.Types.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\src\Validation\HotChocolate.Validation.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Abstractions.Tests\HotChocolate.Abstractions.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Execution.Tests\HotChocolate.Execution.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Fetching.Tests\HotChocolate.Fetching.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\StarWars\HotChocolate.StarWars.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Subscriptions.InMemory.Tests\HotChocolate.Subscriptions.InMemory.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Subscriptions.Redis.Tests\HotChocolate.Subscriptions.Redis.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Types.CursorPagination.Tests\HotChocolate.Types.CursorPagination.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Types.OffsetPagination.Tests\HotChocolate.Types.OffsetPagination.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Types.Records.Tests\HotChocolate.Types.Records.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Types.Tests.Documentation\HotChocolate.Types.Tests.Documentation.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Types.Tests\HotChocolate.Types.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Utilities\HotChocolate.Tests.Utilities.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Core\test\Validation.Tests\HotChocolate.Validation.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Data\src\Data\HotChocolate.Data.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Data\test\Data.Filters.InMemory.Tests\HotChocolate.Data.Filters.InMemory.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Data\test\Data.Filters.SqlServer.Tests\HotChocolate.Data.Filters.SqlServer.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Data\test\Data.Filters.Tests\HotChocolate.Data.Filters.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Data\test\Data.Sorting.Tests\HotChocolate.Data.Sorting.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Filters\src\Types.Filters\HotChocolate.Types.Filters.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Filters\src\Types.Sorting\HotChocolate.Types.Sorting.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Filters\test\Types.Filters.Mongo.Tests\HotChocolate.Types.Filters.Mongo.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Filters\test\Types.Filters.Tests\HotChocolate.Types.Filters.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Filters\test\Types.Sorting.Mongo.Tests\HotChocolate.Types.Sorting.Mongo.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Filters\test\Types.Sorting.Tests\HotChocolate.Types.Sorting.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Language\src\Language.SyntaxTree\HotChocolate.Language.SyntaxTree.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Language\src\Language.Utf8\HotChocolate.Language.Utf8.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Language\src\Language.Visitors\HotChocolate.Language.Visitors.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Language\src\Language\HotChocolate.Language.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Language\test\Language.Tests\HotChocolate.Language.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\PersistedQueries\src\PersistedQueries.FileSystem\HotChocolate.PersistedQueries.FileSystem.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\PersistedQueries\src\PersistedQueries.Redis\HotChocolate.PersistedQueries.Redis.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\PersistedQueries\test\PersistedQueries.FileSystem.Tests\HotChocolate.PersistedQueries.FileSystem.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\PersistedQueries\test\PersistedQueries.Redis.Tests\HotChocolate.PersistedQueries.Redis.Tests.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Utilities\src\Utilities.Introspection\HotChocolate.Utilities.Introspection.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Utilities\src\Utilities\HotChocolate.Utilities.csproj"/>
<ProjectReference Include="..\..\..\..\src\HotChocolate\Utilities\test\Utilities.Tests\HotChocolate.Utilities.Tests.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Linq;
using Accounts.Models;

namespace Accounts.Data
{
public class UserRepository
{
private Dictionary<string, User> _users;


public UserRepository()
{
_users = CreateUsers().ToDictionary(t => t.Id);
}

public User GetUserById(string id)
{
return _users[id];
}

private static IEnumerable<User> CreateUsers()
{
yield return new User
{
Id = "1",
Name = "Ada Lovelace",
Username = "@ada",
};

yield return new User
{
Id = "2",
Name = "Alan Turing",
Username = "@complete",
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Linq;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Accounts.Data;
using HotChocolate;
using HotChocolate.ApolloFederation;
using HotChocolate.Language;

namespace Accounts.Models
{
[ReferenceResolver(EntityResolverType = typeof(UserReferenceResolver))]
public class User
{
[Key]
public string Id { get; set; }
public string Name { get; set; }
public string Username { get; set; }
}

public static class UserReferenceResolver
{
public static async Task<User> GetUserReferenceResolverAsync(
[LocalState] ObjectValueNode data,
[Service] UserRepository userRepository)
{
// some code ....
return userRepository.GetUserById((string)data.Fields.First(field => field.Name.Value.Equals("id")).Value.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Accounts
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(
webBuilder =>
{
webBuilder.UseStartup<Startup>();
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Accounts.Data;
using Accounts.Models;
using HotChocolate;

namespace Accounts
{
public class Query
{
public User Me([Service] UserRepository userRepository)
{
return userRepository.GetUserById("1");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Accounts.Data;
using HotChocolate.AspNetCore;
using HotChocolate.AspNetCore.Playground;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Accounts
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// Add the custom services like repositories etc ...
services.AddSingleton<UserRepository>();

services.AddGraphQLServer()
.AddQueryType<Query>()
.AddApolloFederation();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseEndpoints(
endpoints =>
{
endpoints.MapGraphQL();
}
);
app.UsePlayground(new PlaygroundOptions()
{
Path = "/playground",
QueryPath = "/graphql"
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"urls": "http://localhost:5001"
}
Loading